Repository navigation
feat(webhooks): signed delivery with retries and dead-letter queue - #569
Closed
Simultech369 wants to merge 1 commit into
Closed
Simultech369 wants to merge 1 commit into
Simultech369 wants to merge 1 commit into
Conversation
Contributor
|
Closing as part of a repository reset; new issues will be opened shortly. Thanks for contributing! |
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
Closes #552
This PR implements an end-to-end webhook delivery pipeline featuring cryptographic HMAC-SHA256 signing, timestamp replay attack defense, bounded retries with exponential backoff on transient errors (
5xxand network timeouts), and an in-memory bounded Dead-Letter Queue (DLQ) with inspection and replay endpoints.Architecture & Implementation
1. Cryptographic HMAC Signing (
src/webhooks/signer.ts)X-Signature: t=<timestamp_ms>,v1=<hmac_sha256_hex>.${timestamp}.${rawPayload}, binding the timestamp cryptographically to the exact body bytes.verifyWebhookSignature()uses constant-timetimingSafeEqualto defeat timing attacks and enforces a configurable clock drift tolerance window (default 300s).2. Delivery Pipeline with Exponential Backoff (
src/webhooks/delivery.ts)2xx Success: Delivery acknowledged immediately.4xx Client Error: Non-retryable error (e.g. 400 Bad Request, 401 Unauthorized, 404 Not Found); stops retries immediately and dead-letters.5xx Server Error/ Network Timeout: Transient error; retries up tomaxRetries(default 3) using exponential backoff:delayMs = initialBackoffMs * Math.pow(backoffFactor, attempt - 1).maxPayloadBytes(default 64 KB) are rejected and dead-lettered prior to network transmission.fetchFnfor fast, hermetic testing without network sockets.3. Dead-Letter Queue (DLQ) Engine (
src/webhooks/deadLetterQueue.ts)4. REST API & Lifecycle Integration (
src/index.ts&src/stores.ts)POST /api/v1/webhooks: Accepts optional callersecret(8–256 chars) or generates a securewhsec_<hex>secret. Secret is returned in the201 Createdresponse.GET /api/v1/webhooks,GET /api/v1/webhooks/:id,PATCH /api/v1/webhooks/:id: Secrets are strictly stripped and never leaked in list or read responses.GET /api/v1/webhooks/dead-letter: Paginated list of dead-letter records with total count and optionalwebhookIdfilter.GET /api/v1/webhooks/dead-letter/:id: Read a specific dead-letter record.POST /api/v1/webhooks/dead-letter/:id/replay: Replays an event from the DLQ.DELETE /api/v1/webhooks/dead-letter/:id: Purges a record from the DLQ.docs/webhook-delivery.mdwith complete architecture specifications, header tables, and verification examples.Edge Case Coverage
Every edge case specified in Issue #552 is implemented and tested:
X-SignatureandX-Signature-Timestampheaders generated and verified by subscriber.lastErrorandlastStatusCode.Verification & Test Results
src/__tests__/webhookSignerAndDlq.unit.test.ts: 13/13 tests passsrc/__tests__/webhookDelivery.test.ts: 23/23 tests passsrc/__tests__/webhooks.test.ts: 31/31 tests passsrc/__tests__/openapi.test.ts: 3/3 tests pass (zero route drift)npm test: 37/37 test suites passed, 1021/1021 tests passednpm run lint: 0 errorsnpm run build:tsccompiles clean with 0 errors