Skip to content

Inefficient Regular Expression Complexity

Description

The application is constructing a regular expression with user-controllable input, which may result in excessive resource consumption when applied to certain inputs, or when the user is allowed to control the match target.

Examples

Insecure Code

ruby
Regexp.new(user_input)

Secure Code

ruby
ALLOWED_PATTERNS = { 'digits_only' => /^\d+$/ }; safe_pattern = ALLOWED_PATTERNS['digits_only']; target_data.match(safe_pattern)

Remediation

Avoid allowing users to specify regular expressions processed by the server. If user-controllable input in a regular expression is necessary, use an allow-list to restrict the expressions users may supply to limit catastrophic backtracking.

Rule Details

FieldValue
IDCODE-0547
CategoryInjection
SeverityMEDIUM
CWECWE-1333
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
TagsReDoS, Regular Expression Denial of Service
OWASPA6:2017-Security Misconfiguration, A04:2021-Insecure Design

References