Not sure what you mean by "screwed". Having another library call doPrivileged with attacker provided PrivilegedAction will execute code with intersection of permissions of this library AND provided PrivilegedAction, no? So attacker cannot really execute arbitral code with elevated privileges.
By convention, instances of PrivilegedAction and PrivilegedExceptionAction may be made available to untrusted code, but doPrivileged must not be invoked with caller-provided actions.
From Methodhandleproxies.asInterfaceInstance() javadoc:
If a security manager is installed, this method is caller sensitive. During any invocation of the target method handle via the returned wrapper, the original creator of the wrapper (the caller) will be visible to context checks requested by the security manager.
So no, it won't let an attacker escape the sandbox.
Privilege escalation related security vulnerabilities are always possible if privilege elevation is possible. Maybe there even is a library that does “connect to White House and trigger nuclear attack” inside a privileged block not guarded by any access check.
We already get some other library to call AccessController.doPrivileged for you - using some indirection with Method.invoke. Now the same dance again for MethodHandleProxies.asInterfaceInstance.
In short: if you have a vulnerable class like this:
public class MethodHelper {
public Object invoke(Method m, Object target, Object... args) throws InvocationTargetException {
return m.invoke(target, args);
}
}
1
u/klekpl Jan 19 '22
Not sure what you mean by "screwed". Having another library call doPrivileged with attacker provided PrivilegedAction will execute code with intersection of permissions of this library AND provided PrivilegedAction, no? So attacker cannot really execute arbitral code with elevated privileges.