CWE
Home > CWE List > CWE-185 Individual Dictionary Definition (Draft 9)   View the CWE List

CWE-185 Individual Dictionary Definition (Draft 9)

Regular Expression Error
Weakness ID
Status: Draft

185 (Weakness Class)

Description

Summary

A regular expression is incorrectly specified in a way that causes data to be improperly filtered, compared, or cleansed.

Potential Mitigations

Regular expressions can become error prone when defining a complex language even for those experienced in writing grammars. Determine if several smaller regular expressions simplifies one large regular expression. Also, subject your 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 full proof. If an exploit is allowed to slip through, then record the exploit and refactor your regular expression.

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

Keywords: regexp

This can seem to overlap whitelist/blacklist problems, but it is intended to deal with improperly written regular expressions, regardless of the values that those regular expressions use.

Can overlap partial comparison.

Interacts with null byte in PHP.

Research Gaps

Regexp errors are likely a primary factor in many MFVs, especially those that require multiple manipulations to exploit. However, they are rarely diagnosed at this level of detail.

Relationships
NatureTypeIDName
ChildOfCategoryCategory171Cleansing, Canonicalization, and Comparison Errors
CanAlsoBeWeakness BaseWeakness BaseWeakness Base187Partial Comparison
CanAlsoBeWeakness BaseWeakness BaseWeakness Base182Collapse of Data Into Unsafe Value
ParentOfWeakness BaseWeakness BaseWeakness Base186Overly Restrictive Regular Expression
ParentOfWeakness BaseWeakness BaseWeakness Base625Permissive Regular Expression
Source Taxonomies

PLOVER - Regular Expression Error

Applicable Platforms

All

Related Attack Patterns
CAPEC-IDAttack Pattern Name
79Using Slashes in Alternate Encoding
15Command Delimiters
6Argument Injection
Page Last Updated: April 21, 2008