Versions Compared

Key

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

...

Noncompliant Code Example

Accepting tainted inputs from untrusted code can A method that passes untrusted inputs to the Class.forName() method might permit an attacker to load access classes with escalated privileges. The single argument Class.forName() method is another API method that uses its immediate caller's class loader to load a requested class. Untrusted code can misuse this API to indirectly manufacture classes that have the same privileges as those of the attacker's immediate caller.

Code Block
bgColor#ffcccc
lang#FFccccjava
public Class loadClass(String className) {
  // className may be the name of a privileged or even a malicious class
Class c =return Class.forName(className);
}

Compliant Solution

...

(Hardcoded Name)

Limit the visibility of the method that uses this API. Do not operate on tainted inputs. This compliant solution hard-codes the class's name.

Code Block
bgColor#ccccff
langjava
public Class loadClass() {
 c =return Class.forName("Foo"); // Explicitly hardcode
}

Noncompliant Code Example

...

Code Block
bgColor#FFcccc
public Connection getConnection() {
  // ...
  return DriverManager.getConnection(url, username, password);
}

Compliant Solution

Ensure that instances of objects created using the unsafe methods are not returned to untrusted code. It is preferable to reduce the accessibility of methods that perform sensitive operations and define wrapper methods that are accessible from untrusted code.

...