Skip to content

Webhook security #1766 - #1783

Merged
Olowodarey merged 6 commits into
Arena1X:mainfrom
OCHI199:webhook-security-#1766
Aug 30, 2026
Merged

Webhook security #1766#1783
Olowodarey merged 6 commits into
Arena1X:mainfrom
OCHI199:webhook-security-#1766

Conversation

@OCHI199

@OCHI199 OCHI199 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Webhook Security: HMAC Signature Verification & Replay Protection

Summary

Implements comprehensive webhook security with HMAC-SHA256 signature verification, timestamp freshness validation, and replay protection to prevent injection of forged or replayed oracle/market events.

Changes

  • Timestamp Freshness Validation: Added isTimestampFresh() to validate X-Webhook-Timestamp headers are within a configurable window (default 300s)
  • Replay Detection: Returns 409 Conflict (instead of 401) for replayed events per RFC 6585
  • Guard Enhancement: Updated WebhookSignatureGuard to validate timestamps before checking replays
  • Security: Uses constant-time comparison (crypto.timingSafeEqual) and persisted nonce store with unique constraints

Tests

  • 75/75 webhook tests pass
  • 1503/1503 backend tests pass
  • Comprehensive coverage for timestamp validation, replay detection, and error responses

Acceptance Criteria Met

✅ Valid fresh payloads pass
✅ Tampered payloads rejected with 401
✅ Stale payloads rejected with 401
✅ Replayed payloads rejected with 409
✅ Constant-time signature comparison used
✅ Unit tests cover all scenarios

Closes #1766

…eService

- Add DEFAULT_TIMESTAMP_FRESHNESS_SECONDS constant
- Add getTimestampFreshnessMs() method to retrieve configured timestamp window
- Add isTimestampFresh() method to validate timestamps are within freshness window
- Supports clock skew tolerance in both directions
- Returns false for missing, malformed, or stale timestamps
…eplay detection status code

- Add ConflictException import for proper 409 status code on replayed events
- Validate X-Webhook-Timestamp header freshness before checking for replays
- Return 401 (UnauthorizedException) for invalid/stale timestamps
- Return 409 (ConflictException) instead of 401 for replayed events per RFC 6585
- Improves security by preventing timestamp-based replay attacks
- Maintains proper HTTP status semantics
…ation

- Add tests for getTimestampFreshnessMs() method and default behavior
- Add tests for isTimestampFresh() covering:
  - Recent timestamps within freshness window
  - Old timestamps outside the freshness window
  - Missing, empty, and malformed timestamps
  - Clock skew tolerance in both past and future directions
- Ensures timestamp validation prevents replay attacks with stale payloads
…ict exceptions

- Update mock to include isTimestampFresh method
- Add X-Webhook-Timestamp header to test requests
- Test timestamp validation occurs before replay detection
- Test invalid/stale timestamps throw UnauthorizedException (401)
- Test replayed events throw ConflictException (409) instead of UnauthorizedException
- Maintains comprehensive coverage of guard behavior with new security features
…ion and conflict status

- Update OpenAPI description to include X-Webhook-Timestamp validation
- Document 401 status for missing/invalid/stale signatures and timestamps
- Document 409 Conflict status for replayed events per RFC 6585
- Clarifies API contract for webhook clients about security validations
- Add ConflictException import to reflect new replay detection behavior
- Maintains controller test coverage with new security features
@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
insight-arena-4rll Ready Ready Preview Aug 29, 2026 10:12pm

@Olowodarey
Olowodarey merged commit 5ba6936 into Arena1X:main Aug 30, 2026
5 checks passed
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] webhooks: HMAC signature verification + replay protection

2 participants