How can protecting my server from malicious activity when accepting and executing uploaded, untrusted code?
The users should be able to implement my interface and given data, perform some calculations and return data. No I/O operations are required and certainly no thread/process manipulation or other tomfoolery.
Using the java.policy file it is possible to deny everything (by granting nothing).
$ cat test.policy
grant {
};
Using this policy file, operations not granted will cause a security exception.
$ cat Print.java
public class Print {
public static void main(String a[]) throws Exception {
System.out.println(System.getProperty("os.name"));
}
}
$ javac Print.java
$ java -Djava.security.manager -Djava.security.policy==test.policy Print
Exception in thread "main" java.security.AccessControlException:
access denied (java.util.PropertyPermission os.name read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:1285)
at java.lang.System.getProperty(System.java:650)
at Print.main(Print.java:3)
Is this foolproof? Do I need to do more to secure my server environment from untrusted sources?