Don't allow more than 10 repetitions in one pattern

This commit is contained in:
shortcutme 2017-07-15 01:30:53 +02:00
parent 0e930efd95
commit ac1a03d17b
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -14,6 +14,11 @@ def isSafePattern(pattern):
unsafe_pattern_match = re.search("[^\.][\*\{\+]", pattern) # Always should be "." before "*{+" characters to avoid ReDoS unsafe_pattern_match = re.search("[^\.][\*\{\+]", pattern) # Always should be "." before "*{+" characters to avoid ReDoS
if unsafe_pattern_match: if unsafe_pattern_match:
raise UnsafePatternError("Potentially unsafe part of the pattern: %s" % unsafe_pattern_match.group(0)) raise UnsafePatternError("Potentially unsafe part of the pattern: %s" % unsafe_pattern_match.group(0))
repetitions = re.findall("\.[\*\{\+]", pattern)
if len(repetitions) >= 10:
raise UnsafePatternError("More than 10 repetitions of %s" % repetitions[0])
return True return True