fix: inbound webhook replay protection (#1238) - #1
Open
Dev-Odun-oss wants to merge 1 commit into
Open
Conversation
Wire HMAC-SHA256 + 5-minute timestamp window into POST /api/webhooks/actions: - verifySignature() in webhookService.js enforces TOLERANCE_MS (5 min) and timing-safe HMAC comparison; already exported but not wired to inbound route - webhooks.js /actions endpoint now rejects stale timestamps (400 Replay detected) and bad HMAC (401 Invalid signature) before processing the request - vitest.config.js: set NODE_ENV=test in env so test-environment guards in merchantRepository.js and similar modules fire correctly in all workers Tests (tests/webhookInboundVerification.test.js): - valid signature + recent timestamp accepted (crypto unit test) - expired timestamp (> 5 min) → 400 replay_detected - bad HMAC → 401 unauthorized - missing headers → 401 - valid sig but missing body fields → 400 validation_error Closes Nova-reward#1238
🦀 Cargo Dependency Vulnerability Scan
|
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
Wires timestamp tolerance + HMAC verification into the inbound webhook endpoint (
POST /api/webhooks/actions), preventing replay attacks.Changes
routes/webhooks.js—/actionsendpoint callsverifySignature()before processing. Stale timestamps (> 5 min) return400 replay_detected; bad HMAC returns401 unauthorized.tests/webhookInboundVerification.test.js— 5 tests covering all acceptance criteria paths.vitest.config.js— AddedNODE_ENV: 'test'toenvso test-environment guards activate correctly in vitest workers.Acceptance Criteria
400 Replay detected401Testing
Closes Nova-reward#1238