Overly Restrictive Regular Expression

Draft Base
Structure: Simple
Description

This weakness occurs when a regular expression is too narrow, failing to detect all the dangerous or unexpected input values it was designed to catch.

Extended Description

An overly restrictive regex doesn't match every input it should, creating a gap in your security checks. This isn't about the regex being computationally complex; it's about its logic being incomplete. For example, using /[0-8]/ to validate digits would miss the number '9', potentially allowing an unwanted value to slip through. The result is either false negatives (missing real threats) or false positives (blocking safe input), depending on whether the regex is used to allowlist or blocklist terms. As a developer, you must carefully review the intended scope of your validation. Test your regular expressions against the full range of both valid and malicious edge cases to ensure they capture everything relevant. This proactive testing helps close the gap between what you think your regex catches and what it actually allows or blocks in practice.

Common Consequences 1
Scope: Access Control

Impact: Bypass Protection Mechanism

Potential Mitigations 1
Phase: Implementation
Regular expressions can become error prone when defining a complex language even for those experienced in writing grammars. Determine if several smaller regular expressions simplify one large regular expression. Also, subject your regular expression to thorough testing techniques such as equivalence partitioning, boundary value analysis, and robustness. After testing and a reasonable confidence level is achieved, a regular expression may not be foolproof. If an exploit is allowed to slip through, then record the exploit and refactor your regular expression.
Observed Examples 1
CVE-2005-1604MIE. ".php.ns" bypasses ".php$" regexp but is still parsed as PHP by Apache. (manipulates an equivalence property under Apache)
Applicable Platforms
Languages:
Not Language-Specific : Undetermined
Modes of Introduction
Implementation
Taxonomy Mapping
  • PLOVER
Notes
RelationshipCan overlap allowlist/denylist errors (Permissive List of Allowed Inputs/Incomplete List of Disallowed Inputs)