Regular expression DoS (ARCH6135)
Ce contenu n’est pas encore disponible dans votre langue.
Key ruby.security.regex-dos · Severity warning · Category security · CWE CWE-1333
Applying a regex with nested quantifiers (causing catastrophic backtracking) to untrusted input leads to a CPU-exhausting denial of service (ReDoS).
Incorrect
Section titled “Incorrect”def valid?(input) input =~ /^(a+)+$/endCorrect
Section titled “Correct”def valid?(input) Regexp.new("^a+$").match?(input, timeout: 1)endAvoid nested quantifiers and add a timeout/length limit to regex matching.