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

Regular expression DoS (ARCH6135)

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

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).

def valid?(input)
input =~ /^(a+)+$/
end
def valid?(input)
Regexp.new("^a+$").match?(input, timeout: 1)
end

Avoid nested quantifiers and add a timeout/length limit to regex matching.