Skip to content

Commit

Permalink
Don't allow more than 10 repetitions in one pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcutme committed Jul 14, 2017
1 parent 0e930ef commit ac1a03d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/util/SafeRe.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ def isSafePattern(pattern):
unsafe_pattern_match = re.search("[^\.][\*\{\+]", pattern) # Always should be "." before "*{+" characters to avoid ReDoS
if unsafe_pattern_match:
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


Expand Down

0 comments on commit ac1a03d

Please sign in to comment.