fix: use timing-safe HMAC comparison in Nodeless callback controller#584
Open
Anshumancanrock wants to merge 4 commits intocameri:mainfrom
Open
fix: use timing-safe HMAC comparison in Nodeless callback controller#584Anshumancanrock wants to merge 4 commits intocameri:mainfrom
Anshumancanrock wants to merge 4 commits intocameri:mainfrom
Conversation
…cation and guard against missing NODELESS_WEBHOOK_SECRET
🦋 Changeset detectedLatest commit: d4fd38d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Collaborator
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
The Nodeless callback controller was using a plain
!==string comparison to verify webhook HMAC signatures. This PR fixes it to usecrypto.timingSafeEqualwith proper Buffer comparison, matching how the OpenNode callback already handles it.Also adds a guard for when
NODELESS_WEBHOOK_SECRETis not set (previously this would throw aTypeErrorfromcreateHmac)Related Issue
Fixes #581
Motivation and Context
The OpenNode callback controller uses
timingSafeEqualfor its HMAC check, but the Nodeless controller was using!==. This is inconsistent and goes against the standard practice of using constant-time comparison for secret values.Also, if
NODELESS_WEBHOOK_SECRETwas unset (e.g. on a relay using a different payment processor), any POST to/callbacks/nodelesswould crash with aTypeErrorinstead of returning a clean error response and removes the valid HMAC value from the signature mismatch log (the old code logged{ expected, actual }, leaking the correct signature).How Has This Been Tested?
returns 403 when callback signature has wrong lengthreturns 403 when callback signature is a valid-length hex string but does not matchreturns 500 when NODELESS_WEBHOOK_SECRET is not configuredtsc --noEmit)Screenshots (if appropriate):
N/A
Types of changes
Checklist: