...
Code Block | ||
---|---|---|
| ||
private final void makeAccessible() { // private final String fieldName = "i""i"; // hardcode C c = new C(); // ... } class C { private int i = 10; // private } |
...
Code Block | ||
---|---|---|
| ||
package Safe; public class Trusted { Trusted() { } // package private constructor public static <T><T> T create(Class<T>Class<T> c) throws InstantiationException, IllegalAccessException { return c.newInstance(); } } package Attacker; import Safe.Trusted; public class Attack { public static void main(String[] args) throws InstantiationException, IllegalAccessException { System.out.println(Trusted.create(Trusted.class)); // succeeds } } |
...
Code Block | ||
---|---|---|
| ||
package Safe; import java.beans.Beans; public class Trusted { Trusted() { } public static <T><T> T create(Class<T>Class<T> c) { try { ClassLoader cl = new SafeClassLoader(); Object b = Beans.instantiate(cl, c.getName()); return c.cast(b); } catch(Throwable t) { t.printStackTrace(); /* forward to handler */ } return null; } } // code outside the package package Attacker; import Safe.Trusted; public class Attack { public static void main(String[] args) { Object o = Trusted.create(Trusted.class); // throws java.lang.IllegalAccessException, o = null } } |
...
Search for vulnerabilities resulting from the violation of this rule on the CERT website.
References
Wiki Markup |
---|
\[[Chan 99|AA. Java References#Chan 99]\] java.lang.reflect AccessibleObject \[[SCG 07|AA. Java References#SCG 07]\] Guideline 6-4 Be aware of standard APIs that perform Java language access checks against the immediate caller |
...
SEC02-J. Do not expose standard APIs that may bypass Security Manager checks to untrusted code 02. Platform Security (SEC) SEC04-J. Do not rely on the default automatic signature verification provided by URLClassLoader and java.util.jar