After setting up a JavaScript-ScriptEngine like this:
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
public class Compute {
public static void main(String[] args){
try{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
System.out.println(engine.eval(args[0]));
}
catch(Exception e){
System.out.println("Syntax Error!");
}
}
}
Why can you do things like: java Compute "java.util.Arrays.toString(new java.io.File(\".\").listFiles())"
Isn't the ScriptEngine for "JavaScript" supposed to execute JS only?
Any links on what the Engine actually does or why this is possible, would be greatly appreciated.
(edit: This is no duplicate of security problem with Java ScriptEngine, as I want to know why this is possible, not how to avoid it)