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

Regex denial of service (ARCH2135)

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

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

Regular expressions with nested quantifiers cause catastrophic backtracking and denial of service (ReDoS) when applied to untrusted input.

import re
def is_valid(s):
return re.fullmatch(r"(\w+)+$", s) is not None
import re
def is_valid(s):
return re.fullmatch(r"\w+", s) is not None

Simplify the pattern to eliminate nested quantifiers, or bound the length of untrusted input.