CWEweakness
CWE-186 Overly Restrictive Regular Expression
- Abstraction
- Base
- Structure
- Simple
- Status
- Draft
- Languages
- Not Language-Specific
- CWE version
- 5.0
Description
A regular expression is overly restrictive in a way that does not match all intended values.
Common consequences
• Access Control: Bypass Protection Mechanism, Varies by Context — An overly restrictive regexp misses some potentially security-relevant values, leading to either false positives *or* false negatives, depending on how the regexp is being used within the code.
Potential mitigations
• [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
• CVE-2005-1604: MIE. ".php.ns" bypasses ".php$" regexp but is still parsed as PHP by Apache. (manipulates an equivalence property under Apache)
Related
Observed example · CVE (1)
- CVE-2005-1604 PHP Advanced Transfer Manager (phpATM) 1.21 allows remote attackers to upload arbitrary files via filenames containing multiple file… vulnerability
Can also be · CWE (2)
Child of · CWE (1)
- CWE-185 Incorrect Regular Expression weakness
Referenced by CVE · weakness (2)
- CVE-2026-47241 Net::IMAP implements Internet Message Access Protocol (IMAP) client functionality in Ruby. vulnerability
- CVE-2025-46821 Envoy is a cloud-native edge/middle/service proxy. vulnerability