Should I use Security Manager in Java web applications?
Asked Answered
W

3

8

Is it sufficient to secure a Java web application with the rights of the user that is running the application server process or is it reasonable also to use SecurityManager with a suitable policy file?

I have used to do the former and not the latter, but some customers would like us to also use SecurityManager that would explicitly give permissions to every third-party component to be sure there isn't any evil code lurking there.

I've seen some Servlet containers, like Resin to propose not using SecurityManager to slow things up. Any thoughts?

Widener answered 25/8, 2009 at 8:33 Comment(0)
J
10

While I hate to ever recommend not using a security feature, it's my opinion that a SecurityManager is more intended to manage situations where untrusted or third-party code is executing in the JVM. Think applets, or a hosted, shared app server scenario. If you have complete control over the app server and are not running anybody else's code, I think it's redundant. Enable the SecurityManager does have significant performance impact in my experience.

Jambeau answered 25/8, 2009 at 9:57 Comment(2)
In our case the third-part code are various known OS libraries. It's quite much of work to review every line of code to check if there are any potential "bad" code. I do trust in these libraries, but our customer is a bit paranoid :)Widener
You need to be careful before you say you aren't running anyone else's code. E.g., XML External Entity (XEE) attacks can be used if you parse XML but most people would say that's 'just data.'Manara
C
2

There is no simple yes/no answer to your question, because it really depends: what do you want to secure, and what do you want to secure it from?

For example, I've used SecurityManager to implement IP filtering and allow only whitelisted IP addresses to connect to my application. If you just want to disallow access to disk files, maybe running application as user with lesser privileges is better solution.

If you don't trust third party plugins at all, remember that once you allow execution of plugin code, that plugin can crash your application if it wants to even if you use SecurityManager. If your application loads plugins, maybe whitelisting plugin and checking the list before loading plugin is better solution.

If you decide to use it, you will take a performance hit (since JVM will do more checks), but how fast it will run really depends on your code/configuration that will do the checks. My IP whitelist was pretty fast since it included only single list lookup; if your checks include invoking remote web service and accessing database you can slow things down a lot, but on the other hand, even that should not matter if you have enough hardware and few concurrent users (in other words, if you can afford it).

Contrived answered 25/8, 2009 at 10:27 Comment(0)
C
2

Correctly configurin Security Manager in java can be hard. For instance, if you do not restrict the security manager itself, one can bypass all security just by setting the Security Manager to null.

Using a security manager only makes sense if your JVM will run untrusted code, otherwise it is a pain to set up, because you'll have to know beforehand what permissions you should set for each feature (ex: RMI, sockets, I/O) and for each client.

Crosswise answered 25/8, 2009 at 11:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.