The product specifies a regular expression in a way that causes data to be improperly matched or compared.
When the regular expression is used in protection mechanisms such as filtering or validation, this may allow an attacker to bypass the intended restrictions on the incoming data.

Primary

Implementation

Other
Unexpected State
Varies by Context
When the regular expression is not correctly specified, data might have a different format or type than the rest of the program expects, producing resultant weaknesses or errors.

Access Control
Bypass Protection Mechanism
In PHP, regular expression checks can sometimes be bypassed with a null byte, leading to any number of weaknesses.

Automated Static Analysis
Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)
High

Architecture and Design
Refactoring
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 the 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 the regular expression.

The following code takes phone numbers as input, and uses a regular expression to reject invalid phone numbers.

$phone = GetPhoneNumber();if ($phone =~ /\d+-\d+/) {
# looks like it only has hyphens and digits
system("lookup-phone $phone");}
else {error("malformed number!");}

An attacker could provide an argument such as: "; ls -l ; echo 123-456" This would pass the check, since "123-456" is sufficient to match the "\d+-\d+" portion of the regular expression.

This code uses a regular expression to validate an IP string prior to using it in a call to the "ping" command.

import subprocess
import re

def validate_ip_regex(ip: str):

ip_validator = re.compile(r"((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}")
if ip_validator.match(ip):

return ip

else:

raise ValueError("IP address does not match valid pattern.")

def run_ping_regex(ip: str):

validated = validate_ip_regex(ip)
# The ping command treats zero-prepended IP addresses as octal
result = subprocess.call(["ping", validated])
print(result)

Since the regular expression does not have anchors (CWE-777), i.e. is unbounded without ^ or $ characters, then prepending a 0 or 0x to the beginning of the IP address will still result in a matched regex pattern. Since the ping command supports octal and hex prepended IP addresses, it will use the unexpectedly valid IP address (CWE-1389). For example, "0x63.63.63.63" would be considered equivalent to "99.63.63.63". As a result, the attacker could potentially ping systems that the attacker cannot reach directly.

CVE-2002-2109
Regexp isn't "anchored" to the beginning or end, which allows spoofed values that have trusted values as substrings.
https://www.cve.org/CVERecord?id=CVE-2002-2109

CVE-2005-1949
Regexp for IP address isn't anchored at the end, allowing appending of shell metacharacters.
https://www.cve.org/CVERecord?id=CVE-2005-1949

CVE-2001-1072
Bypass access restrictions via multiple leading slash, which causes a regular expression to fail.
https://www.cve.org/CVERecord?id=CVE-2001-1072

CVE-2000-0115
Local user DoS via invalid regular expressions.
https://www.cve.org/CVERecord?id=CVE-2000-0115

CVE-2002-1527
chain: Malformed input generates a regular expression error that leads to information exposure.
https://www.cve.org/CVERecord?id=CVE-2002-1527

CVE-2005-1061
Certain strings are later used in a regexp, leading to a resultant crash.
https://www.cve.org/CVERecord?id=CVE-2005-1061

CVE-2005-2169
MFV. Regular expression intended to protect against directory traversal reduces ".../...//" to "../".
https://www.cve.org/CVERecord?id=CVE-2005-2169

CVE-2005-0603
Malformed regexp syntax leads to information exposure in error message.
https://www.cve.org/CVERecord?id=CVE-2005-0603

CVE-2005-1820
Code injection due to improper quoting of regular expression.
https://www.cve.org/CVERecord?id=CVE-2005-1820

CVE-2005-3153
Null byte bypasses PHP regexp check.
https://www.cve.org/CVERecord?id=CVE-2005-3153

CVE-2005-4155
Null byte bypasses PHP regexp check.
https://www.cve.org/CVERecord?id=CVE-2005-4155

Regular Expression Error

Allowed-with-Review
This CWE entry is a Class and might have Base-level children that would be more appropriate
Examine children of this entry to see if there is a better fit

While there is some overlap with allowlist/denylist problems, this entry is intended to deal with incorrectly written regular expressions, regardless of their intended use. Not every regular expression is intended for use as an allowlist or denylist. In addition, allowlists and denylists can be implemented using other mechanisms besides regular expressions.
Regexp errors are likely a primary factor in many MFVs, especially those that require multiple manipulations to exploit. However, they are rarely diagnosed at this level of detail.

PLOVER
2006-07-19
Draft 3
2006-07-19

Eric Dalci
Cigital
2008-07-01
updated Time_of_Introduction

CWE Content Team
MITRE
2008-09-08
updated Description, Name, Relationships, Observed_Example, Other_Notes, Taxonomy_Mappings

CWE Content Team
MITRE
2009-12-28
updated Common_Consequences, Other_Notes

CWE Content Team
MITRE
2010-02-16
updated References

CWE Content Team
MITRE
2010-04-05
updated Description

CWE Content Team
MITRE
2011-03-29
updated Observed_Examples

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences

CWE Content Team
MITRE
2012-05-11
updated Demonstrative_Examples, Related_Attack_Patterns, Relationships

CWE Content Team
MITRE
2012-10-30
updated Potential_Mitigations

CWE Content Team
MITRE
2014-06-23
updated Applicable_Platforms, Common_Consequences, Other_Notes, Relationship_Notes

CWE Content Team
MITRE
2014-07-30
updated Demonstrative_Examples, Relationships

CWE Content Team
MITRE
2015-12-07
updated Relationships

CWE Content Team
MITRE
2017-11-08
updated References

CWE Content Team
MITRE
2018-03-27
updated References

CWE Content Team
MITRE
2019-06-20
updated Related_Attack_Patterns, Relationships, Type

CWE Content Team
MITRE
2020-02-24
updated Relationships, Type

CWE Content Team
MITRE
2020-06-25
updated Relationship_Notes

CWE Content Team
MITRE
2021-03-15
updated Relationships

CWE Content Team
MITRE
2022-10-13
updated Demonstrative_Examples, Relationships

CWE Content Team
MITRE
2023-01-31
updated Description

CWE Content Team
MITRE
2023-04-27
updated Detection_Factors, Relationships

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Weakness_Ordinalities

Regular Expression Error