CWE-777: Regular Expression without Anchors
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.
Last updated
Overview
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.
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).
Real-world CVEs
2 recorded CVEs are caused by CWE-777 (Regular Expression without Anchors). The highest-severity and most recent are shown first. 2 new CWE-777 CVEs have been recorded so far in 2026.
Common consequences
What can happen when CWE-777 is exploited.
Bypass Protection Mechanism
Affects: Availability, Confidentiality, Access Control
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.
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
How to prevent it
Practical mitigations for CWE-777, grouped by where in the lifecycle they apply.
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.
Code examples
Illustrative examples from MITRE showing how the weakness appears in code.
Consider a web application that supports multiple languages. It selects messages for an appropriate language by using the lang parameter.
Vulnerable example
$dir = "/home/cwe/languages";Attack input
../../etc/passwdThis code uses a regular expression to validate an IP string prior to using it in a call to the "ping" command.
Vulnerable example
import subprocessSince 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.
Illustrative examples
Real CVEs that MITRE cites as examples of this weakness.
- 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).
Frequently asked questions
Common questions about CWE-777.
- What is CWE-777?
- 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.
- What CVEs are caused by CWE-777?
- 2 recorded CVEs are attributed to CWE-777, including CVE-2026-39087, CVE-2026-40110.
- 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.
- Is CWE-777 actively exploited?
- 2 recorded CVEs are caused by CWE-777; none are currently in CISA's KEV catalog of actively exploited flaws.
References
- MITRE CWE definition (CWE-777) (opens in a new tab)
- CWE-777 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Stay ahead of CWE-777
Get alerted the moment a new CWE-777 vulnerability affects your stack, with AI-written analysis, severity context, and remediation guidance.