we have a Java application and we want to run untrusted code using the built-in Javascript interpreter (javax.script. *)
However, by default, the interpreter allows access to any java class. For example, " java.lang.System.exit(0) " in the script will disable the JVM. I find this to be called “Live Connect,” see Sun's “Java Script Programmer's Guide” for more details.
I would like to somehow disable the script access feature for Java classes, i.e. I want the script to be able to access objects that I specifically insert using the eval() or put() methods on ScriptEngine .
I found some documentation on how to achieve this using an older standalone version of the interpreter (Rhino), e.g. see http://codeutopia.net/blog/2009/01/02/sandboxing-rhino-in-java/
However, this approach is not possible in JDK 1.6 without using the inner classes of the sun, since ClassShutter, etc. are internally configured and cannot be overridden by public methods.
I hope there is an easy way around this that does not require going through complex hoops with the help of a special SecurityManager, ClassLoader, etc., but could not find anything.
You would expect with the frequency of the security bulletins surrounding Javascript in different applications, there would be a simple flag to disable Live Connect!
Brett Vasconcellos
source share