CWE
Home > CWE List > CWE- Individual Dictionary Definition (1.0)  
Search by ID:

CWE-625: Permissive Regular Expression

Individual Definition in a New Window
Permissive Regular Expression
Status: Draft
Weakness ID: 625 (Weakness Base)
Description
Summary

The product uses a regular expression that does not sufficiently restrict the set of allowed values.

Extended Description

This effectively causes the regexp to accept substrings that match the pattern, which produces a partial comparison to the target. In some cases, this can lead to other weaknesses. Common errors include: (1) not identifying the beginning and end of the target string; (2) using wildcards instead of acceptable character ranges; and others.

Weakness Ordinalities
Primary (where the weakness exists independent of other weaknesses)
Potential Mitigations

When applicable, ensure that your regular expression marks beginning and ending string patterns, such as "/^string$/" for Perl.

Demonstrative Examples

$phone = GetPhoneNumber();
if ($phone =~ /\d+-\d+/) {
# looks like it only has hyphens and digits
system("lookup-phone $phone");
}
else {
error("malformed number!");
}

An attacker could provide an argument such as: "; ls -l ; echo 123-456" This would pass the check, since "123-456" is sufficient to match the "\d+-\d+" portion of the regular expression.

Observed Examples
ReferenceDescription
".*" regexp leads to static code injection
insertion of username into regexp results in partial comparison, causing wrong database entry to be updated when one username is a substring of another.
regexp intended to verify that all characters are legal, only checks that at least one is legal, enabling file inclusion.
Regexp for IP address isn't anchored at the end, allowing appending of shell metacharacters.
Regexp isn't "anchored" to the beginning or end, which allows spoofed values that have trusted values as substrings.
regexp in .htaccess file allows access of files whose names contain certain substrings
allow load of macro files whose names contain certain substrings.
 VIM Mailing list, March 14, 2006
Other Notes

This problem is frequently found when the regular expression is used in input validation or security features such as authentication.

Relationships
NatureTypeIDNameView(s) this relationship pertains toView(s)
ChildOfWeakness ClassWeakness ClassWeakness Class185Incorrect Regular Expression
Development Concepts (primary)699
Research Concepts (primary)1000
PeerOfWeakness BaseWeakness BaseWeakness Base187Partial Comparison
Research Concepts1000
PeerOfWeakness BaseWeakness BaseWeakness Base184Incomplete Blacklist
Research Concepts1000
PeerOfWeakness BaseWeakness BaseWeakness Base183Permissive Whitelist
Research Concepts1000
Applicable Platforms
Languages
Perl
PHP
Time of Introduction
* Implementation
Content History
Modifications
Eric Dalci. Cigital. 2008-07-01. (External)
updated Time_of_Introduction
CWE Content Team. MITRE. 2008-09-08. (Internal)
updated Applicable_Platforms, Description, Relationships, Observed_Example, Other_Notes, Weakness_Ordinalities
Page Last Updated: September 10, 2008