Skip to main content

Webhook Security: HMAC Signature Validation Guide

Verify Didit webhooks with HMAC-SHA256: check X-Signature-V2 against the canonical JSON, reject X-Timestamp values more than 300 seconds away from your clock, and compare in constant time.

Webhook Security: HMAC Signature Validation Guide

Contents

In this guide

Jump to the part you need.

This guide is for teams that already receive Didit webhooks for identity, business or transaction events and want to reject forged calls. We sign every delivery to a documented destination with HMAC-SHA256, and the recommended header is X-Signature-V2. Sandbox sessions are free. Our public price feed gives no separate webhook delivery price. The caveat: capture the request body before middleware can change it. For V2, use the JSON to compute the signature and verify it before acting on any event fields.

Last updated: November 26, 2026. Prices checked against the live Didit price feed on November 26, 2026.

Didit webhook signing surface at a glance
ItemValue
Recommended headerX-Signature-V2, HMAC-SHA256 over the sorted, Unicode-preserved canonical JSON
Raw-bytes headerX-Signature, HMAC-SHA256 over the exact raw request bytes
Envelope-only headerX-Signature-Simple, deprecated last resort, authenticates the envelope and not the decision body
Dispatch timeX-Timestamp, Unix epoch seconds when Didit dispatched the webhook
Freshness ruleReject when the absolute difference between now and X-Timestamp is more than 300 seconds
Rotation headersX-Signature-V2-Previous, X-Signature-Previous, X-Signature-Simple-Previous, sent for 24 hours after a destination's signing secret is rotated
ComparisonConstant-time comparison, accept a match on the current header or its -Previous header
Published webhook priceSandbox sessions are free. Our public price feed gives no separate webhook delivery price. Signature verification runs in your handler. We document the List Webhook Destinations API as pay-per-call without publishing a rate in that reference.

Start free in the sandbox at business.didit.me, no sales call. Developers who want an assistant to read the webhook documentation and draft the receiver can connect Didit through MCP, and the current per-check prices sit on Didit pricing.

What HMAC signature validation proves, and what it does not

HMAC combines a hash function with a shared secret. We compute HMAC-SHA256 over the delivery and put the result in a request header. Your endpoint recomputes the same value with the destination signing secret. If the two match, the request came from someone holding that secret and the signed content did not change in transit.

Two things it does not prove. A valid signature says nothing about whether a decision is correct, only that the delivery is genuine. And a valid signature does not stop replay, because an old signed body is still correctly signed. For session events verified with X-Signature-V2 or X-Signature, use the verified event_id to prevent duplicate state changes. For V2, the HMAC covers the canonical JSON body. Evaluate the verified decision under your own policy.

The three signature headers, and the secret behind each

We ship three signature headers. Verify the strongest one your stack can support.

Didit signature headers and what each one signs
HeaderWhat is signedWhen to use it
X-Signature-V2Sorted, Unicode-preserved canonical JSONRecommended default. The signed data has to survive parsing intact.
X-SignatureThe exact raw request bytesUse when your stack hands you the untouched body bytes.
X-Signature-SimpleThe string {timestamp}:{session_id}:{status}:{webhook_type}Deprecated fallback. It authenticates the envelope only, not the decision body, so re-fetch the decision from GET /v3/session/{session_id}/decision/ instead of trusting the payload.

Rotation adds a second header for each scheme. The current header is always checked with the current secret, and its -Previous counterpart with the secret it replaced.

Which secret belongs to which rotation header
HeaderSecret to verify it with
X-Signature-V2The current destination secret
X-Signature-V2-PreviousThe replaced secret
X-SignatureThe current destination secret
X-Signature-PreviousThe replaced secret
X-Signature-SimpleThe current destination secret
X-Signature-Simple-PreviousThe replaced secret
A session overview with its warnings in the Didit Business Console
The decision object inside a status.updated webhook mirrors this session view in the console. The warning fields it carries are defined in the Didit data models.

Prerequisites

  • Create a webhook destination in the Business Console. If you already have a destination, use the list API to check its URL and subscriptions.
  • The destination signing secret. The list call returns only secret_last4, so read the full value from GET /v3/webhook/destinations/{destination_uuid}/ or from the console when you create the destination.
  • An endpoint that can read the raw request body before any global JSON middleware touches it, and that can build the canonical JSON for V2.
  • A synchronized clock. The freshness window is 300 seconds in either direction, so drifting servers reject good deliveries.
  • An API key with access to the application if you want to audit destinations and failure alerts from code.

Step by step: validate a Didit webhook signature

  1. Create the destination and subscribe explicitly. Pick every event family you want, because there is no wildcard. If you need status.updated and transaction.created, subscribe to both. Multiple destinations can fan out to different URLs.
  2. Store the secret outside the code. Put the destination signing secret in an environment variable or a secret manager. Never commit it, and re-read it from the API rather than copying values between environments.
  3. Capture the raw POST body first. Register the webhook route ahead of body-parsing middleware, or keep a copy of the bytes. Preserve the original request bytes: X-Signature covers those exact bytes, and X-Signature-V2 covers sorted, Unicode-preserved canonical JSON, so the signed data has to survive parsing intact.
  4. Reject stale deliveries. Compare X-Timestamp with your own clock and reject when the absolute difference is more than 300 seconds. A delivery can arrive late or with a clock that runs ahead, so apply the check in both directions.
  5. Recompute the documented HMAC and compare in constant time. Use X-Signature-V2 against the canonical JSON, or X-Signature against the raw bytes. Check the current header with the current secret and its -Previous header with the replaced secret, so a rotation does not drop events.
  6. Use the verified event once. For session events verified with X-Signature-V2 or X-Signature, use event_id to apply each event once. If you verify with X-Signature-Simple, fetch the decision with GET /v3/session/{session_id}/decision/ and use the fetched decision for state changes. Dispatch by webhook_type, and match status strings exactly, including Kyc Expired with a single capital K.
  7. Answer fast. Return 2xx promptly once the event is recorded or recognized as already processed.

The part people get wrong: V2 canonicalization

V2 canonicalization needs to read the JSON to sort its keys, so the handler parses the body in order to compute the digest. Parsing is not the problem. Acting on the fields before verification is. Keep the parsed object aside until the comparison passes, and only then read status, decision or anything else from it. V2 canonicalization sorts the keys, so changing their input order alone does not change the digest. Changing a value or its type can change the digest.

Expected output

The destinations call returns a JSON array, not paginated, ordered by created_at. Each item carries url, label, enabled, webhook_version, subscribed_events, secret_last4, health_status, failing_streak, failing_since and 30-day delivery metrics. The list never includes the signing secret itself.

This abbreviated V3 session-event payload shows a status.updated event and omits the decision object.

{
  "event_id": "uuid",
  "session_id": "uuid",
  "status": "Approved",
  "webhook_type": "status.updated",
  "created_at": 1627680000,
  "timestamp": 1627680000,
  "application_id": "uuid",
  "environment": "live",
  "sandbox_scenario": null,
  "workflow_id": "uuid",
  "workflow_version": 1,
  "vendor_data": "your-internal-user-id",
  "metadata": {"user_type": "premium"}
}

A real Approved session payload includes the full decision object with all feature results, as the verification-status documentation requires.

For session events verified with X-Signature-V2 or X-Signature, use event_id to apply each event once. In the deprecated X-Signature-Simple path, fetch the decision with GET /v3/session/{session_id}/decision/ and use the fetched decision for state changes. Dispatch by webhook_type, and return 2xx promptly once the event is recorded or recognized as already processed. Reject invalid signatures and stale timestamps without changing application state. Status strings are exact and case-sensitive, so compare with strict equality rather than a fuzzy match.

Inputs and outputs

What goes into the check and what comes out of it
InputWhere it comes fromWhat you do with it
Raw request bodyThe POST itselfPreserve the original request bytes. X-Signature covers those exact bytes. X-Signature-V2 covers sorted, Unicode-preserved canonical JSON and requires the signed data to survive parsing intact.
X-Signature-V2Request headerCompare in constant time with the current secret, and accept X-Signature-V2-Previous with the replaced secret during the overlap
X-TimestampRequest headerReject when the absolute difference from your clock is more than 300 seconds
Destination signing secretBusiness Console or GET /v3/webhook/destinations/{destination_uuid}/HMAC key, held in a secret manager
Accept or rejectYour handlerReturn 2xx promptly for accepted or already processed events. Reject invalid signatures and stale timestamps without changing application state.
event_idParsed bodyOutput two: for session events verified with X-Signature-V2 or X-Signature, the idempotency key, so a retry does not double-apply state
webhook_type and statusParsed bodyOutput three: the branch and the state transition you record
AML screening result for a session in the Didit Business Console
AML results reach you through the same signed delivery, inside the aml_screenings[] array of the decision object. See AML screening.

Failure cases and recovery

Symptoms, causes and fixes for a failing signature check
SymptomLikely causeFix
Rejected before any digest comparisonX-Timestamp missing, or your clock drifted past 300 secondsSync with NTP and treat freshness as its own failure, which happens before signature comparison
Signature mismatch after request parsingMiddleware re-encoded the body before you hashed itPreserve the original bytes for X-Signature, or verify X-Signature-V2 against canonical JSON and confirm the signed values survive parsing
Works in one language, fails in anotherDifferent digest encoding, or a scheme prefix on one sideRecord the failure category and header name, then compare digest encodings against a local test fixture
Started failing after a secret rotationOnly the new secret is configuredCheck the current header with the current secret and the -Previous header with the replaced secret for the 24-hour overlap
Fails for one destination onlyWrong secret for that destinationCheck secret_last4 in the destinations list, then re-read the full secret
Same event applied twiceNo idempotencyFor session events verified with X-Signature-V2 or X-Signature, deduplicate on event_id
No decision object in the payloadThe session status does not carry a decisionCheck whether the session status includes a decision before you look for decision fields
Decision body unauthenticatedVerified with X-Signature-SimpleRetrieve the decision with GET /v3/session/{session_id}/decision/

Delivery health is separate from your handler logic. health_status summarizes how a destination has been answering: failing when 3 or more consecutive events failed their first delivery attempt since the destination last answered successfully, degraded when the destination is below the failing threshold, an attempt failed in the last 24 hours, and no later attempt delivered that event, and healthy otherwise. Retries do not add to failing_streak, and any success, including a retry or a resend, ends the streak. A failed attempt is one your endpoint answered with HTTP 400 or above, or did not answer at all.

Inspect webhook destinations

The documented command lists each destination's configuration, subscriptions and delivery health.

curl -X GET "https://verification.didit.me/v3/webhook/destinations/" \
  -H "x-api-key: YOUR_API_KEY"

Recorded failure alerts come from the destination activity endpoint, newest first, each entry with occurred_at and failure_count, paginated with limit and offset. Those alerts are not individual attempts. Use the deliveries endpoint for per-attempt detail, and the activity endpoint to see when a destination started failing. Record the failure category and header name, and keep live signatures, secrets and payloads out of logs.

Didit Business Console: transaction monitoring alert detail
Transaction events such as transaction.created and transaction.status.updated arrive under the same signature headers. See transaction monitoring.

Sandbox verification checklist

Every sandbox application is free, so run these checks against your receiver before you point a production destination at it. Use specimen documents and fictional data.

Expected result for each sandbox check
CheckExpected result
A real sandbox session delivery verified with X-Signature-V2 or X-SignatureSignature and timestamp pass, the event is applied once under its event_id, and your handler answers 2xx.
A local fixture with a broken signatureRejected with no state change. Logging is a separate assertion, and the exact log fields depend on the receiver.
A local fixture with X-Timestamp 400 seconds in the pastRejected as stale before any digest comparison.
A local fixture with X-Timestamp 400 seconds in the futureRejected the same way, because the rule uses the absolute difference.
The same event delivered twiceThe second delivery is recognized as already processed, no second state change, and the answer is still 2xx.
A delivery during a rotation overlapThe current header passes with the current secret and the -Previous header passes with the replaced secret.

Sandbox sessions carry "environment": "sandbox" in the payload, so you can keep their events out of production state. The example records that ship with a sandbox application are never billed and never send a webhook, so create your own session to trigger a delivery.

Rotating the signing secret

Rotate the signing secret for a webhook destination in the Business Console. For 24 hours after that, Didit sends X-Signature-V2-Previous, X-Signature-Previous or X-Signature-Simple-Previous next to the current header, each produced with the replaced secret. Check the current header with the current secret and its -Previous counterpart with the replaced secret, and accept a match on either. The legacy application webhook_url never receives previous headers, so move that endpoint to a webhook destination before you rotate. Retire the replaced secret when the 24-hour overlap ends. Keep support for the previous headers so you can use it on the next rotation.

A checklist for any webhook signing scheme

If you also receive webhooks from other systems, ask the same four questions of each one.

  • Which header carries the signature?
  • Which hash algorithm and key derivation does it use?
  • Which encoding does the digest use, hex or base64, and does it carry a scheme prefix?
  • Exactly which bytes or fields are signed, and in what order?

Answers differ between providers, and reusing one scheme on another is a common source of failures. Write the answers down next to each endpoint so the next person on call does not have to guess.

Sandbox sessions are free. We publish unit prices for completed checks, including $0.33 for a full ID check and $0.20 for AML screening. Our public price feed does not list a separate webhook delivery price. Signature verification runs in your handler. We document the List Webhook Destinations API as pay-per-call without publishing a rate in that reference. Other published prices are ID document only $0.15, wallet screening $0.15, business verification from $2.00 per company, and transaction monitoring $0.001 per transaction beyond the plan allowance.

  • A passing signature is not a passing decision. It confirms origin and integrity. Whether the person or business should be approved comes from the decision object and your policy.
  • In Review needs a person. An In Review event calls for manual review. Wait for an approval decision before treating the session as approved.

Worked cost example

A team completes 12,000 full ID checks and 3,000 AML screenings in a month and asks whether the plan discount matters next to the integration work. This compares undiscounted list usage with monthly Growth spend. All amounts are USD.

At list price: 12,000 x $0.33 = $3,960.00, plus 3,000 x $0.20 = $600.00, for $4,560.00.

On Growth: 12,000 x $0.3168 = $3,801.60, plus 3,000 x $0.192 = $576.00, for $4,377.60 of usage. The plan adds $99.00 a month and grants $115.00 of monthly credit, so $4,377.60 minus $115.00 plus $99.00 = $4,361.60. That is $198.40 less than list price for the month.

Both totals cover only the listed KYC and AML usage and the stated Growth plan terms. The example excludes webhook delivery and List Webhook Destinations API calls. Our public price feed lists no separate delivery rate, and the API reference describes the list call as pay-per-call without publishing a rate. See Didit pricing for the current plan terms and the full price list.

Sources

Run a documented sandbox scenario with specimen data, confirm the legitimate delivery passes your check, then replay a local fixture with a broken signature and confirm your handler rejects it. When both behave, point the destination at production. The whole test starts with a free application at business.didit.me, and no sales call is involved.

Try it

Try this in the sandbox

Run the check this guide describes, free.

ID Verification

The product this post is about, taken from its topic. Run it free in the sandbox.

$0.15 per checkStart free

Author

Alejandro Rosas

Co-founder and CTO

Alejandro Rosas

Alejandro Rosas

Co-founder and CTO

About Didit

Questions

Frequently asked questions

Which Didit webhook signature header should I verify?

Verify X-Signature-V2 first. It is HMAC-SHA256 over the sorted, Unicode-preserved canonical JSON, so it keeps working when a framework re-serializes the body, provided the signed data survives parsing intact. Keep X-Signature, which covers the exact raw request bytes, as the fallback for stacks that pass bytes through untouched.

What is the difference between X-Signature, X-Signature-V2 and X-Signature-Simple?

X-Signature-V2 signs the sorted, Unicode-preserved canonical JSON and is the recommended header. X-Signature signs the exact raw request bytes. X-Signature-Simple signs only the string {timestamp}:{session_id}:{status}:{webhook_type}, so it authenticates the envelope and not the decision body, and it is documented as a deprecated last resort.

Why does my computed HMAC differ from the received one?

The usual causes are a body that was parsed and re-encoded before hashing, a digest compared in hex on one side and base64 on the other, or a wrong destination secret. Record the failure category and header name, then compare digest encodings against a local test fixture, and keep live signatures, secrets and payloads out of logs. An out-of-window timestamp is a separate failure that your handler should raise before it compares digests at all.

How do I stop someone replaying an old valid webhook?

Check X-Timestamp against your clock and reject a difference greater than 300 seconds in either direction. The documented inputs for X-Signature-V2 and X-Signature cover the body, and the docs do not state that either covers the separate timestamp header. For session events verified with either signature, apply each verified event_id only once, even when a duplicate arrives within the freshness window.

