---
title: "CWE-777: Regular Expression without Anchors"
url: https://radicalnotion.ai/cwe/cwe-777
type: cwe
description: "The product uses a regular expression to perform neutralization, but the regular expression omits one or more anchors that may allow malicious or malformed data to slip through."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-777: Regular Expression without Anchors

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 6
- **Of those, in CISA KEV:** 0
- **New in 2026:** 6
- **CWE catalog version:** 4.21

## Description

The product uses a regular expression to perform neutralization, but the regular expression omits one or more anchors that may allow malicious or malformed data to slip through.

## Background

Regular expressions are typically used to match a pattern of text. Anchors are used in regular expressions to specify where the pattern should match: at the beginning, the end, or both (the whole input). When performing tasks such as validating against a set of allowed inputs (allowlist), data is examined and possibly modified to ensure that it is well-formed and adheres to a list of safe values.

## Modes of introduction

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

## Applicable platforms

**Languages:** Python (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Availability, Confidentiality, Access Control | Bypass Protection Mechanism, Varies by Context | An unanchored regular expression in the context of an allowlist will possibly result in a protection mechanism failure. Malicious or malformed data may be included before or after any string matching the regular expression, allowing the data to enter trusted regions of the program. The type of malicious data that is allowed will depend on the context of the application and which anchors are omitted from the regular expression. The specific consequences will depend on what functionality the allowlist was protecting. |

## Potential mitigations

### Implementation

Be sure to understand both what will be matched and what will not be matched by a regular expression. Anchoring the ends of the expression will allow the programmer to define an allowlist strictly limited to what is matched by the text in the regular expression. If you are using a package that only matches one line by default, ensure that you can match multi-line inputs if necessary.

## Demonstrative examples

### Example 1

Consider a web application that supports multiple languages. It selects messages for an appropriate language by using the lang parameter.

Bad code:

```php
$dir = "/home/cwe/languages";
$lang = $_GET['lang'];
if (preg_match("/[A-Za-z0-9]+/", $lang)) {
    include("$dir/$lang");
}
else {
    echo "You shall not pass!\n";
}
```

Attack code:

```
../../etc/passwd
```

### 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-2022-30034 | Chain: Web UI for a Python RPC framework does not use regex anchors to validate user login emails (CWE-777), potentially allowing bypass of OAuth (CWE-1390). |

## Real CVEs with this weakness

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-78191 | WebDyne versions from 2.031 before 3.022 for Perl execute files with .psp anywhere in the name as Perl pages | critical | 9.8 | - | No | 2026-10-31 |
| CVE-2026-39087 | ntfy.sh allows a remote attacker to execute arbitrary code via the parseActions function | critical | 9.8 | - | No | 2026-04-23 |
| CVE-2026-105803 | Git LFS may execute arbitrary commands via crafted Git LFS configurations | high | 8.6 | - | No | 2026-11-19 |
| CVE-2026-40110 | jupyter-server CORS origin validation bypass via unanchored regex in allow\_origin\_pat | high | 7.6 | - | No | 2026-05-05 |
| CVE-2026-22068 | Apache Traffic Server: Regex mappings match with malicious domain names | medium | 6.9 | - | No | 2026-07-29 |
| CVE-2026-97736 | - | medium | 5.4 | - | No | 2026-09-25 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-625](https://radicalnotion.ai/cwe/cwe-625) | Permissive Regular Expression |

## Frequently asked questions

### What is CWE-777?

The product uses a regular expression to perform neutralization, but the regular expression omits one or more anchors that may allow malicious or malformed data to slip through.

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

6 recorded CVEs are attributed to CWE-777, including CVE-2026-78191, CVE-2026-39087 and CVE-2026-105803.

### How do you prevent CWE-777?

Be sure to understand both what will be matched and what will not be matched by a regular expression. Anchoring the ends of the expression will allow the programmer to define an allowlist strictly limited to what is matched by the text in the regular expression. If you are using a package that only matches one line by default, ensure that you can match multi-line inputs if necessary.

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

Exploiting CWE-777 can lead to: Bypass Protection Mechanism, Varies by Context.

### Is CWE-777 actively exploited?

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

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

---

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