CWE-1333: Inefficient Regular Expression Complexity

What is CWE-1333?

CWE-1333 is Inefficient Regular Expression Complexity. The flaw arises when the product uses a regular expression whose worst-case computational complexity is inefficient and may be exponential. The database currently holds 183 vulnerabilities mapped to CWE-1333 and none of them are in the CISA Known Exploited Vulnerabilities catalog.

OWASP Top 10 Rank-
Related CVES (365 days)183
AbstractionBase
Likelihood of exploitHigh

Vulnerabilities mapped to CWE-1333

183 vulnerabilities663% increase year over year

No data

No vulnerability data in CISA KEV for CWE-1333

Official definition

ByMitre CWE

The product uses a regular expression with a worst-case computational complexity that is inefficient and possibly exponential.

Some regular expression engines have a feature called "backtracking". If the token cannot match, the engine "backtracks" to a position that may result in a different token that can match.

Detailed description

Some regular-expression engines use backtracking to try alternative parses when a token does not match. If an expression permits an exponential number of backtracking attempts relative to input length, a long input designed to fail can force excessive computation. The weakness commonly arises during implementation when easy-to-write patterns with unbounded matching characters are used without considering backtracking cost. This behavior is commonly called ReDoS or catastrophic backtracking.

Characteristics

The weakness commonly appears in expressions that create many possible backtracking paths, especially through nested quantifiers or overlapping capture groups. In engines that support backtracking, a failed token can cause the engine to return to an earlier position and try another matching path. The risk becomes significant when the number of attempts grows exponentially with input length, the input can fail to match, and the input can be sufficiently long. The record identifies this as not language-specific and also lists Go as an applicable platform.

Common consequences

The primary consequence is an availability impact through CPU resource consumption. An attacker can provide crafted input that triggers excessive backtracking, causing CPU usage to spike and potentially delaying or preventing processing of other requests or messages. The record characterizes this as denial of service.

ImpactScopeExplanation
DoS: Resource Consumption (CPU)AvailabilityAttackers can create crafted inputs that intentionally cause the regular expression to use excessive backtracking in a way that causes the CPU consumption to spike.

Risk mitigations

  • Architecture and design: Prefer regular-expression implementations that do not support backtracking, for example by removing nested quantifiers. This is one of the few highly effective options when regular expressions are supplied by users.
  • System configuration: Configure backtracking limits for the regular-expression implementation, such as PHP's pcre.backtrack_limit, and consider limiting the process execution time.
  • Implementation: Do not apply regular expressions to untrusted input where this can be avoided. When regular expressions are necessary, avoid backtracking in the expression.
  • Input handling: Limit the length of input processed by the regular expression.
  1. Architecture and Design · Effectiveness: HighUse regular expressions that do not support backtracking, e.g. by removing nested quantifiers.This is one of the few effective solutions when using user-provided regular expressions.
  2. System Configuration · Effectiveness: ModerateSet backtracking limits in the configuration of the regular expression implementation, such as PHP's pcre.backtrack_limit. Also consider limits on execution time for the process.
  3. Implementation · Effectiveness: HighDo not use regular expressions with untrusted input. If regular expressions must be used, avoid using backtracking in the expression.
  4. Implementation · Effectiveness: ModerateLimit the length of the input that the regular expression will process.

Detection methods

Automated static analysis, commonly called Static Application Security Testing (SAST), can identify some instances by analyzing source code or binary/compiled code without execution. It typically builds data-flow and control-flow models, then searches for potentially vulnerable patterns connecting input sources with regular-expression processing or external components. This approach may not identify every expression with excessive backtracking, so assessment should also consider the expression structure and input-length limits.

MethodApproachEffectiveness
Automated Static AnalysisAutomated 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.)High

Representative vulnerabilities

Representative examples in the record include:

  • CVE-2020-5243: a server could be subjected to ReDoS through crafted User-Agent strings because overlapping capture groups caused excessive backtracking.
  • CVE-2021-21317: an npm user-agent parser package was susceptible to ReDoS due to overlapping capture groups.
  • CVE-2019-16215: a Markdown parser used an inefficient regular expression, allowing CPU consumption and delays that prevented other messages from being processed.
  • CVE-2019-6785: a long string in a version-control product could cause denial of service through an inefficient regular expression.
  • CVE-2019-12041: JavaScript code permitted ReDoS through a long string because of excessive backtracking.
  • CVE-2015-8315: ReDoS occurred while parsing time.
  • CVE-2015-8854: ReDoS occurred while parsing documents.
  • CVE-2017-16021: ReDoS occurred while validating a URL.

These are curated representative examples from the record, not an exhaustive list of vulnerabilities.

Sources (2)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.