Reputation: 36715
I wanted to create a very restrictive security manager, so I extended SecurityManager and overridden all the custom checkXXX methods.
But then I found out that my security manager is useless, because anyone can just:
System.setSecurityManager(null);
So I have to add:
@Override public void checkPermission(Permission perm) {
if (perm.getName().equals("setSecurityManager")) {
throw new SecurityException("You shall have no other security manager but me!");
}
}
Are there any more surprises? Any other things I have to do to make my SecurityManager hermetic?
Upvotes: 5
Views: 371
Reputation: 54806
There are at least a couple of things I can think of:
Someone could use reflection to set the System.security
field to accessible, and then set it to whatever they want.
Someone could use sun.misc.Unsafe to directly overwrite your instance in memory with whatever random thing they want.
I think your SecurityManager
can guard against these things, since they both rely on calls to Field.setAccessible()
. But better to test it out to make sure.
Upvotes: 8