Repository navigation
perf(signer): early exit on missing delimiter in unsign to avoid redundant HMAC calculations - #379
Open
TalhaHunter101 wants to merge 1 commit into
Open
TalhaHunter101 wants to merge 1 commit into
TalhaHunter101 wants to merge 1 commit into
Conversation
…HMAC computations Signed-off-by: Talha Shafeeq <talha.shafeeq.ts@gmail.com>
gurgunday
reviewed
Oct 21, 2026
This branch has not been deployed
This file contains hidden or 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
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.
Description
When un-signing a cookie via
signer.unsign(signedValue), signed cookies are expected in the format<value>.<signature>.If an incoming cookie is unsigned or malformed (i.e. contains no dot delimiter or ends with a trailing dot):
signedValue.lastIndexOf('.')returns-1.signedValue.slice(0, -1)slices off the last character instead of failing.signedValue.slice(0)treats the entire string as the signature buffer.secretsarray and computes an expensivecrypto.createHmac(...)digest for every key before finally failing on signature length comparison.Changes
dotIndexbefore allocating buffers or executing crypto operations. IfdotIndex === -1 || dotIndex === signedValue.length - 1, early-exits with{ valid: false, renew: false, value: null }.test/signer.test.jscovering unsigned strings and strings ending with a dot.Benchmark
Benchmark on unsigned cookie inputs (
50,000iterations with 3 rotating secrets):Checklist
npm test)c8 --100)tstyche)npm run lint)