fix(compliance-cli-python): verify HMAC over raw bytes, not a re-serialized parse#64
Open
ucekmez wants to merge 1 commit into
Open
fix(compliance-cli-python): verify HMAC over raw bytes, not a re-serialized parse#64ucekmez wants to merge 1 commit into
ucekmez wants to merge 1 commit into
Conversation
…alized parse
The Python compliance CLI computed the webhook HMAC over json.dumps() of
the *parsed* body, so key order, whitespace, and unicode escaping differed
from the bytes the publisher actually signed — producing false "signature
mismatch" results against conformant publishers. It also mishandled rotated
multi-signature headers via str.replace("v1,", "").
Capture the exact received body bytes in the receiver and verify through a
new, tested verify_webhook_signature() helper that mirrors the TypeScript
verifyWebhookSignature: raw-byte signed content, space-separated v1 token
rotation, timing-safe digest comparison, and structured reasons (ok /
ok_via_multi_signature / missing_secret / malformed_header / no_v1_token /
signature_mismatch). Brings the Python conformance tooling to parity with TS.
Signed-off-by: Ugur Cekmez <ucekmez@gmail.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Audit finding (conformance vertical, #17): the Python compliance CLI verified
the webhook HMAC over
json.dumps(parsed_body)— re-serializing the parseinstead of hashing the bytes the publisher signed. Key order, whitespace, and
unicode escaping differ, so the check produced false "signature mismatch"
results against perfectly conformant publishers. It also mishandled rotated
multi-signature headers via
str.replace("v1,", "").The TypeScript CLI already does this correctly (
verifyWebhookSignatureoverraw bytes); this brings the Python tooling to parity.
Change
_received_raw_body) in the webhookreceiver, separate from the parsed JSON.
verify_webhook_signature()helper mirroring the TS one:raw-byte signed content, space-separated
v1token rotation, timing-safedigest comparison, and structured reasons (
ok/ok_via_multi_signature/missing_secret/malformed_header/no_v1_token/signature_mismatch).hashlib/hmac/base64imports.Tests
tests/test_helpers.py: 25 passed. NewTestVerifyWebhookSignaturecovers thehappy path over raw bytes, a regression test proving a re-serialized body now
fails (the original bug), multi-signature rotation, and every reason branch.
Part of the EEP vertical-audit follow-up (Wave 1). Python-only; no wire/schema
change.
🤖 Generated with Claude Code