Title: Bug: get_adcp_signed_headers_for_webhook signs compact JSON but wire body uses default JSON · Issue #151 · adcontextprotocol/adcp-client-python · GitHub
Open Graph Title: Bug: get_adcp_signed_headers_for_webhook signs compact JSON but wire body uses default JSON · Issue #151 · adcontextprotocol/adcp-client-python
X Title: Bug: get_adcp_signed_headers_for_webhook signs compact JSON but wire body uses default JSON · Issue #151 · adcontextprotocol/adcp-client-python
Description: Summary get_adcp_signed_headers_for_webhook() in src/adcp/webhooks.py computes the HMAC signature over compact JSON (no spaces), but callers send the HTTP body via requests.post(url, json=payload) which uses default JSON (with spaces). R...
Open Graph Description: Summary get_adcp_signed_headers_for_webhook() in src/adcp/webhooks.py computes the HMAC signature over compact JSON (no spaces), but callers send the HTTP body via requests.post(url, json=payload) ...
X Description: Summary get_adcp_signed_headers_for_webhook() in src/adcp/webhooks.py computes the HMAC signature over compact JSON (no spaces), but callers send the HTTP body via requests.post(url, json=payload) ...
Opengraph URL: https://github.com/adcontextprotocol/adcp-client-python/issues/151
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Bug: get_adcp_signed_headers_for_webhook signs compact JSON but wire body uses default JSON","articleBody":"## Summary\n\n`get_adcp_signed_headers_for_webhook()` in `src/adcp/webhooks.py` computes the HMAC signature over **compact JSON** (no spaces), but callers send the HTTP body via `requests.post(url, json=payload)` which uses **default JSON** (with spaces). Receivers that verify against raw HTTP body bytes (per the AdCP spec) will always get a signature mismatch.\n\n## Root Cause\n\nIn `get_adcp_signed_headers_for_webhook()`:\n\n```python\npayload_bytes = json.dumps(payload_dict, separators=(\",\", \":\"), sort_keys=False).encode(\"utf-8\")\nsigned_message = f\"{timestamp}.{payload_bytes.decode('utf-8')}\"\n```\n\nThis signs over compact JSON: `{\"contextId\":\"msg_123\",\"final\":false}`\n\nBut the caller sends the body with `requests.post(url, json=payload)`, which internally uses `json.dumps(payload)` with default separators, producing: `{\"contextId\": \"msg_123\", \"final\": false}`\n\nThe receiver verifies `HMAC(secret, \"{timestamp}.{raw_http_body}\")` — since the raw body has spaces but the signature was computed without spaces, they never match.\n\n## Reference Implementation Mismatch\n\nThe official [`@adcp/client` JS library](https://github.com/adcontextprotocol/adcp-client) (the reference implementation) uses `JSON.stringify(payload)` for signing, which produces **default serialization with spaces** — matching what goes on the wire.\n\nFrom the [JS test suite](https://github.com/adcontextprotocol/adcp-client/blob/main/test/webhook-signature-verification.test.js):\n\n```javascript\nconst message = `${timestamp}.${JSON.stringify(payload)}`;\nconst hmac = crypto.createHmac('sha256', webhookSecret);\nhmac.update(message);\nconst signature = `sha256=${hmac.digest('hex')}`;\n```\n\n`JSON.stringify` output: `{\"contextId\": \"msg_123\", \"final\": false}` (with spaces after `:` and `,`)\n\nThe Python client should match this behavior.\n\n## Reproduction\n\n```python\nimport json, hashlib, hmac\n\npayload = {\"contextId\": \"msg_123\", \"final\": False, \"kind\": \"status-update\"}\nsecret = \"my-test-webhook-secret-that-is-32chars!\"\ntimestamp = \"1773185740\"\n\n# What get_adcp_signed_headers_for_webhook signs (compact):\ncompact = json.dumps(payload, separators=(\",\", \":\"), sort_keys=False)\n# '{\"contextId\":\"msg_123\",\"final\":false,\"kind\":\"status-update\"}'\n\n# What requests.post(json=payload) sends on the wire (default):\ndefault = json.dumps(payload)\n# '{\"contextId\": \"msg_123\", \"final\": false, \"kind\": \"status-update\"}'\n\nsig_compact = hmac.new(secret.encode(), f\"{timestamp}.{compact}\".encode(), hashlib.sha256).hexdigest()\nsig_default = hmac.new(secret.encode(), f\"{timestamp}.{default}\".encode(), hashlib.sha256).hexdigest()\n\nprint(f\"Match: {sig_compact == sig_default}\") # False\n```\n\n## Suggested Fix\n\n```python\n# In get_adcp_signed_headers_for_webhook(), change:\npayload_bytes = json.dumps(payload_dict, separators=(\",\", \":\"), sort_keys=False).encode(\"utf-8\")\n\n# To:\npayload_bytes = json.dumps(payload_dict).encode(\"utf-8\")\n```\n\nThis aligns with the JS reference implementation's `JSON.stringify()` behavior.\n\nAlternatively, the function's docstring could be updated to instruct callers to pre-serialize and send with `data=` instead of `json=`, but that's a larger change for all consumers.\n\n## Impact\n\nAll consumers of `get_adcp_signed_headers_for_webhook()` that use `requests.post(json=...)` or `httpx.post(json=...)` will have webhook HMAC validation failures on the receiver side. This is currently breaking `create_media_buy`, `update_media_buy`, and `sync_creatives` webhook callbacks.","author":{"url":"https://github.com/EmmaLouise2018","@type":"Person","name":"EmmaLouise2018"},"datePublished":"2026-03-11T00:35:26Z","url":"https://github.com/adcontextprotocol/adcp-client-python/issues/151"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4e3fb4a2-3575-8c49-351d-e7653338a292 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8BA0:1148D3:EF6227:132A233:6B010EBB |
| html-safe-nonce | 7b26ba4053662dcdb4d2f2800d7bd493b1927394173630cc861a5522fd71db5a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QkEwOjExNDhEMzpFRjYyMjc6MTMyQTIzMzo2QjAxMEVCQiIsInZpc2l0b3JfaWQiOiIzODE0NDE1NjQzNDA3NjE3NzIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 5bcd2471c20c13876fe21343fce031ec879cc97c7813fd1c88fdb4c1ca43aca7 |
| hovercard-subject-tag | issue:4054978979 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/adcontextprotocol/adcp-client-python/151/issue_layout |
| twitter:image | https://opengraph.githubassets.com/41f8e4fdb5ca5097a35659e64bc811a363c030aa45f65962c7127aff330f5235/adcontextprotocol/adcp-client-python/issues/151 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/41f8e4fdb5ca5097a35659e64bc811a363c030aa45f65962c7127aff330f5235/adcontextprotocol/adcp-client-python/issues/151 |
| og:image:alt | Summary get_adcp_signed_headers_for_webhook() in src/adcp/webhooks.py computes the HMAC signature over compact JSON (no spaces), but callers send the HTTP body via requests.post(url, json=payload) ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | EmmaLouise2018 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/adcontextprotocol/adcp-client-python git https://github.com/adcontextprotocol/adcp-client-python.git |
| octolytics-dimension-user_id | 221690821 |
| octolytics-dimension-user_login | adcontextprotocol |
| octolytics-dimension-repository_id | 1090305973 |
| octolytics-dimension-repository_nwo | adcontextprotocol/adcp-client-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1090305973 |
| octolytics-dimension-repository_network_root_nwo | adcontextprotocol/adcp-client-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width