CWE一覧に戻る
CWE-186

過度に制限された正規表現

Overly Restrictive Regular Expression
脆弱性 レビュー中
JA

正規表現は過度に制限的であるため、危険な値が検出されない。

この弱点は正規表現の複雑さについてではない。むしろ、正規表現が意図したすべての値にマッチしないということです。許容される値を特定するため、あるいは、不要な用語を発見するために正規表現を使用することを考えてください。正規表現が過度に制限されていると、コードの中で正規表現がどのように使用されているかによって、セキュリ ティに関連する可能性のある値を見逃してしまい、偽陽性(false positive)または偽陰性(false negative)になってしまいます。例えば、/[0-8]/という表現を考えてみてください。 この式は「複雑」ではないが、プログラマーが「9」をチェックするつもりだったのかもしれないのに、「9」という値はマッチしない。

EN

A regular expression is overly restrictive, which prevents dangerous values from being detected.

This weakness is not about regular expression complexity. Rather, it is about a regular expression that does not match all values that are intended. Consider the use of a regexp to identify acceptable values or to spot unwanted terms. An overly restrictive regexp misses some potentially security-relevant values leading to either false positives *or* false negatives, depending on how the regexp is being used within the code. Consider the expression /[0-8]/ where the intention was /[0-9]/. This expression is not "complex" but the value "9" is not matched when maybe the programmer planned to check for it.

Scope: Access Control / Impact: Bypass Protection Mechanism
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 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 foolproof. If an exploit is allowed to slip through, then record the exploit and refactor your regular expression.
MITRE公式ページ — CWE-186