-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with Js sanitizer #151
Comments
Thank you for raising this issue! Could you provide a code example to help reproduce the issue? Are there any regular expressions in the code that is run by the sandbox? |
Hello, An exemple : public class NashornSandboxBug {
public static void main(String[] args) throws ScriptException {
String s = """
function(data) {
if (data.get("propertyA") == "a special value 1" || data.get("propertyA") == "a special value 2") {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyC") == "a special value 1" || data.get("propertyJ") == "a special value 1" || data.get("propertyV") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "4" && (data.get("propertyD") == "a special value 1" || data.get("propertyV") == "a special value 1" || data.get("propertyW") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 2" && (data.get("propertyE") == "a special value 1" || data.get("propertyF") == "a special value 1" || data.get("propertyL") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyE") == "a special value 1" || data.get("propertyF") == "a special value 1" || data.get("propertyL") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else if (data.get("propertyB") == "a special value 3" && (data.get("propertyM") == "a special value 1" || data.get("propertyY") == "a special value 1" || data.get("propertyH") == "a special value 1")) {
return "a special value 1";
} else {
return "0"
};
}
""";
NashornSandbox sandbox = NashornSandboxes.create();
sandbox.eval(s);
}
} and the stacktrace :
Thanks |
I have the same issue with the 0.4.2 implementation used in https://github.com/thingsboard I am unsure on the mechanics of how Thingsboard uses nashorn-sandbox, but my application code below(I assume part of a string passed to nashorn works:
adding a single non-whitespace character to the above breaks it. |
Any workaround, met the same issue. |
Attempting to parse JavaScript using regular expressions is hard. It might be better to switch to a full JavaScript parser written in Java - as this should be much faster and simpler to insert the necessary JavaScript snippets for checking CPU usage etc. The regular expressions could then be removed. |
Love the changes, that's some great work ❤! Left some comments on the PR and I think a few things to sort out before we can release, but definitely looks like the way forward to me! |
Thank you for your great work @busterace ❤ The version with your improvements has been published to Maven central as part of |
Script fails on js sanitizer with following exception: java.lang.RuntimeException: delight.nashornsandbox.exceptions.ScriptCPUAbuseException: Regular expression running for too many iterations. The operation could NOT be gracefully interrupted.
After that error, even the simplest script will fail with thread interrupted exception. On second call everything is fine.
I'm using java 17 and sandbox version 0.3.2. On version 0.3.0 it works as expected.
The text was updated successfully, but these errors were encountered: