Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Application code that calls security-sensitive methods must validate the arguments being passed to the methods. In particular, null values may be interpreted as benign by certain security-sensitive methods and but may override default settings. Although security critical -sensitive methods must should be coded defensively in the first place, sometimes the onus is on the client code to must validate and provide the argumentsarguments that the method might otherwise accept as valid. Failure to do so can result in privilege escalation and execution of arbitrary code.

Noncompliant Code Example

This noncompliant code example shows the two-argument doPrivileged() method that takes an access control context as the second argument. The construct allows changing privileges to that of This code restores privileges from a previously saved context.

Code Block
bgColor#ffcccc
langjava
AccessController.doPrivileged(
  new PrivilegedAction<Void>() {
    public Void run() {
      // ...
    }
  }, accessControlContext);

null access When passed a null access control context means that the privileges would not be reduced , the two-argument doPrivileged() method fails to reduce the current privileges to those of the previously saved context. Consequently, this code can grant excess privileges when the accessControlContext argument is null. Programmer who intend to call AccessController.doPrivileged() with a null access control context should explicitly pass the null constant or use the one-argument version of AccessController.doPrivileged().

Compliant Solution 

This compliant solution ...prevents granting of excess privileges by ensuring that accessControlContext is non-null:

Code Block
bgColor#ccccff
langjava
if (accessControlContext == null) {
  throw new SecurityException("Missing AccessControlContext");
}
AccessController.doPrivileged(
  new PrivilegedAction<Void>() {
    public Void run() {
      // ...
    }
  }, accaccessControlContext);

Noncompliant Code Example

This noncompliant code example ...

Code Block
bgColor#ffcccc
langjava
 System.setSecurityManager(null);

Compliant Solution 

This compliant solution ...

Code Block
bgColor#ccccff
langjava
System.setSecurityManager(new SecurityManager());

Applicability

 

Bibliography

 

Image Removed Image Removed Image Removed

 

Noncompliant Code Example

Code Block
 

 

Compliant Solution

Code Block
 

Noncompliant Code Example

Applicability

Security-sensitive methods must be thoroughly understood and their parameters validated to prevent corner cases with unexpected argument values (such as null arguments). If unexpected argument values are passed to security-sensitive methods, arbitrary code execution becomes possible, and privilege escalation becomes likely.

Bibliography

 

...

Image Added Image Added Image Added

...