Skip to content

Command injection via environment variables

Description

Detected unvalidated user input being passed as environment variables to Runtime.exec(). This can allow attackers to influence system commands.

Examples

Insecure Code

java
Runtime.getRuntime().exec("/bin/cmd", new String[]{userInput});

Secure Code

java
if (Arrays.asList(allowed).contains(userInput)) {
    Runtime.getRuntime().exec("/bin/cmd", new String[]{userInput});
}

Remediation

Validate input using allowlists before using it as an environment argument.

Rule Details

FieldValue
IDCODE-0290
CategoryInjection
SeverityHIGH
CWECWE-78
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsinjection, command injection
OWASPA03:2021-Injection