toolhq.io

All posts
7 min readby Jameel Haider

HTTP Message Signatures: the standard way to sign a request

Every webhook provider invented its own signature scheme. Each one picks a header name, issues a secret, assembles a string to sign from some subset of the timestamp, the method, the path and the body, and runs an HMAC over it. They all do the same job slightly differently, and every new integration means reading another page of documentation to learn which pieces go in which order.

HTTP Message Signatures is the IETF standard that generalises this. It does not replace HMAC. It standardises everything around it: what gets signed, how it is written down, and how the result travels with the request.

How it works

The signer picks an ordered list of components to cover, builds a deterministic string from them called the signature base, signs that, and sends two headers. Signature-Input names the covered components and the parameters. Signature carries the bytes.

POST /hooks/orders HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Digest: sha-256=:<base64 hash of the body>:
Signature-Input: sig1=("@method" "@target-uri" "content-type" "content-digest");created=1794614400;keyid="key-2026-11";alg="hmac-sha256"
Signature: sig1=:<base64 signature>:

The verifier does not trust anything the sender computed. It reads Signature-Input, rebuilds the base from the request it actually received, and checks the signature against it. For the request above, the base is:

"@method": POST
"@target-uri": https://api.example.com/hooks/orders
"content-type": application/json
"content-digest": sha-256=:<base64 hash of the body>:
"@signature-params": ("@method" "@target-uri" "content-type" "content-digest");created=1794614400;keyid="key-2026-11";alg="hmac-sha256"

The last line is the component list and its parameters, so those are signed too. Nobody can change the timestamp or drop a component from the list without breaking the signature.

Components and parameters

Components come in two kinds.

  • Header fields, named in lower case: "content-type", "content-digest", "authorization".
  • Derived components, taken from the request itself and written with a leading @, such as @method, @target-uri and @authority.

Covering the derived components is what stops a signed request being replayed against a different path or host. A signature over the body alone says the payload is real. It says nothing about where the payload was meant to go.

The parameters on Signature-Input carry the metadata.

ParameterPurpose
keyidWhich key signed the request
algThe algorithm, where the key does not already imply it
createdWhen the signature was made
expiresWhen it stops being valid
nonceA unique value, to detect replay
tagAn application specific label for the signature's purpose

sig1 in the example is a label, and a request can carry several signatures under different labels. That matters when a proxy adds its own: it signs under a second label and leaves the first intact, so the final recipient can check both.

The body is covered indirectly

Notice that the body never appears in the signature base. You add a Content-Digest header holding a hash of the body, then include that header in the covered components. The signature protects a digest of the body, not the bytes themselves.

This has a practical benefit. A verifier can check the signature from the headers alone, reject a bad request before reading a large body, and hash the body as it streams in. It also has a catch that bites people: verifying the signature is only half the work. You must also hash the body you received and compare it with Content-Digest. Skip that step and an attacker can keep the signed headers and swap the body. You can compute a SHA-256 of a sample payload with the Hash Generator to check your digest code, bearing in mind that the header holds the base64 form of the hash, not hex.

Why the deterministic base matters

A signature over a loosely defined string breaks whenever something between the two ends touches the request. A proxy reorders headers, folds two values into one line, or changes the spacing after a colon, and a signature that was valid when it left is invalid when it arrives.

The standard defines exactly how each component is serialised: names in lower case, surrounding whitespace trimmed, repeated fields joined in a set way, and rules for structured fields. This is the hard part, and it is the part any homegrown scheme gets wrong. Most bespoke webhook signatures avoid the problem by signing only the raw body and a timestamp, which is why they cannot protect the method or the path.

When a verification fails, the base is the place to look. Log the base your code built, ask the sender for theirs, and compare them line by line. If both ends use HMAC, paste the base and the secret into the HMAC Generator to see the expected output without sending either to a server.

Verification rules for either scheme

The checklist is the same whether you verify the standard or a provider's own format. How to verify webhook signatures with HMAC walks through the bespoke case in code.

  • Compare with a constant time comparison. A plain string equality check can leak how many leading bytes matched.
  • Reject a missing created, and one outside a tolerance window. A few minutes either side allows for clock drift. Honour expires if it is present.
  • Keep a nonce or idempotency record. A timestamp narrows the replay window but does not close it. Idempotency keys cover the storage side.
  • Verify before parsing the body. Do not hand unauthenticated input to a JSON parser, and do not hash a parsed and reserialised copy.
  • Check that the components you need are covered. A valid signature over @method alone proves very little. Decide the minimum list and refuse anything less.
  • Support two active keys. keyid tells you which one to use, so rotation does not need a flag day.

HMAC or asymmetric keys

The standard allows both. With HMAC, the two ends share one secret, and anyone who holds it can both verify and sign. A leak on the receiving side lets an attacker forge requests.

Asymmetric keys are a real advantage here. The signer keeps a private key and the verifier only needs the public one, so a leak of the verifier's copy does not let anyone forge anything. That suits a provider signing for thousands of customers, who can all fetch the same public key.

HMAC remains fine when both ends are yours, and it is simpler and faster. SHA-256 vs HMAC vs bcrypt explains where a keyed hash fits among the alternatives.