Versions Compared

Key

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

...

The untrustedCode method invokes loadLibrary loadLib method in this noncompliant example. This is dangerous as the library gets loaded on behalf of the untrusted code. The acceptance of Accepting tainted inputs from the untrusted code can further exacerbates exacerbate this issue. In essence, the untrusted code's class loader may be able to load the intended library even if it does not have sufficient permissions.

Code Block
bgColor#FFcccc
class NativeCode {
  public staticnative void untrustedCodeloadLib();

  static {
    System.loadLibrary("/com/foo/MyLib.so");
  }
    

  public static void loadLibraryuntrustedCode() {
    new SystemNativeCode().loadLibraryloadLib(lib);
  }
}

Compliant Solution

Ensure that untrusted code cannot invoke the affected APIs directly or indirectly (that is, via a call to an invoking method). Do not operate on tainted inputs and make sure that internal objects are not returned to untrusted code.

...

bgColor#ccccff

...

Risk Assessment

Allowing untrusted code to load libraries using the immediate caller's class loader may seriously compromise the security of a java application.

...