Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

malicious regular expressions #24

Open
dominictarr opened this issue Mar 19, 2015 · 3 comments
Open

malicious regular expressions #24

dominictarr opened this issue Mar 19, 2015 · 3 comments

Comments

@dominictarr
Copy link
Contributor

This is vunerable to evil regular expressions. It's possible to construct a regular expression that executes in exponential time, which won't look like an obvious infinite loop, but will lock the cpu for a while.

require('notevil')("/((a+)+)b/.test('aaaaaaaaaaaaaaaaaaaaaaaaaaaaa')")

This tricks the regex evaluator into searching for all possible ways to arrange the two nested a groups,
(since the string is missing a b at the end it will continue searching, if it had a b it would return as soon as it has found a match)

the simplest way to prevent this is just to block regular expressions with a starheight > 1 (i.e. with nested groups) this may block some non-evil regular expressions, but is much simpler than implementing a regular expression interpreter.

for more detail: http://perlgeek.de/blog-en/perl-tips/in-search-of-an-exponetial-regexp.html

also, @substack has a module for detecting safe regular expressions: https://github.com/substack/safe-regex

@mmckegg
Copy link
Owner

mmckegg commented Mar 19, 2015

i knew this would be a rabbit hole 😵

@aredridel
Copy link

Boom!

@dominictarr
Copy link
Contributor Author

hey it looks like this might do it: https://github.com/aaditmshah/regex
you'd just need to add the run time checker... maybe use the native regex engine for safe regular expressions and the interpreted one for unsafe.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants