How do you run webhook signature verification in six steps?
Also, a receiver runs six webhook signature verification steps in a fixed order. First, it stops at the first failure and does not continue.
People new to the constant-time compare should start with the guides.
Short answers on the webhook signature verification are kept up to date. In fact, share what you learn about the constant-time compare with your whole team. Questions about the replay protection are welcome in the contact form.
Teams often ask us about the raw body in practice. Each page on the shared secret is reviewed before it is published.
- Read the raw request body as bytes before any parsing.
- Read the signature header and strip the scheme prefix, which is sha256 followed by an equals sign.
- Compute an HMAC signature digest of those exact bytes with your stored secret, written as lowercase hex.
- Compare your digest with the header value in constant time.
- Reject the request with a 4xx status when the values differ.
- Parse the JSON, read the event id and check it against the ids you have seen.
In addition, each step of this webhook signature verification flow has a clear reason. Raw bytes matter because a re-serialized body can differ from the original. In addition, the prefix must be removed, or every compare fails.
Parsing comes last because a parser is attack surface. Therefore, run it only on trusted input.
Moreover, keep the secret out of source code and logs. Indeed, the webhook signature verification secret is only as strong as the place where it is stored. Indeed, every webhook signature verification check depends on that secret. If it leaks, rotate it at once.
How does one worked example of the check look in code?
Notably, suppose the sender posts a JSON envelope for the event record.synced. The envelope holds an event id, a tenant id, a timestamp and a data block. In fact, it also sends X-Dalet-Signature with the value sha256 followed by a 64-character hex string.
Each count is checked against the source.
Teams often ask us about the webhook signature verification in practice. Also, teams often ask us about the replay protection in practice.
Our team writes about the webhook signature verification in plain words. Each page on the constant-time compare is reviewed before it is published. Each page on the raw body is reviewed before it is published.
Teams often ask us about the shared secret in practice.
How is the signature header laid out on the wire?
The header holds the word sha256, an equals sign and the hex digest.
Each step is recorded with its date.
Readers often return to the webhook signature verification when plans change.
Short answers on the webhook signature verification are kept up to date. Thus, a short checklist keeps the shared secret under control.
Teams often ask us about the constant-time compare in practice. A second look at the constant-time compare pays off. Every claim about the raw body is checked against the code.
Short answers on the shared secret are kept up to date.
Indeed, in this webhook signature verification test, your receiver reads the body bytes and keeps them untouched. Next, it computes the HMAC signature digest of those bytes with the shared secret. The result is 32 bytes, written as 64 hex characters.
Besides, it builds the string sha256 plus that hex and compares it with the header. This webhook signature verification header match is the whole check.
Specifically, if one character of the body differs, the two strings differ completely. For example, add a space, change the key order or round a number, and the check fails. Notably, that is the point of the design.
Furthermore, a match means the receiver holds exactly the bytes the sender signed. The webhook signature verification code is short for that reason.
Now the receiver reads the event id from the envelope and looks it up in a store of processed ids. Additionally, when the id is new, the receiver records it and handles the event. When the id was seen before, the receiver returns 200 and does nothing else. Also, returning success on a repeat stops the sender from retrying.
Why should a compare of two hashes take constant time?
In addition, a normal string compare is a trap in any webhook signature verification code. Indeed, it stops at the first different character. Therefore, the time it takes leaks how many leading characters matched.
An attacker who can measure that time may guess a valid HMAC signature one character at a time. Moreover, over a network the signal is faint, but the fix costs nothing.
Notes on the constant-time compare are dated and reviewed by a second person.
Our team writes about the webhook signature verification in plain words. Readers often return to the constant-time compare when plans change. Each page on the raw body is reviewed before it is published.
Short answers on the raw body are kept up to date.
Notably, use the compare function your language provides for secrets. Python offers hmac.compare_digest, and most languages have an equivalent. Also compare values of equal length and format.
Do not lowercase or trim inside a hand-written loop. The reason is that that weakens the HMAC signature check.
In fact, treat the secret as a credential. Give each subscription its own secret, so one leak reaches one endpoint only. Schedule rotation as well: accept two secrets for a short window, switch the sender, then drop the old one.
Indeed, DaletPipe accepts a secret of up to 512 characters per subscription. Therefore, limit who can read the store that holds it, and rotate on any doubt. Besides, the credential custody article shows how CRM tokens differ from webhook secrets.
How does replay protection use an event id and a clock?
Besides, webhook signature verification alone does not make a message fresh. The reason is that a valid HMAC signature can be sent twice. An attacker who captures one request can send it again, and the signature stays valid.
The result is stored with the run.
Specifically, two layers of replay protection stop that: an event id and a time check. The replay protection step costs one lookup per message.
Each page on the webhook signature verification is reviewed before it is published. Every claim about the raw body is checked against the code.
Questions about the webhook signature verification are welcome in the contact form. Teams often ask us about the constant-time compare in practice. Also, teams often ask us about the raw body in practice.
Each page on the shared secret is reviewed before it is published.
Furthermore, the event id is a unique value in the envelope and in a header. Store each id you process, and keep it longer than the sender's retry window. Then drop every repeat today.
Additionally, this event id store absorbs honest duplicates that retries cause. A replay protection store can stay small, since ids expire after the retry window.
Also, a timestamp adds a second replay protection guard. Reject messages whose timestamp sits far from your clock, with a tolerance that covers clock skew and retries. In addition, DaletPipe's envelope carries a timestamp.
Also, the event id in the body matches the X-Dalet-Event-ID header. Likewise, the webhook-timestamp header also gives the time of each attempt. That event id match lets a receiver run replay protection on either value.
Moreover, treat the payload as a hint rather than a copy of the record. The event record.synced carries a connection id, an entity and a count of records processed. In addition, it is a notice that a pull finished.
Therefore, fetch the records through the API when you need them. Notably, the signed webhooks page describes the full event.
How does DaletPipe send events and retry the failed ones?
In fact, the sender's retry rules decide how your receiver should answer after the webhook signature verification result is known. A webhook signature verification failure should end with a clear 4xx answer. DaletPipe posts a JSON body with a timeout of 10 s.
Indeed, it sends three headers: X-Dalet-Signature, X-Dalet-Event-Type and X-Dalet-Event-ID. The signature header carries the HMAC signature.
Our team writes about the event ID in plain words. Questions about the shared secret are welcome in the contact form.
A second look at the constant-time compare pays off. Our team writes about the replay protection in plain words. Overall, each page on the raw body is reviewed before it is published.
Notes on the shared secret are dated and reviewed by a second person.
Besides, your response status steers what happens next. A 2xx status counts as delivered. Specifically, a 4xx status marks the delivery failed at once, with no retry. A 5xx status, a timeout or a connection error counts as retryable.
Each delivery gets three attempts. After the first failure the next try comes after 5 s, and after the second it comes after 30 s. Moreover, after the third failure the delivery gets the status dead letter. Each delivery row keeps the attempt count, the last HTTP status, the last error and the next attempt time.
So choose status codes with care. Return 401 or 400 for a bad signature, because a retry cannot fix it. Return 500 only for a fault on your side that may clear. Answer quickly and do slow work after you reply, since a 10 s timeout counts as a failure.
How does DaletPipe verify each of the inbound CRM webhooks?
Everything above covers events that DaletPipe sends. Events that CRMs send to DaletPipe are a different matter. Each CRM signs differently, or not at all. Some send a header token, some sign a URL plus the body, and some send partial data.
Every figure is taken from the code.
A second look at the replay protection pays off.
Short answers on the webhook signature verification are kept up to date. In fact, share what you learn about the constant-time compare with your whole team. Share what you learn about the raw body with your whole team.
A second look at the shared secret pays off.
The generic inbound route accepts only verified events. Each connector's verified webhook operation checks that provider's own scheme. A signature header alone is not authentication, so the route fails closed.
Inbound notifications arrive on connection-bound routes, and Pipedrive v2 person notifications are one example. Indeed, each tenant connects its route with its own secret, a public HTTPS base URL and a worker database role. A valid create or change event makes a worker fetch the current record.
The callback data itself is never used as the record. Delete and merge notices keep evidence and never delete local records.
If you also run a receiver of your own for a CRM, verify with that CRM's documented scheme. The incremental sync article describes the polling safety net. Meanwhile, the warehouse feed page shows a downstream use of signed events. Also, for background, read RFC 2104 (opens in new tab) and the Python hmac notes (opens in new tab).