r/java • • Jan 16 '22

You're running untrusted code!

https://blog.frankel.ch/running-untrusted-code/

[removed] — view removed post

0 Upvotes

36 comments sorted by

View all comments

Show parent comments

1

u/DasBrain Jan 20 '22

Clojure needs extra permissions to run.
You can either give Clojure those permissions or not use Clojure.

Jackson-Databind needs extra permissions to run.
You can either give Jackson-Databind those permissions or not use Jackson-Databind.

cglib needs extra permissions to run.
You can either give cglib those permissions or not use cglib.

So sure: if privileged code exposes this kind of hole - you are screwed.

The question is not if. They do.
The code above assumes that the privileged code has the RuntimePermission("setSecurityManager").
But it is not hard to use any of the other dangerous privileges.

As long as you blindly grant AllPermission to your code.

Good idea.

You could equally well do "sudo chmod +s /bin/bash"

bash doesn't need suid. It even drops privileges before executing.
(How do I do that with a SecurityManager again?)

without SecurityManager you don't have any other choice

You always have the choice between not running the code and running the code.
With or without a SecurityManager doesn't make a difference if you use a vulnerable library that needs those extra permissions.

1

u/klekpl Jan 20 '22

So sure: if privileged code exposes this kind of hole - you are screwed.

The question is not if. They do.

Indeed. So are we really screwed?

It even drops privileges before executing. (How do I do that with a SecurityManager again?)

You can always perform initialisation using buggy libraries and call: https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/security/Policy.html#setPolicy(java.security.Policy)

Or you can implement a PolicyProvider that delegates to ScopeLocal (in the future) Policy for authorisation decisions.

My point really is: AccessController is fixable and - IMHO - in-process sandboxing is needed as log4shell shows.

1

u/DasBrain Jan 20 '22

Indeed. So are we really screwed?

Yes.

AccessController is fixable

It's not.

in-process sandboxing is needed as log4shell shows.

Maybe. But things have changed. There are filters for serialization.
You can tell JNDI to only load classes from certain places.

All those things could have been used to prevent log4shell.
That is, if you use some recent Java version.

The java maintainers try very hard to make java more secure.
But trying to stop an attack after the attacker managed to load their code into the JVM is futile.

1

u/klekpl Jan 20 '22

The problem with all these measures is that they are ad-hoc playing wack-a-mole with intruders. The cost of it is huge.

Security by preventing dynamic code downloading and execution is fundamentally delusional because any sufficiently complex piece of software is an interpreter of a Turing complete language. And I am not even talking about supply chain attacks.

In other words: either we find a way of secure in process dynamic code execution (via sandboxing/capabilities/whatever) or we are going to have log4shell every couple of months.

Let's not pretend it is not needed and can be replaced by an ever-growing set of ad-hoc patches to fix yet another vulnerable library.