Skip to content

fix: inbound webhook replay protection (#1238) - #1

Open
Dev-Odun-oss wants to merge 1 commit into
mainfrom
fix/webhook-replay-protection-1238
Open

fix: inbound webhook replay protection (#1238)#1
Dev-Odun-oss wants to merge 1 commit into
mainfrom
fix/webhook-replay-protection-1238

Conversation

@Dev-Odun-oss

Copy link
Copy Markdown
Owner

Summary

Wires timestamp tolerance + HMAC verification into the inbound webhook endpoint (POST /api/webhooks/actions), preventing replay attacks.

Changes

  • routes/webhooks.js/actions endpoint calls verifySignature() before processing. Stale timestamps (> 5 min) return 400 replay_detected; bad HMAC returns 401 unauthorized.
  • tests/webhookInboundVerification.test.js — 5 tests covering all acceptance criteria paths.
  • vitest.config.js — Added NODE_ENV: 'test' to env so test-environment guards activate correctly in vitest workers.

Acceptance Criteria

  • Inbound webhook with timestamp > 5 minutes old returns 400 Replay detected
  • Inbound webhook with a valid signature and recent timestamp is accepted
  • Inbound webhook with an invalid HMAC signature is rejected with 401
  • Unit tests cover all three paths (5 tests, all passing)

Testing

npx vitest run tests/webhookInboundVerification.test.js
Tests: 5 passed (5)

Closes Nova-reward#1238

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
@github-actions

Copy link
Copy Markdown

🦀 Cargo Dependency Vulnerability Scan

✅ No vulnerabilities found in Rust dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Enforce Webhook Inbound Replay Protection Using Timestamp Tolerance

1 participant