-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
use full-string match to speed up aspnet regex match #2939
Conversation
Original expression /(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/ rvagg's fix /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?(?:\d*)?)?$/ There is essentially a duplicate 0 or more condition ( /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?(?:\d+)?)?$/ /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?(?:\d*))?$/ The last one can be simplified even more without loosing any functionality: /^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/ |
smarty pants updated with @Starefossen's regex what's that tool @Starefossen? |
Either fix seems acceptable from a security perspective. Both remove the extreme blocking behavior and take upwards of around 2.5 million characters to take 1 second of cpu time. so 👍 Thank you @rvagg and @Starefossen |
Thanks! |
Staging for next release. @ichernev - Due to the security implications, it may make sense to release this separately as 2.11.2, unless you're ready to merge the other PRs I've marked for 2.12.0. Your call. |
Since this seems to be breaking builds left and right (hurrah, popularity!) my vote is to release it ASAP as a patch version. |
Merged in 52a807b |
use full-string match to speed up aspnet regex match
This is available now in 2.11.2. Thanks @ichernev for getting this out. |
Thank you @rvagg and @Starefossen for working on this. @joeybaker thank you for reporting. Is there any way I can get my email for the moment security advisories? |
@ichernev FWIW, you might try adding https://www.npmjs.com/package/nsp to the tests. It would then fail the build if moment or any of its deps had a security vulnerability. @nlf, @daviddias, or @evilpacket might know more about an email list? |
Fixes: #2936
C# duration match was almost complete enough to match full-strings, just needed to allow for the extra digits in microseconds. Getting to put in
^
$
resolves the speed problem reported @ #2936.