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
JS: Atomic group polyfill not detected as a ReDOS mitigation #9062
Comments
|
Yes the ReDoS analysis doesn't really understand back-references or lookaheads. And yes, that's an FP. But I also think your regexp is broken, and fixing the regexp would also remove the ReDoS FP. I can get the regexp to match strings like From the name of the regexp it sounds like you are trying to match char escapes (which it does) and char classes (it only matches Maybe try Some examples that show why I think your current regexp is broken: > /^(?:\\.|\[(?=((?:\\.|.)*?))\1\])$/.test("\\d") // should match - and does - good
true
> /^(?:\\.|\[(?=((?:\\.|.)*?))\1\])$/.test("[]") // should not match - but does - bad
true
> /^(?:\\.|\[(?=((?:\\.|.)*?))\1\])$/.test("[a-z]") // should match - but doesn't - bad
false |
|
Mmmh, indeed, well spotted thanks, there's a hole in my test suite, and another one in my understanding of look aheads :-) Thankfully, the bug has no consequence on the functionality of the lib. This is part of the logic to determine if a non-capturing group is required before applying a quantifier. This bug means there will be useless non-capturing groups. It will soon be fixed. Edit2: I went for the atomic version of your suggestion, with Btw, I may reject it at some point, because it makes little sense to quantify |
No problem.
Hmm. I misremembered. It's a syntax errors in some languages, I just remembered wrong for JS.
This is nitpicking, but I'm not fond of using features like backreferences when something can be expressed using a plain regular expression. Looking at your regexp and mine, they don't match the same things (not just the The proper fix (I think), is to modify the regular expression to something like: |
Description of the false positive
You can polyfill atomic groups in JS by using the
/(?=(...))\1//pattern, but LGTM doesn't seem to understand it and reports a false positive here.Here's the culprit:
There are other similar cases in the project, it is a RegExp composition lib that provides an
atomic(x)helper that wrapsxaccordingly (and uses such RegExps internally).Still, to my amusement (and slight consternation), LGTM caught an polynomial ReDOS in my lib... Thanks for the project.
URL to the alert on the project page on LGTM.com
https://lgtm.com/projects/g/compose-regexp/compose-regexp.js/snapshot/e31d432f942019263401085e38558c5661dc7460/files/commonjs/compose-regexp.js?sort=name&dir=ASC&mode=heatmap#xdcee8d483c053100:1
The text was updated successfully, but these errors were encountered: