...
Code Block | ||
---|---|---|
| ||
private void privilegedMethod(final String filename) throws FileNotFoundException { try { FileInputStream fis = (FileInputStream) AccessController.doPrivileged( new PrivilegedExceptionAction() { public FileInputStream run() throws FileNotFoundException { return new FileInputStream(filename); } } ); // do something with the file and then close it } catch (PrivilegedActionException e) { /* forward to handler and log */ } // do something with the file and then close it } |
Compliant Solution
Explicitly hardcode the name of the file and confine the privileged variables to the same method. This ensures that no malicious file is loaded by exploiting the privileges of the corresponding code.
Code Block | ||
---|---|---|
| ||
private void privilegedMethod(final String filename) throws FileNotFoundException { try { FileInputStream fis = (FileInputStream) AccessController.doPrivileged( new PrivilegedExceptionAction() { public FileInputStream run() throws FileNotFoundException { return new FileInputStream("/usr/home/filename"); } } ); // do something with the file and then close it } catch (PrivilegedActionException e) { /* forward to handler and log */ } // do something with the file and then close it } |
Risk Assessment
Allowing tainted inputs in privileged operations can lead to privilege escalation attacks.
...