Skip to main content
HomeBlogGuidesHow to Verify a Tracking Webhook Is Authentic: Signatures, Secrets, and Replay Protection

How to Verify a Tracking Webhook Is Authentic: Signatures, Secrets, and Replay Protection

17TRACK

To verify a tracking webhook, authenticate the exact request bytes using the sender’s documented signature scheme and a secret stored on your server. If the scheme includes a signed timestamp, check its age; then reject or safely ignore repeated deliveries using a stable event identifier. Do this before updating shipment records, sending notifications, or placing the event on a processing queue.

How to Verify a Tracking Webhook Is Authentic Signatures Secrets

A valid signature answers a narrow question: whether the request matches what someone holding the signing secret could have produced. It does not prove that a tracking status is correct, that the secret has never been exposed, or that a signed request has not been replayed. Those risks need separate controls.

Start with the sender’s verification contract

There is no universal tracking-webhook signature format. Before writing verification code, confirm the details in your provider’s current documentation or integration settings. Do not substitute a signature example from another service, even if both use HMAC-SHA-256.

  • Signing method: Is the request signed with a shared-secret HMAC, an asymmetric key, or another mechanism? Which algorithm is specified?
  • Signed input: Is the signature calculated over the raw body alone, or over a timestamp, request path, and other fields as well? What is their exact order and separator?
  • Header format: Where are the signature, timestamp, key identifier, and event identifier supplied? Is the signature encoded as hexadecimal or Base64?
  • Secret scope: Is the secret associated with an account, endpoint, or environment? How are new secrets activated during rotation?
  • Delivery behavior: Can events be retried, arrive out of order, or carry an identifier that remains the same across retries?

These details are part of the security protocol, not incidental parsing choices. The HMAC specification defines how HMAC uses a secret key and a hash function; it does not define which webhook fields a particular sender signs. A verifier must follow the sender’s contract for those fields.

Verify the signature before parsing the payload

Capture the raw HTTP request body as bytes at the receiving endpoint. Many frameworks automatically parse JSON before application code runs. Parsing and serializing it again can change whitespace, property order, escaping, or number formatting. The resulting JSON may mean the same thing to an application while producing different bytes for signature verification.

  1. Receive and limit the request. Require HTTPS, impose a reasonable body-size limit, and retain the original body bytes. Identify the webhook endpoint through your own routing configuration, not through a value supplied in the payload.
  2. Read and validate the signature fields. Reject missing, malformed, ambiguous, or unsupported signature versions. Set bounds on header length and format before decoding. Do not let an untrusted header select an arbitrary cryptographic algorithm.
  3. Select the appropriate secret. Look it up from trusted configuration for the endpoint or account. If the protocol includes a key identifier, treat it as a lookup hint, not proof of identity; the calculated signature must still match.
  4. Reconstruct the signed message exactly. For example, a hypothetical scheme might sign the UTF-8 timestamp, a period, and then the raw body bytes. That is an illustration, not a format to assume your provider uses.
  5. Calculate and compare. Use a well-maintained cryptographic library to calculate the documented MAC. Decode the supplied signature into the expected byte format and compare it with the calculated value using a constant-time comparison function. A malformed or wrong-length signature must fail verification.
  6. Only then process the event. Parse JSON, validate its schema, identify the shipment, and apply business rules after authentication succeeds.

A signature mismatch is not something to repair by trimming the body, normalizing JSON, or trying several undocumented message formats. Check whether middleware changed the bytes, whether the correct environment and endpoint secret were selected, and whether the timestamp and signature were decoded exactly as specified.

Protect the signing secret

A shared-secret signature is only as trustworthy as the secret. Store webhook secrets in a server-side secret store or equivalent protected configuration, with access limited to the services and people that need it. Do not put them in browser code, mobile apps, public repositories, sample payloads, or support screenshots. Avoid logging the secret or complete authentication headers.

Keep test and production secrets separate. If multiple webhook endpoints have distinct secrets, bind each secret to its endpoint rather than searching every known secret until one matches. That binding reduces the chance of accepting a request at the wrong destination. For a multi-tenant receiver, the tenant identifier in an unverified payload must not, by itself, authorize the choice of secret or the shipment record to update.

Plan for rotation before it becomes urgent. Where the sender supports overlapping active secrets, accept the explicitly configured old and new secrets for a limited transition period, then remove the old one. Record which secret version verified a request without recording the secret itself. If a secret may have been exposed, rotate it through the sender’s documented process and review delivery logs and affected shipment actions. Signature verification alone cannot distinguish a legitimate sender from an attacker who has obtained the secret.

Block replay without discarding legitimate retries

An attacker who captures a valid signed request may be able to send those same bytes again. A signature over the body alone does not make an old request expire. Even when a timestamp is included in the request, changing an unsigned timestamp must not be allowed to renew a signature. Replay-age checks are meaningful only when the timestamp is covered by the signature or by another authenticated mechanism.

