-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Protection against ReDoS #6163
Protection against ReDoS #6163
Conversation
This PR is related to #5996. |
We decided to ship with regex (#4641 (comment)) so we should merge this PR before that PR gets merged, or merge this PR into the other first. |
Even less, should be better. Parsing a regex shouldn't take more than 1s. |
The regex module is compatible with the re module (VERSION0 flag). It is also faster. ```python >>> import re >>> import regex >>> import timeit >>> pattert = "(a+)+b" >>> input = "a" * 25 >>> timeit.timeit(lambda: re.search(pattern, input), number=10) 32.332445038000515 >>> timeit.timeit(lambda: regex.search(pattern, input, flags=regex.VERSION0), number=10) 0.003861578001306043 >>> input = "a" * 10000 >>> regex.search(pattern, input, flags=regex.VERSION0, timeout=5) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/stsewd/.pyenv/versions/readthedocs.org/lib/python3.6/site-packages/regex/regex.py", line 266, in search concurrent, partial, timeout) TimeoutError: regex timed out ```
48e187f
to
7cc0b47
Compare
Ok, I've decreased the timeout to 1 second. Another alternative is to use a finite state machine type of regex, but I wasn't able to find one lib for python... |
The regex module is compatible with the re module (VERSION0 flag).
It is also faster.
I put the timeout to 15, maybe we can drop it to 5?