Skip to content
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

#67-2: Remove extra evaluations for bindings by introducing a cached set of bindings #69

Merged
merged 3 commits into from
Nov 15, 2018

Conversation

everestbt
Copy link
Contributor

This works by performing the following:

  1. Run the securing script as before
  2. Pull out the produced bindings and cache them
  3. Create a new set of bindings and put those into the engine
  4. If custom bindings are present put the cached set of secure bindings into them.

Additional parts done here, if before a script is run it detects that the secure settings have been changed inside the engine then it will re-create them. I am not certain this is needed as this doesn't protect a single running script but it will stop one script from causing problems for another. To address this fully further sanitation of the scripts going in would be needed but that seems outside the scope.

Typically the cached bindings only contains 16 entries so this check should not cost anything but the reset of the bindings does cost something, however it should rarely take place unless someone makes a mistake.

Important to note this issue discovered for binding still exists for ScriptContext, but at the moment I don't have time to dig into this. I will open an issue to flag this after this pull request and the current issue is closed.

From my testing this resolves issue #67, any comments on the code would be appreciated.

everestbt and others added 2 commits November 5, 2018 10:14
Changed the bindings protection to cache an initial Secure set of bindings, which are then put into custom bindings, and also used to check whether the engine bindings need to be reset. This does not protect from malicious actors!
Copy link
Collaborator

@mxro mxro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you looks great! Just a few minor comments I've left in the code - could you have a look?

@Ignore
public class TestPerformance {
@Test
public void noBindings() throws ScriptCPUAbuseException, ScriptException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to prefix all unit test methods with test eg testNoBinding? Just for consistencies sake!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked the added tests and ensured they follow this pattern.

for (int i = 0; i< 1000; ++i) {
sandbox.eval(js);
}
System.out.println("No binding " + (((double)(System.nanoTime() - start))/1_000_000_000));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the output to std out be replaced with asserts? e.g. Assert.assertTrue(time < ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have opted to remove the test file entirely, it was mostly for my own purposes to see what the difference was between the implementations. I agree they are useless tests, and any asserts would be flaky and prone to failure. They will exist in the history if anyone wants to revive them for some purpose.

}

// This will detect whether the current engine bindings match the cached protected bindings
private boolean engineBindingsSafe() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rename to engineBindingsUnchanged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have renamed it as suggested, it is much clearer this way.

@everestbt
Copy link
Contributor Author

@mxro Thank you very much for the comments, I have addressed them as best I can. Let me know if you have any other thoughts.

@mxro mxro merged commit 06c8316 into javadelight:master Nov 15, 2018
@mxro
Copy link
Collaborator

mxro commented Nov 15, 2018

@everestbt Perfect, thank you! Sorry again for merging this in later. Merged to master now but not deployed in a release yet.

SergeyZh pushed a commit to JetBrains/intellij-community that referenced this pull request Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants