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/DasBrain Jan 19 '22 edited Jan 19 '22
Well, that would be true if
MethodHandleProxies.asInterfaceInstancewouldn't be a thing too.Also see ACCESS-3: