Skip to content

Regular Expression Denial of Service

Description

The regex used to compare with user-supplied input is vulnerable to regular expression denial of service, which can cause the application to become unresponsive or crash.

Examples

Insecure Code

javascript
app.get('/', (req, res) => { const regex = /^.*$/; regex.test(req.query.input); res.send('Hello World'); });

Secure Code

javascript
app.get('/', (req, res) => { const regex = /^[a-zA-Z0-9]+$/; regex.test(req.query.input); res.send('Hello World'); });

Remediation

Use a safe regex pattern or validate user input to prevent malicious regex patterns.

Rule Details

FieldValue
IDCODE-0366
CategoryInjection
SeverityMEDIUM
CWECWE-185
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityEASY
Tagsregex, denial of service
OWASPA6:2017-Security Misconfiguration, A05:2021-Security Misconfiguration