A webhook endpoint can acknowledge an event and still lose its work if the process exits before a background task becomes durable. It can also process an authentic delivery twice or apply an old event after a newer state. Design authenticity, acceptance, and business processing as separate boundaries with explicit recovery states.
This guide covers incoming signed webhooks, using GitHub and Stripe documentation for provider-specific examples. The proposed inbox workflow is an application design recommendation. Signature formats, replay controls, retry schedules, and event semantics must come from the selected provider rather than a generic verifier copied between integrations.
Bound the incoming bytes before interpreting their meaning
Give the webhook route explicit body-size, read-duration, and concurrent-request limits. Capture the byte representation required by the provider's signature scheme before ordinary parsing middleware changes it. Keep that capture bounded so unauthenticated traffic cannot allocate arbitrary memory.
Stripe's webhook documentation requires the raw body for signature verification and warns that manipulation breaks the check. Parsing JSON and serializing it again can change the representation even when the resulting object appears equivalent.
After successful authentication, parse the verified payload through a schema with bounded nesting and field lengths appropriate to the application. Allow only supported event types into their corresponding processing paths. Unknown but authentic events need a deliberate ignore or quarantine policy, not an accidental parser exception.
Treat the payload as untrusted application data even after verification. Encode any text displayed in an operator interface, avoid constructing database queries from payload fragments, and do not follow embedded URLs without a separately reviewed outbound-request policy. Authenticity establishes a source relationship under a key; it does not make every supplied value safe for every use.
Verify the provider's exact protocol
Use the provider's maintained verification library where suitable, following its required body representation, algorithm, header parsing, and key configuration. Reject missing or malformed signatures before accepting business work. Public errors should identify a rejected delivery without exposing internal exceptions or verification material.
GitHub's delivery validation guide documents its HMAC-based signature and recommends comparison methods that mitigate timing attacks. That protocol is distinct from Stripe's timestamp-bearing signature scheme. Do not assume every provider signs the same fields or supplies an authenticated timestamp.
For protocols with authenticated freshness information, enforce the documented tolerance and keep the receiving clock healthy. A timestamp copied from an unsigned header cannot establish freshness by itself. Plan a bounded key-rotation window and retire old verification material according to the provider's supported process.
Verify account context after authenticity. A signed event for one connected account must not update a different tenant selected by an untrusted request parameter. Map the authenticated integration context to the application's authorized account and check that the event belongs there.
Make acknowledgement follow durable acceptance
For the proposed design, write a verified event into an inbox with a stable application identity and an initial processing state. Enforce uniqueness through the database rather than an in-memory check that two concurrent requests can both pass.
Acknowledge an accepted event only after the durable acceptance boundary succeeds. If storage fails before that point, return the provider-compatible failure response and preserve a retry opportunity. Do not start a detached task, respond successfully, and assume the task will survive process replacement.
Keep the worker's source of truth connected to the inbox. A worker can poll durable pending records, or the acceptance transaction can include a transactional outbox for subsequent queue publication. Writing an inbox row and then independently publishing a message leaves a gap if the process stops between those actions.
GitHub's webhook best practices recommend prompt responses, asynchronous processing where appropriate, and use of delivery identifiers. Meet the provider's response deadline by bounding acceptance work, rather than by acknowledging an event whose only copy is still in process memory.
Separate delivery deduplication from business correctness
Choose an inbox uniqueness key whose scope includes the provider and integration identity. Verify which identifiers are covered by authentication. A delivery header outside the signed content can be useful for correlation without being sufficient protection against an attacker replaying a valid body with altered headers.
Use an authenticated event identity or another provider-supported mechanism where available, and retain business-level idempotency even when delivery deduplication works. Multiple distinct events may describe the same business transition. A delivery key cannot decide whether sending another entitlement notification is appropriate.
Stripe documents duplicate delivery and does not guarantee event ordering. Treat event creation times as metadata rather than a complete ordering protocol. For a synthetic subscription receiver, define whether an event applies a versioned transition or triggers reconciliation against the provider's current object state.
Protect reconciliation requests with their own timeout and retry budget. If a provider read fails, keep the inbox record pending or retryable rather than pretending the event's business effect completed. The guide to idempotent operations explains how repeated execution can preserve the intended result.
Exercise the boundaries where a process can stop
Test rejection before persistence for invalid signatures, altered bodies, malformed supported events, and an account mismatch. Include a valid event from another integration. Assert that rejected deliveries produce no inbox record eligible for business processing.
Then interrupt the process before the acceptance commit, after the commit but before the response, during worker execution, and after an external effect but before its local completion record. The last case needs reconciliation or downstream idempotency; repeating an external action blindly is insufficient recovery.
Send simultaneous copies and reordered events. Verify the expected durable state, not only that the endpoint returned success. Check that failed workers release or expire ownership according to a documented claim protocol and that retry exhaustion has an owner.
Keep raw payload access restricted and retention bounded. Routine diagnostics can use event classification and sanitized state transitions. A receiver is ready when each interruption leads to a rejected, pending, completed, or explicitly unresolved operation that the application can inspect and recover.
Was this guide useful?
Your rating helps us prioritize clearer, more practical technical content.
Review diffs, run checks, and prepare the release in Arezgit.
Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.
Explore Arezgit