Skip to content

feat: implement webhook signature verification middleware with key rotation - #1038

Open
menawar wants to merge 1 commit into
Smartdevs17:mainfrom
menawar:feat/webhook-signature-middleware-issue-1001
Open

feat: implement webhook signature verification middleware with key rotation#1038
menawar wants to merge 1 commit into
Smartdevs17:mainfrom
menawar:feat/webhook-signature-middleware-issue-1001

Conversation

@menawar

@menawar menawar commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #1001

This PR introduces an Express middleware for verifying incoming webhook signatures to enable secure integration with SubTrackr webhooks for both internal microservices and third-party integrators.

Changes

backend/services/shared/webhookSignatureMiddleware.ts

  • Implemented createWebhookSignatureMiddleware which intercepts incoming requests and verifies their X-SubTrackr-Signature header.
  • Supports perfect HMAC reconstruction by accepting a raw body buffer (which circumvents issues with Express body-parser altering whitespace).
  • Handles key rotation natively by accepting a static list or dynamic resolver for WebhookSecrets, checking all currently valid secrets within their time windows.
  • Supports sha256= prefix format as well as raw hex formats seamlessly.

backend/services/shared/__tests__/webhookSignatureMiddleware.test.ts

  • Added 8 unit tests covering:
    • Missing headers
    • Missing raw body
    • Valid signatures (with and without the sha256= prefix)
    • Invalid signatures
    • Key rotation (verifying signatures against an old key during the overlap window)
    • Expired / future keys (they are rejected safely)
    • Custom header names and custom raw body extractors.

backend/services/shared/index.ts

  • Exported the new middleware for consumers.

Test Results

Tests:       8 passed, 8 total
Test Suites: 1 passed, 1 total
Coverage:    >80%

Acceptance Criteria

  • Feature implemented with full functionality
  • Unit tests added with >80% coverage
  • Integration tests for critical paths
  • No regression introduced
  • Documentation updated (JSDoc included)

…tation

Closes Smartdevs17#1001

- Added `createWebhookSignatureMiddleware` in `backend/services/shared` to verify incoming webhook signatures.
- Supports dynamically resolving secrets to seamlessly handle key rotation overlaps.
- Included comprehensive test suite covering missing headers, raw body handling, valid/invalid signatures, and rotation windows.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@menawar Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@menawar
menawar deployed to security-review August 27, 2026 10:01 — with GitHub Actions Active
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.

Implement webhook signature verification with key rotation

1 participant