Why use a constant-time comparison instead of equal?

A normal string comparison can return early on the first mismatched byte, and the timing difference leaks information about the expected value. Use a constant-time comparison between the received signature and the HMAC you recompute for the selected header. Digest encoding and prefixes are general integration checks, and you should confirm them against the provider's documentation.

How do I rotate a Didit signing secret without losing events?

Rotate in the Business Console, then check the current header with the current secret and its -Previous counterpart with the replaced secret. Didit sends the previous headers for 24 hours after a webhook destination's secret is rotated, and the legacy application webhook_url never receives them. Retire the replaced secret once that 24-hour overlap ends.

What should my endpoint return, and what counts as a delivery failure?

Return 2xx promptly once the event is recorded or recognized as already processed, because Didit retries within bounds. A failed attempt is one your endpoint answered with HTTP 400 or above, or did not answer at all. Three or more consecutive first-attempt failures set health_status to failing.

Does Didit charge for webhooks or for signature validation?

Sandbox sessions are free. We publish unit prices for completed checks, including $0.33 for a full ID check and $0.20 for AML screening. Our public price feed does not list a separate webhook delivery price, and signature verification runs in your handler. We document the List Webhook Destinations API as pay-per-call without publishing a rate in that reference.

Do transaction, user, business and investigator events use the same signature?

The Didit webhooks guide documents this signing scheme for the listed destination events, including session, user, business, transaction, Travel Rule and Investigator events. Subscribe to each event you need using its exact name. For authentication and bank events, consult their respective webhook documentation.

How do I keep audit evidence that webhook signatures were validated?

For session events verified with X-Signature-V2 or X-Signature, record event_id, X-Timestamp, whether the current or -Previous header matched, the result, and the status you acted on, wherever your logs live. Keep the live signature values, the secret and the payload out of those logs. The destination activity endpoint adds recorded failure alerts with occurred_at and failure_count.

Do the example records in my sandbox application send webhooks?

No. The example data that ships with a sandbox application is returned by the API, is never billed and sends no webhook. Create your own sandbox session to trigger a delivery, and expect "environment": "sandbox" in the payload so those events stay out of production state.

Compliance built in

Audited, certified and attested.

We hold the certifications and build each country's rules into your flows, so you can launch anywhere without worrying. Security and Compliance center

  • Regulation encoded into your flows

    Tell us what you do and where. Didit lists the rules that apply to you, with sources, and builds the checks each country needs into one workflow.

  • Ready for AMLR

    Every requirement of the new EU anti-money laundering rules, from checking customers to human review, is already covered by a Didit check.

  • Tested in Spain's Treasury sandbox

    Spain's Treasury published its supervised sandbox report on Didit's NFC plus active liveness onboarding; SEPBLAC took part and valued the added measures positively.

  • Audited, not self-declared

    iBeta Level 1 and Level 2. Liveness tested under ISO/IEC 30107-3.

Compliance assistant

Your obligations · 3 regions

EU · AMLRCustomer due diligence, human reviewCovered
Illinois, Texas, ColoradoExplicit biometric consentCovered
Germany · Youth protectionVerified adults only (JMStV)Covered
Workflow checked. Every obligation is met
  • SOC 2 Type 2
  • ISO 27001
  • iBeta Level 1 and Level 2
  • EU regulator attestation
  • FSM youth protection
  • GDPR
  • EBA remote onboarding
  • MiCA compatible
  • FIDO Alliance member
  • AMLREU AML Regulation ready

Integration · Didit MCP

Run Didit from your own AI agent

Connect Didit to Claude, Cursor, VS Code or ChatGPT and just ask in plain words. Your agent can do anything you can do in the console, with the same permissions you have.

Add to ClaudeChatGPT
Didit Academy · Lesson 04 · Use Didit with MCP
  • Build workflowsDescribe the checks you need. The agent creates and publishes the flow.
  • Run investigationsAsk why a session was declined, review cases, search people and companies.
  • Change rulesCreate payment rules, test them on past data and switch them on.
  • Pull reportsAsk for numbers, exports or the audit log.

Verify your first user today.

Start free

Free sandbox. Credit applies to work-email sign-ups.