Skip to content

Improper Control of Generation of Code ('Code Injection')

Description

The software constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.

Examples

Insecure Code

scala
val parser = new SpelExpressionParser(); val expression = parser.parseExpression(userInput);

Secure Code

scala
val parser = new SpelExpressionParser(); val expression = parser.parseExpression(sanitizeUserInput(userInput));

Remediation

Validate and sanitize any user-controlled input before passing it to the SpelExpressionParser to prevent code injection attacks.

Rule Details

FieldValue
IDCODE-0064
CategoryInjection
SeverityMEDIUM
CWECWE-94
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagscode-injection, injection
OWASPA1:2017-Injection, A03:2021-Injection