CWE-185: Incorrect Regular Expression
The product specifies a regular expression in a way that causes data to be improperly matched or compared.
Last updated
The product specifies a regular expression in a way that causes data to be improperly matched or compared.
Last updated
42 recorded CVEs are caused by CWE-185 (Incorrect Regular Expression). The highest-severity and most recent are shown first. 22 new CWE-185 CVEs have been recorded so far in 2026 (1 in 2025).
Mercury: Unauthenticated Remote Code Execution in /api/terminals - access control bypass
Incorrect Regular Expression in GravityZone Update Server (VA-11465)
fast-xml-parser has an entity encoding bypass via regex injection in DOCTYPE entity names
LAM has incorrect regular expression in PDF export component that allows user to upload files of any type
Cisco IOS and IOS XE Software Split DNS Denial of Service Vulnerability
follow-redirects sensitiveHeaders regex escaping can expose credential headers
authentik has an insecure default configuration for OAuth2 Redirect URIs
Consul vulnerable to an authorization bypass in the Connect service mesh
Incorrect Regular Expression vulnerability in GitHub Enterprise Server allowed unauthorized access to user accounts via OAuth callback URL validation bypass
@dicebear/converter ensureSize() Vulnerable to SVG Dimension Capping Bypass via XML Comment Injection
Showing 12 of 42 recorded CWE-185 CVEs. Get an alert for each new one, with AI-written analysis and fixes.
Monitor these CVEsWhat can happen when CWE-185 is exploited.
Unexpected State, Varies by Context
Affects: Other
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.
Bypass Protection Mechanism
Affects: Access Control
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.
Bypass Protection Mechanism
Affects: Access Control
In PHP, regular expression checks can sometimes be bypassed with a null byte, leading to any number of weaknesses.
Typically introduced during these phases of the software lifecycle.
Languages
Practical mitigations for CWE-185, grouped by where in the lifecycle they apply.
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.
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.)
Effectiveness: High
MITRE examples of the weakness in code.
The following code takes phone numbers as input, and uses a regular expression to reject invalid phone numbers.
Vulnerable example
$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.
Vulnerable example
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.
Real CVEs that MITRE cites as examples of this weakness.
CAPEC attack patterns that exploit this weakness.
Common questions about CWE-185.
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Get an alert when a new CWE-185 CVE affects your products, with AI-written analysis and remediation steps.