Inefficient Regular Expression Complexity in faisalman/ua-parser-js
Reported on
Sep 16th 2021
Description
Hello my dear
I found another inefficient regular expression in ua-parser-js
that have a Polynomial execution time ( not exponential but still dangerous).
Proof of Concept
I create two payloads that you can compare the execution times between them in Regexr provided links.
payload 1
https://regexr.com/65o79
payload 2
https://regexr.com/65o7c
if you got error in execution time in Regexr this means that the execution time is greater that 2.5 second.
SECURITY.md
2 years ago
Hi, thanks for reporting the issue, I have followed the links that you give but I don't see the error in execution time that you mentioned.. Can you provide more details regarding this issue? Thanks
excuse me for my bad explanation
first open this url https://regexr.com/
and use /^\s+|\s+$/g
that already placed in your code.
this is a correct input for this regex that have a low time execution and you should copy the spaces too :
fdsfsdffdsfsdffdsfsdffdsfsdffdsfsdffdsfsdffdsfsdf
this is a bad crafted input :
fdsfsdffdsfsdffdsfsdffdsfsdffdsfsdffdsfsdffdsfsdf ffffff
if you compare the execution time of this two payloads you can find out that the regex is inefficient.
I mentioned to error because if you face with error in Regexr.com
you understand this means the execution time is too much.
I can provide a PoC video just tell me to do that
and If there isn't any problem can I ask you just validate my report? the report will remain confidential until you submit a patch for it.
No, that's okay, I also found this article https://blog.stevenlevithan.com/archives/faster-trim-javascript which also says that the approach I'm currently using is slow when working with long strings and the article suggests using two separate replace() as a faster implementation
https://github.com/faisalman/ua-parser-js/commit/336ce2b9502923fb931615598dfb0baefed04f5d
Do you think this solved the original issue?
@maintainer - are you able to confirm the fix against the report?
We can then go ahead and publish a CVE on your behalf.
Thanks! 👏
The original fix turns out to be vulnerable as well, which later fixed in https://github.com/faisalman/ua-parser-js/commit/a6140a17dd0300a35cfc9cff999545f267889411