Repository navigation
Description
Summary
SingleAgentClient.verifyWebhookSignature() computes the expected HMAC over JSON.stringify(payload) (a re-serialized parsed object) instead of the raw HTTP body bytes. This is the same class of bug as adcontextprotocol/adcp-client-python#151 on the Python signing side.
The Problem
// SingleAgentClient.js line 653
const message = `${ts}.${JSON.stringify(payload)}`;payload here is the parsed JavaScript object from req.body. JSON.stringify re-serializes it, which may not produce the same bytes that were on the wire. For example:
- Sender (Python) sends:
{"key": "value", "num": 1.0} JSON.stringify(JSON.parse(...))produces:{"key":"value","num":1}- Key ordering, spacing, number formatting, and unicode escaping all vary by language
The HMAC will only match if JSON.stringify happens to produce byte-identical output to the sender's serializer. This is fragile and breaks cross-language interop.
The Correct Approach
HMAC verification must always use the raw HTTP body bytes — the exact bytes received on the wire, before JSON parsing. This is how GitHub, Stripe, and Slack all implement webhook HMAC verification.
The AdCP spec itself says: HMAC-SHA256(secret, rawBody) — not HMAC-SHA256(secret, JSON.stringify(parsed)).
Current Workaround
We bypass this method entirely by passing enforceWebhookSignature=false and implementing our own raw-body verification:
// Our workaround in adcp-webhook.ts
const message = `${ts}.${rawBody}`; // rawBody = actual wire bytes
const expected = `sha256=${createHmac('sha256', secret).update(message).digest('hex')}`;Suggested Fix
Change verifyWebhookSignature to accept raw body bytes instead of a parsed object:
// BEFORE (broken):
verifyWebhookSignature(payload: object, signature: string, timestamp: string | number): boolean {
const message = `${ts}.${JSON.stringify(payload)}`;
// ...
}
// AFTER (correct):
verifyWebhookSignature(rawBody: string, signature: string, timestamp: string | number): boolean {
const message = `${ts}.${rawBody}`;
// ...
}This is a breaking API change, so it could be offered alongside the old method during a deprecation period:
verifyWebhookSignatureRaw(rawBody: string, signature: string, timestamp: string | number): booleanRelated
- Python client has the same issue on the signing side: Bug: get_adcp_signed_headers_for_webhook signs compact JSON but wire body uses default JSON adcp-client-python#151
- Spec PR to clarify raw body requirement: docs: update HMAC-SHA256 webhook spec to match reference implementation adcp#1382
Activity
EmmaLouise2018 commentedon Mar 11, 2026
The spec (now on main) explicitly requires raw bytes:
See: https://docs.adcontextprotocol.org/docs/building/implementation/webhooks#hmac-sha256-recommended-for-production
Raw bytes is the only correct approach because the raw HTTP body is the one string both sender and receiver are guaranteed to have in common. The sender created it, the receiver received it. The moment either side re-serializes a parsed object, you lose that guarantee —
JSON.stringify()in JS andjson.dumps()in Python produce different output for the same logical data (key ordering, whitespace, number formatting like1.0vs1, unicode escaping). This is how GitHub, Stripe, and Slack all implement webhook HMAC verification.verifyWebhookSignaturecurrently takes a parsed object and callsJSON.stringify(payload)on line 653 of SingleAgentClient.js. This needs to acceptrawBody: stringinstead.fix: use raw body bytes for webhook HMAC verification (#313)
fix: use raw body bytes for webhook HMAC verification (#313)