Skip to content
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

Closed
wants to merge 1 commit into from
Closed

use full-string match to speed up aspnet regex match #2939

wants to merge 1 commit into from

Conversation

rvagg
Copy link
Contributor

@rvagg rvagg commented Feb 2, 2016

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.

@Starefossen
Copy link

Original expression

/(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?)?/

screen shot 2016-02-02 at 10 21 48

rvagg's fix

/^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?(?:\d*)?)?$/

screen shot 2016-02-02 at 10 21 38

There is essentially a duplicate 0 or more condition (* with a ?) at the end of this expression that can be optimised in the following two ways:

/^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?(?:\d+)?)?$/

screen shot 2016-02-02 at 10 28 19

/^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?(?:\d*))?$/

screen shot 2016-02-02 at 10 28 43

The last one can be simplified even more without loosing any functionality:

/^(\-)?(?:(\d*)[. ])?(\d+)\:(\d+)(?:\:(\d+)\.?(\d{3})?\d*)?$/

screen shot 2016-02-02 at 10 32 36

@rvagg
Copy link
Contributor Author

rvagg commented Feb 2, 2016

smarty pants

updated with @Starefossen's regex

what's that tool @Starefossen?

@HPate-Riptide
Copy link

@rvagg Looks like Regexper

@evilpacket
Copy link

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

@mattjohnsonpint
Copy link
Contributor

Thanks!

@mattjohnsonpint
Copy link
Contributor

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.

@SomeKittens
Copy link

Since this seems to be breaking builds left and right (hurrah, popularity!) my vote is to release it ASAP as a patch version.

@mattjohnsonpint mattjohnsonpint changed the title use full-string match to speed up C# duration match use full-string match to speed up aspnet regex match Feb 3, 2016
@ichernev
Copy link
Contributor

ichernev commented Feb 3, 2016

Merged in 52a807b

@ichernev ichernev closed this Feb 3, 2016
ichernev added a commit that referenced this pull request Feb 3, 2016
use full-string match to speed up aspnet regex match
@mattjohnsonpint mattjohnsonpint modified the milestones: 2.11.2, 2.12.0 Feb 3, 2016
@mattjohnsonpint
Copy link
Contributor

This is available now in 2.11.2. Thanks @ichernev for getting this out.

@ichernev
Copy link
Contributor

ichernev commented Feb 3, 2016

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?

@joeybaker
Copy link

@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?

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

Successfully merging this pull request may close these issues.

Regular Expression Denial of Service
8 participants