fix(integration): correct ingress HMAC substitution and constant-time challenge compare#592
Merged
Merged
Conversation
… challenge compare - Build the HMAC signed content with a single-pass function replacer instead of chained String.replace. The old code only replaced the first token and interpreted $&, $`, $', $$, $n in the replacement (the attacker-controlled raw body), so a legitimately-signed delivery whose body contained a $-sequence diverged from the provider's signed bytes and was silently rejected (inbound message loss). - Compare the GET-challenge verify token with the existing constant-time safeEqualStr (now exported) instead of plain ===, matching the signature path and removing a timing oracle.
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.
Summary
Two correctness/hardening fixes on the inbound-webhook (ingress) verification path.
Changes
template.replace('{rawBody}', rawBody).replace('{timestamp}', ts).String.prototype.replacewith a string pattern only replaces the first occurrence and interprets$&,$\``,$',$in the replacement — which here is the attacker-controlled raw body. A provider that legitimately signed a body containing a$-sequence would have its signature rejected (silent inbound message loss). Replaced with a single-pass function replacer over/{rawBody}|{timestamp}/gthat inserts each value literally; because the body is substituted (not re-scanned), a{timestamp}` embedded in the body is never re-interpreted.===; switched to the existing constant-timesafeEqualStr(now exported), matching the signature path and removing a timing oracle. Thetoken && verifyToken &&guards are preserved so a null token never matches.Verification
npm run build✓ ·npm test✓ (1852/1852, +3) · lint ✓. New tests: a body with$&/$'/$/$$/$1and a literal{timestamp}` verifies correctly (both single- and multi-token templates); a challenge with an empty/absent verify token is rejected.