Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CWE-777 — Vulnerability Class 1

1 vulnerabilities classified as CWE-777. AI Chinese analysis included.

CWE-777 represents a critical input validation weakness where regular expressions lack proper anchoring, allowing malicious data to bypass security controls. This flaw typically occurs when developers use patterns to sanitize or validate user input without enforcing strict boundaries, such as missing start (^) or end ($) anchors. Attackers exploit this by injecting carefully crafted payloads that partially match the allowed pattern, effectively slipping through neutralization mechanisms intended to filter out harmful content. For instance, a regex designed to block specific keywords might fail if an attacker appends the keyword to a valid string. To prevent this, developers must ensure all regular expressions used for validation are fully anchored, explicitly defining the start and end of the expected input. This guarantees that only complete, well-formed strings matching the entire pattern are accepted, eliminating the risk of partial matches enabling injection attacks or data corruption.

MITRE CWE Description
The product uses a regular expression to perform neutralization, but the regular expression is not anchored and may allow malicious or malformed data to slip through. 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. If the regular expression is not anchored, malicious or malformed data may be included before or after any string matching the regular expression. 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.
Common Consequences (1)
Availability, Confidentiality, Access ControlBypass Protection Mechanism
An unanchored regular expression in the context of an allowlist will possibly result in a protection mechanism failure, allowing malicious or malformed data to enter trusted regions of the program. The specific consequences will depend on what functionality the allowlist was protecting.
Mitigations (1)
ImplementationBe 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.
Examples (2)
Consider a web application that supports multiple languages. It selects messages for an appropriate language by using the lang parameter.
$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"; }
Bad · PHP
../../etc/passwd
Attack
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)
Bad · Python

Vulnerabilities classified as CWE-777 represent 1 CVEs. The CWE taxonomy describes the weakness; review individual CVEs for product-specific impact.