---
title: "CWE-185: Incorrect Regular Expression"
url: https://radicalnotion.ai/cwe/cwe-185
type: cwe
description: "The product specifies a regular expression in a way that causes data to be improperly matched or compared."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-185: Incorrect Regular Expression

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 40
- **Of those, in CISA KEV:** 0
- **New in 2026:** 20
- **CWE catalog version:** 4.21

## Description

The product specifies a regular expression in a way that causes data to be improperly matched or compared.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | - |

## Applicable platforms

**Languages:** Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| 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 | 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. |
| Access Control | Bypass Protection Mechanism | In PHP, regular expression checks can sometimes be bypassed with a null byte, leading to any number of weaknesses. |

## Potential mitigations

### Implementation (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.

## Detection methods

### 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.)

Effectiveness: High

## Demonstrative examples

### Example 1

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

Bad code:

```perl
$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.

### Example 2

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

Bad code:

```python
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.

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2002-2109 | Regexp isn't "anchored" to the beginning or end, which allows spoofed values that have trusted values as substrings. |
| CVE-2005-1949 | Regexp for IP address isn't anchored at the end, allowing appending of shell metacharacters. |
| CVE-2001-1072 | Bypass access restrictions via multiple leading slash, which causes a regular expression to fail. |
| CVE-2000-0115 | Local user DoS via invalid regular expressions. |
| CVE-2002-1527 | Chain: Malformed input generates a regular expression error that leads to information exposure. |
| CVE-2005-1061 | Certain strings are later used in a regexp, leading to a resultant crash. |
| CVE-2005-2169 | MFV. Regular expression intended to protect against directory traversal reduces ".../...//" to "../". |
| CVE-2005-0603 | Malformed regexp syntax leads to information exposure in error message. |
| CVE-2005-1820 | Code injection due to improper quoting of regular expression. |
| CVE-2005-3153 | Null byte bypasses PHP regexp check (interaction error). |
| CVE-2005-4155 | Null byte bypasses PHP regexp check (interaction error). |

## Real CVEs with this weakness (sample of 12 of 40)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-111057 | Mercury: Unauthenticated Remote Code Execution in /api/terminals - access control bypass | critical | 10.0 | - | No | 2026-10-19 |
| CVE-2024-2223 | Incorrect Regular Expression in GravityZone Update Server (VA-11465) | critical | 9.8 | - | No | 2024-04-09 |
| CVE-2019-12798 | - | critical | 9.8 | - | No | 2019-06-13 |
| CVE-2026-25896 | fast-xml-parser has an entity encoding bypass via regex injection in DOCTYPE entity names | critical | 9.3 | - | No | 2026-02-20 |
| CVE-2026-27895 | LAM has incorrect regular expression in PDF export component that allows user to upload files of any type | high | 8.8 | - | No | 2026-03-17 |
| CVE-2020-3408 | Cisco IOS and IOS XE Software Split DNS Denial of Service Vulnerability | high | 8.6 | - | No | 2020-09-24 |
| CVE-2026-111755 | follow-redirects sensitiveHeaders regex escaping can expose credential headers | high | 8.2 | - | No | 2026-10-19 |
| CVE-2024-52289 | authentik has an insecure default configuration for OAuth2 Redirect URIs | high | 7.9 | - | No | 2024-11-21 |
| CVE-2018-17984 | - | high | 7.8 | - | No | 2018-10-04 |
| CVE-2026-88021 | Consul vulnerable to an authorization bypass in the Connect service mesh | high | 7.5 | - | No | 2026-09-10 |
| CVE-2026-4296 | Incorrect Regular Expression vulnerability in GitHub Enterprise Server allowed unauthorized access to user accounts via OAuth callback URL validation bypass | high | 7.5 | - | No | 2026-04-21 |
| CVE-2026-33418 | @dicebear/converter ensureSize() Vulnerable to SVG Dimension Capping Bypass via XML Comment Injection | high | 7.5 | - | No | 2026-03-24 |

## Related attack patterns (CAPEC)

- [CAPEC-15](https://radicalnotion.ai/capec/capec-15): Command Delimiters
- [CAPEC-6](https://radicalnotion.ai/capec/capec-6): Argument Injection
- [CAPEC-79](https://radicalnotion.ai/capec/capec-79): Using Slashes in Alternate Encoding

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-697](https://radicalnotion.ai/cwe/cwe-697) | Incorrect Comparison |
| Child | [CWE-186](https://radicalnotion.ai/cwe/cwe-186) | Overly Restrictive Regular Expression |
| Child | [CWE-625](https://radicalnotion.ai/cwe/cwe-625) | Permissive Regular Expression |
| Can precede | [CWE-182](https://radicalnotion.ai/cwe/cwe-182) | Collapse of Data into Unsafe Value |
| Can precede | [CWE-187](https://radicalnotion.ai/cwe/cwe-187) | Partial String Comparison |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Regular Expression Error | - | - |

## Frequently asked questions

### What is CWE-185?

The product specifies a regular expression in a way that causes data to be improperly matched or compared.

### What CVEs are caused by CWE-185?

40 recorded CVEs are attributed to CWE-185, including CVE-2026-111057, CVE-2024-2223 and CVE-2019-12798.

### How do you prevent CWE-185?

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.

### How is CWE-185 detected?

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.)

### What are the consequences of CWE-185?

Exploiting CWE-185 can lead to: Unexpected State, Varies by Context, Bypass Protection Mechanism.

### Is CWE-185 actively exploited?

40 recorded CVEs are caused by CWE-185; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/185.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-185). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
