تخطَّ إلى المحتوى

Regex denial of service (ARCH4135)

هذا المحتوى غير متوفر بلغتك بعد.

Key java.security.regex-dos · Severity warning · Category security · CWE CWE-1333

Regexes with nested quantifiers (e.g. (a+)+) applied to untrusted input cause catastrophic backtracking; an attacker can exhaust CPU with a short input (ReDoS).

Pattern p = Pattern.compile("(a+)+$");
boolean match = p.matcher(userInput).matches();
Pattern p = Pattern.compile("a+$");
boolean match = p.matcher(userInput).matches();

Simplify the regex to remove nested quantifiers; bound input length or use a linear-time engine.