...
Consequently, when an environment variable contains information that is available by other means, including system properties, that environment variable should not be used. Untrusted environmental variables must not be used without appropriate validation.
Noncompliant Code Example
This noncompliant code example tries to get the user name, using an environment variable.
...
This program runs the program /usr/bin/printenv
, which prints out all environment variables and their values. It takes a single argument string and sets the USER
environment variable to that string. The subsequent output of the printenv
program will indicate that the USER
environment variable is indeed set to the string requested.
Compliant Solution
This compliant solution obtains the user name using the user.name
system property. This property always contains the correct user name, even when the USER
environment variable has been set to an incorrect value or is missing.
Code Block | ||
---|---|---|
| ||
String username = System.getProperty("user.name"); |
Risk Assessment
Untrusted environment variables can provide data for injection and other attacks if not properly sanitized.
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
ENV02-J | low | likely | low | P9 | L2 |
Bibliography
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="65dbbe74fa8a0e8f-970b690f-4cc9406c-8f84afde-32659e74f98eabf777039275"><ac:plain-text-body><![CDATA[ | [[API 2006 | AA. Bibliography#API 06]] | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="36f28e9441e2f24b-7d602dc5-4b3c4f97-8cb69480-9c42ab192725a7de82151b2b"><ac:plain-text-body><![CDATA[ | [[Campione 1996 | AA. Bibliography#Campione 96]] |
| ]]></ac:plain-text-body></ac:structured-macro> |
...