If the sender signs a timestamp, parse it strictly and reject requests outside a documented or deliberately chosen acceptance window. Check both requests that are too old and timestamps unreasonably far in the future. Keep receiver clocks synchronized. The window should account for expected delivery delays and clock skew, but a longer window also leaves more time for a captured request to be replayed. If the provider does not sign a timestamp, do not invent timestamp protection by reading an unauthenticated header; rely on the controls the provider actually supports and place more weight on deduplication and secret security.

A timestamp check is not enough on its own. The same valid request can be replayed several times while its timestamp remains acceptable. After authentication, use a stable event or delivery identifier to recognize repeats. Choose the identifier according to the sender’s documented semantics: an identifier that changes on every retry will not deduplicate one underlying event. If no suitable identifier exists, assess whether a documented combination of fields can safely identify a repeat. A body hash may help investigation, but identical bodies are not always proof that two deliveries represent the same business action.

Make the deduplication decision atomic. Two copies of a request can arrive concurrently; a separate “check, then insert” sequence can allow both through. A database uniqueness constraint or equivalent atomic operation on an appropriate key can prevent that race. Include endpoint or account scope in the key when identifiers are not globally unique. Decide how long records must remain available based on retry behavior and your operational requirements. Never add an unauthenticated request to the trusted deduplication store: otherwise an attacker could claim an event identifier before the genuine delivery arrives.

Retries and replays also need different operational treatment. A duplicate that has already been authenticated and handled can usually receive a successful acknowledgment without repeating the shipment update. A request with an invalid signature should not be treated as a harmless duplicate. Follow the sender’s documented response and retry expectations when choosing status codes; returning success too early may prevent a failed delivery from being retried.

Keep shipment updates correct after authentication

Authentication makes an event eligible for processing; it does not make every requested change appropriate. Validate required fields and types, then match the event to the account and shipment it is allowed to affect. Do not let a tracking number alone authorize access to a customer order. Apply rules for duplicate, delayed, and out-of-order statuses before changing the shipment’s current state.

Consider a delivered notification followed by an earlier in-transit event that arrives late. Both requests might be authentic. If your application treats arrival order as shipment order, the later-arriving event could incorrectly reverse the displayed status. Use the sender’s event timestamps and status definitions where documented, while recognizing that timestamps from different sources may have different meanings. Preserve the original event for audit even when your business rules decide not to change the current shipment view.

If processing takes longer than the webhook sender’s response timeout, a practical design is to verify the request, durably record the authenticated event and its deduplication key, and then acknowledge it before asynchronous business processing. The acknowledgment must not precede durable acceptance: otherwise a crash can lose an event the sender believes was received. Set up monitoring for verification failures, processing failures, queue delays, and repeated delivery attempts without exposing secrets or unnecessarily logging personal shipment data.

Test failure cases, not just the happy path

A successful test delivery proves little about the verifier’s boundaries. Build tests using the sender’s official test mechanism or documented examples where available, and include the following cases:

  • A valid request verifies when its raw bytes, signature encoding, secret, and timestamp match the contract.
  • Changing one body byte, one signed timestamp byte, or one signature byte causes verification to fail.
  • A missing, malformed, unsupported, or oversized signature fails cleanly without reaching shipment processing.
  • A signature made with the test secret does not verify against the production endpoint, and vice versa.
  • An expired signed request and an implausibly future-dated request are rejected under the configured window.
  • Two concurrent authenticated deliveries of the same event result in one business action.
  • An authentic but delayed tracking event does not incorrectly overwrite a newer shipment state.

The strongest implementation has a clear boundary: no unverified request can change shipment data, enqueue trusted work, or trigger customer communication. Signature verification, replay controls, and shipment-state rules each enforce a different part of that boundary.

FAQ

Is HTTPS enough to authenticate a tracking webhook?

No. HTTPS protects a connection to your endpoint in transit, but a publicly reachable URL can still receive requests from other clients. Verify the sender using its documented authentication mechanism, and keep HTTPS enabled as a separate transport protection. The TLS 1.3 specification describes the transport protocol; it does not replace application-level webhook authentication.

Can I verify a signature after parsing the JSON body?

Only if the sender explicitly defines the signed input in a way that permits it. For schemes that sign the raw request body, use the original bytes. Parsing and re-serializing JSON can change those bytes and make a genuine request appear invalid.

What if the webhook provider does not supply a signed timestamp?

Do not treat an unsigned timestamp as replay protection. Verify the authentication method the provider does offer, use stable event identifiers for atomic deduplication where available, protect the secret, and ask the provider about its supported replay controls if your risk assessment requires stronger guarantees.

Should a duplicate delivery return an error?

Usually not if it has passed authentication and the original event has already been safely accepted or processed: repeating the business action is the problem to avoid. Return a response consistent with the sender’s retry contract. An invalid signature, however, must fail authentication even if its payload resembles an earlier event.

Does a valid signature mean the shipment status is accurate?

No. It establishes that the request matches the sender’s signing scheme and secret. Shipment accuracy still depends on the underlying tracking data, correct account and shipment matching, event ordering, and your application’s status rules.

Sources