-
Notifications
You must be signed in to change notification settings - Fork 192
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
No RexExp parser #100
Merged
Merged
No RexExp parser #100
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Specifically to avoid any more hidden ReDoS in those regexes. Seems to run tests in 6.9s vs 7.0s so might be a bit of a speed bonus on some platforms!
Replaces a bunch of `[^\d]*$` with bounded `(?:[^\d]|$)` Double checked the RFC6265 spec: time cannot have non-digits beside the colons.
None of the regexps (at least, when they were removed) are vulnerable to ReDoS. However, took this opportunity to check that the RFC is being closer and more clearly documented where in the code. Another way to put this: "regexps are magic and hinder code analysis" Introduced some equivalence tests to ensure that certain "weird" dates are indeed parsing the same as their "canonical" RFC6265 counterpart.
Integration tested |
Looks good. Thanks for merging. |
This was referenced Mar 15, 2021
wjhsf
pushed a commit
that referenced
this pull request
Feb 8, 2024
* Winter '20 (API 47.0) prep * 0.6.0 * use node LTS in CI * Prerelease 0.6.1 (#98) * 0.6.1-alpha1 * wip: synthetic shadow dep * wip: add testEnvironment to preset * update yargs for security alert (#90) * update yargs for security alert * fix test * Bump eslint-utils from 1.3.1 to 1.4.2 (#89) Bumps [eslint-utils](https://github.com/mysticatea/eslint-utils) from 1.3.1 to 1.4.2. - [Release notes](https://github.com/mysticatea/eslint-utils/releases) - [Commits](mysticatea/eslint-utils@v1.3.1...v1.4.2) Signed-off-by: dependabot[bot] <support@github.com> * Update input stub to support "autocomplete" property (#92) * Update to include date-style and time-style attributes (#94) * 0.6.1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have nothing against RegExps in general, but for security conscious code, there's too many pitfalls.
This pull-request is about converting from using mostly RegExp to using mostly native JavaScript code. The main cookie parser and the RFC-compliant date parser are most affected.
When tough-cookie was originally written, the RegExps were used because it seemed easier to maintain. This pull request certainly increases the code complexity, but does so in the hopes that maintaining the RegExps would have been more time-consuming in the long run.
As a bonus, it seems that the pure JavaScript version is about 1 to 2% faster than the RegExp one, based on the time it takes to run the entire tough-cookie test suite (7.0s versus 6.9s now).