When a custom class loader must override the getPermissions()
method, the implementation must consult the default system policy by explicitly invoking the superclass's getPermissions()
method before assigning arbitrary permissions to the code source. The getPermissions()
method is actually defined by SecureClassLoader
, which extends ClassLoader
. ClassLoader
is abstract and must not be extended directly.
...
This noncompliant code example shows a fragment of a custom class loader that extends the class URLClassLoader
. It overrides the getPermissions()
method and does not call the superclass's more restrictive getPermissions()
method. Consequently, a class defined using this custom class loader has permissions that are completely independent of those specified in the system-wide policy file; in . In effect, the class's permissions override them.
...
In this compliant solution, the getPermissions()
method calls super.getPermissions()
. ConsequentlyAs a result, the default system-wide security policy is applied, in addition to the custom policy.
...
Failure to consult the default system policy while defining a custom classloader class loader violates the tenets of defensive programming and can result in classes defined with unintended permissions.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
SEC07-J | high | probable | low | P18 | L1 |
Automated Detection
This Violations of this rule can be addressed discovered with a heuristic checker in the style of FindBugs. As with all heuristic checks, achieving a low false-positive rate is essential.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="100af3cb3d73f13a-74180d9a-46f6402c-8c65a5a6-3168b88979c4a71e97114f74"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | [Class ClassLoader | http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="35a753e11b2ac29f-449c9047-44a747bc-a07396df-29a6984c49359bf1115cfcb3"><ac:plain-text-body><![CDATA[ | [[Oaks 2001 | AA. Bibliography#Oaks 01]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c1fd4d41e3597254-12f5d15f-4a2c42ca-bec8af75-7e073d0bbecba93c20fe8695"><ac:plain-text-body><![CDATA[ | [[Security 2006 | AA. Bibliography#Security 06]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...