I will be distributing a stand alone Java application that will be installed on a public/shared computer. I want to secure the application as best I can from possible malicious/curious users. This means that I want the application to run in the context of a SecurityManager with a custom policy file.
I know of two ways to run a Java application with a Security Manager.
- When launching the application specify the parameters
-Djava.security.manager
and-Djava.security.policy=someUrl
. This approach seems to suffer from the following weaknesses:- If
someUrl
refers to a location on the local machine an attacker could modify the policy file and effectively bypass the security sandbox. - If an attacker can restart the application they could launch it without passing either of these parameters and run the application without a Security Manager and therefore bypass the security sandbox.
- If
someUrl
refers to a location on a remote machine and the remote machine is unaccessible when the application is launched then the application would (presumably) fail to launch.
- If
- Inside the application execute the following code:
System.setProperty("java.security.policy", "path/to/policy/file");
System.setSecurityManager(new SecurityManager());
This approach seems to suffer from the following weakness:- Since the Security Manager is not started by the JVM prior to loading the application, an attacker could tamper with the class files in the application and bypass the security sandbox.
Either way, it seems to me it is not possible to guarantee that a stand alone application will be run in the context of a Security Manager on a public/shared computer.
Is my analysis wrong? Is it possible for an application developer to guarantee the application is run in a Security Manager, and guarantee that the policy file has not been tampered with, when the application is run on a public/shared computer?