CWE-185: Incorrect Regular Expression
CWE版本: 4.18
更新日期: 2025-09-09
弱点描述
The product specifies a regular expression in a way that causes data to be improperly matched or compared.
扩展描述
When the regular expression is used in protection mechanisms such as filtering or validation, this may allow an attacker to bypass the intended restrictions on the incoming data.
常见后果
影响范围: Other
技术影响: Unexpected State Varies by Context
说明: When the regular expression is not correctly specified, data might have a different format or type than the rest of the program expects, producing resultant weaknesses or errors.
影响范围: Access Control
技术影响: Bypass Protection Mechanism
说明: In PHP, regular expression checks can sometimes be bypassed with a null byte, leading to any number of weaknesses.
潜在缓解措施
阶段: Architecture and Design
策略: Refactoring
描述: Regular expressions can become error prone when defining a complex language even for those experienced in writing grammars. Determine if several smaller regular expressions simplify one large regular expression. Also, subject the 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 foolproof. If an exploit is allowed to slip through, then record the exploit and refactor the regular expression.
检测方法
方法: Automated Static Analysis
Automated 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
观察示例
参考: CVE-2002-2109
Regexp isn't "anchored" to the beginning or end, which allows spoofed values that have trusted values as substrings.
参考: CVE-2005-1949
Regexp for IP address isn't anchored at the end, allowing appending of shell metacharacters.
参考: CVE-2001-1072
Bypass access restrictions via multiple leading slash, which causes a regular expression to fail.
参考: CVE-2000-0115
Local user DoS via invalid regular expressions.
参考: CVE-2002-1527
chain: Malformed input generates a regular expression error that leads to information exposure.
参考: CVE-2005-1061
Certain strings are later used in a regexp, leading to a resultant crash.
参考: CVE-2005-2169
MFV. Regular expression intended to protect against directory traversal reduces ".../...//" to "../".
参考: CVE-2005-0603
Malformed regexp syntax leads to information exposure in error message.
参考: CVE-2005-1820
Code injection due to improper quoting of regular expression.
参考: CVE-2005-3153
Null byte bypasses PHP regexp check.
参考: CVE-2005-4155
Null byte bypasses PHP regexp check.
引入模式
| 阶段 | 说明 |
|---|---|
| Implementation | - |
适用平台
编程语言
分类映射
| 分类名称 | 条目ID | 条目名称 | 映射适配度 |
|---|---|---|---|
| PLOVER | - | Regular Expression Error | - |