nathanfranke
nathanfranke

Reputation: 983

Java - How do I sandbox ScriptEngineManager?

I can easily execute JavaScript using the built-in ScriptEngineManager. However, it gives full permission to JavaScript, which is a big problem for me.

It allows dangerous commands such as:

How do I limit the availability of Java functions in the Javascript Engine?

Upvotes: 0

Views: 633

Answers (1)

Sajadur Rahman
Sajadur Rahman

Reputation: 36

The sandbox by default blocks access to all Java classes.

NashornSandbox sandbox = NashornSandboxes.create();
sandbox.allow(File.class);  
sandbox.eval("var File = Java.type('java.io.File'); File;")

delight-nashorn-sandbox

Upvotes: 2

Related Questions