...
Code Block | ||
---|---|---|
| ||
class ACC { private static class RestrictedAccessControlContext { private static final AccessControlContext INSTANCE; static { INSTANCE = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, null) // no permissions }); } } // First sanitize firstName (modify if the name may include special characters) if(!firstName.matches("[\\w]*")) { // String does not match whitelisted characters throw new IllegalArgumentException(); } // Restrict permission using the two-argument form of doPrivileged() try { AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws ScriptException { engine.eval("print('"+ firstName + "')"); return null; } }, RestrictedAccessControlContext.INSTANCE); // From nested class } catch(PrivilegedActionException pae) { // Handle } |
...
Applicability
Failure to prevent code injection can result in the execution of arbitrary code.
Guideline | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
IDS51-JG | high | likely | medium | P18 | L1 |
Related Vulnerabilities
Search for vulnerabilities resulting from the violation of this guideline on the CERT website.
Bibliography
[API 2006] Package javax.script
[OWASP 2008] Code injection in Java
...