|Content by Label|
According to the principle of least privilege, every program and every user of the system should operate using the least set of privileges necessary to complete the particular task \[[Saltzer 1974|AA. Bibliography#Saltzer 74], [Saltzer 1975|AA. Bibliography#Saltzer 75]\]. The Build Security In website \[[DHS 2006|AA. Bibliography#DHS 06]\] provides additional definitions of this principle. Executing with minimal privileges mitigates against exploitation in case a vulnerability is discovered in the code. These principles can be applied in various ways to Java language programming.
Java code should be run with the minimum required privileges. Sign only the code that requires elevated privileges; other code should not be signed. (See rule ENV00-J. Do not sign code that performs only unprivileged operations.) The security policy that defines the set of permissions should be as restrictive as possible. The default security policy file grants permissions sparingly, however, the flexible security model allows the user to grant additional permissions to applications by defining a custom security policy. Specific rules that enforce this principle include:
- SEC00-J. Avoid granting excess privileges
- SEC02-J. Remove superfluous code from privileged blocks
- ENV00-J. Do not sign code that performs only unprivileged operations
- ENV03-J. Do not grant dangerous combinations of permissions
- void ENV04-J. Do not grant ReflectPermission with target suppressAccessChecks
- ENV05-J. Do not grant RuntimePermission with target createClassLoader
Code that needs to be signed can coexist with unsigned classes in the same package (or
JAR file). It is recommended that all privileged code be packaged together. (See rule ENV01-J. Place all security-sensitive code in a single jar and sign and seal it for more information.) Furthermore, it is possible to grant privileges to code on the basis of the code base and/or its signer using a security policy.
Privileged operations should be limited to the smallest possible code blocks that require such privileges. The Java
AccessController mechanism allows only certain parts of code to acquire elevated privileges. When a class needs to assert its privileges, it executes the privileged code in a
doPrivileged block. The
AccessController mechanism works in conjunction with the security policy in effect. Because users may be unaware of the details of the security model and incapable of correctly configuring security policies tailored to their requirements, privileged code present within the
doPrivileged blocks must be kept to a minimum to avoid security vulnerabilities.
A security manager is an object that defines a security policy for Java code. This policy specifies actions that are unsafe or sensitive. Any actions not allowed by the security policy cause a
SecurityException to be thrown. Code can also query its security manager to discover which actions are allowed. The security manager can also be used to control the functions the trusted Java API can perform. (See rule ENV02-J. Create a secure sandbox using a Security Manager.) When untrusted code should be disallowed from accessing system classes, it should be granted specific permissions to prevent it from accessing trusted classes in the specified packages. The
accessClassInPackage permission provides the required functionality. (See rule void SEC12-J. Do not grant untrusted code access to classes in inaccessible packages.) Doing so does not limit what system classes can do; however, it restricts the range of system packages that can be used from less-privileged code.
Risk Assessment Summary
|SEC00-J||medium Medium||likely Likely||high High|
|SEC01-J||high High||likely Likely||low Low|
|SEC02-J||high High||probable Probable||high Medium|
|SEC03-J||high High||probable Probable||medium Medium|
|SEC04-J||high High||probable Probable||medium Medium|
|SEC05-J||high High||probable Probable||medium Medium|
|SEC06-J||high High||probable Probable||medium Medium|
|SEC07-J||high High||probable Probable||low Low|
FIO15-J. Perform proper cleanup at program termination The CERT Oracle Secure Coding Standard for Java SEC00-J. Do not allow doPrivileged() blocks to leak sensitive information outside a trust boundary