-
Notifications
You must be signed in to change notification settings - Fork 82
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
produceSecureBindings() doesn't seem to work #134
Comments
Thank you for raising this issue! I tried to reproduce it in a unit test: public class TestIssue134 {
@Test
public void test() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create();
sandbox.eval("load('classpath:TestIssue134.js')");
sandbox.eval("load('somethingwrong')");
}
} It seems like the load function is just the overriden dummy. When running the same test with the enabled load function as follows: @Test
public void test() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create();
sandbox.allowLoadFunctions(true);
sandbox.eval("load('classpath:TestIssue134.js')");
sandbox.eval("load('somethingwrong')");
} We will get the exception 'I should never be called' from running the script. Could you help me refine the test so it captures what you have encountered? Thank you! |
@Test
public void test() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create();
// create context for Engine scope binding
ScriptContext context = new SimpleScriptContext();
// actually, there is more source for binding
// blah,blah, blah....
sandbox.eval("load('classpath:TestIssue134.js')", context);
sandbox.eval("load('somethingwrong')", context);
} I run eval() with new sciprt context, but that is not secure context. thanks to every reply. |
I think technically the Sandbox worked as expected here. However, I think your example shows that it is very easy to accidentally expose scripts. Therefore, I released a new version 0.3.0 that attempts to make it safer working with script contexts. It will now work as follows: @Test
public void test() throws ScriptCPUAbuseException, ScriptException {
NashornSandbox sandbox = NashornSandboxes.create();
// create context for Engine scope binding
ScriptContext context = sandbox.createScriptContext();
// actually, there is more source for binding
// blah,blah, blah....
sandbox.eval("load('classpath:TestIssue134.js')", context);
sandbox.eval("load('somethingwrong')", context);
} Please let me know if this doesn't resolve your issue! |
Hi, recently I found that sandbox can load remote script by using load() function.
It can be secure problem in my project , so I checked option of sandbox.
I found allowLoadFunctions args is "false" by default.
I debugged NashornSandboxImpl, and there is ambiguous part of produceSecureBindings()
It looks like doing method overide such as quit/load/print ... . but after that, call resetEngineBindings() again.
Doesn't it mean that all overrides are initialized?
I don't know if this is the real cause, but in my current sandbox it is still possible to execute load() function.
Is there something I'm missing?
The text was updated successfully, but these errors were encountered: