-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
improve performance, improve typings #38
Merged
Merged
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
mcollina
approved these changes
Jul 10, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
mcollina
approved these changes
Jul 10, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
@kibertoad |
kibertoad
approved these changes
Jul 10, 2022
@mcollina for some reason I can't merge, this repo not on fastify team? |
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.
This PR improves the overall performance of the csrf-package.
This is done by various strategies:
By using the base64url encoding instead of base64 encoding, it drops alot of unnecessary .replace-calls to achiev exactly that. base64url is supported since node 14.18.0, so for older versions, it fallbacks to base64 with string replacement.
to improve the verify()-method, I removed the double hmac equal time solution from the tsscmp-pakage with crypto.timingsafeequal call. Before crypto.timingssafeequal in node 6.6.0 existed the double hmac solution was proposed as a workaround. There were also attempts to implement crypto timingsafeequal with the double hmac solution approach. But that was denied by the node community and CRYPTO_memcmp of OpenSSL is since used for crypto.timingsafeequal implementation.
The only critical point is when we compare the generated actual value with the expected value. timingsafeequal expect that both buffers have the same length. To avoid even exposing the information that actual and expected have different lengths, we do the timingsafeequal and at the end check that the lengths are equal. Thus making it truely timing safe.
to improve the performance of the create()-method, the salt generation is done by creating a salt generator function just in time and calling it, thus reducing some overhead.
etc.
before:
after: