Repository navigation
Sign backend calls to the mediator's operator routes - #54
Merged
Merged
Conversation
trigger_mediation, trigger_training_mediation and get_audit now send
X-A2ASE-Timestamp, X-A2ASE-Nonce and X-A2ASE-Signature: v2=<hex>, an
HMAC-SHA256 keyed with MEDIATOR_WEBHOOK_SECRET over
v2\n{timestamp}\n{nonce}\n{METHOD}\n{target}\n{body}
The body is serialized once and the same bytes are signed and sent. The
target is the route path the mediator sees, without any path prefix in
MEDIATOR_URL, and the escrow ID is percent-encoded before it is signed
and sent.
A mediator that does not check these headers ignores them, so this can
be deployed before the mediator starts requiring the signature. With no
secret configured the calls go out unsigned, as before.
verify_patch keeps its {timestamp}.{body} signature.
Co-Authored-By: Claude Fable 5.2 <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.
What
The backend now signs its calls to the mediator's operator routes:
POST /mediate/{escrow_id}(trigger_mediation,trigger_training_mediation) andGET /audits/{escrow_id}(get_audit).This is the client half of a2a-settlement/a2a-settlement-mediator#12, which makes the mediator require the signature.
Signature
Headers:
X-A2ASE-TimestampX-A2ASE-Noncesecrets.token_urlsafe(24), new for every requestX-A2ASE-Signaturev2=+ hex HMAC-SHA256 keyed withMEDIATOR_WEBHOOK_SECRETSigned bytes:
targetis the route path the mediator sees (/mediate/<id>,/audits/<id>). A path prefix inMEDIATOR_URLis not signed, so a proxy that strips the prefix still hands the mediator a request that verifies.quote(..., safe="")before it is signed and sent, so the signed target and the wire path are the same string. For IDs made of letters, digits,-,_,.and~the URL is unchanged.verify_patchis unchanged and keeps its{timestamp}.{body}signature.Compatibility and deploy order
Deploy this before the mediator change. A mediator that does not check these headers ignores them. I ran this client against the mediator's current
mainover HTTP and the calls behaved as before.If the mediator change is deployed first, the currently deployed backend's unsigned calls to
/mediateand/auditsget 401 until this is deployed.With
MEDIATOR_WEBHOOK_SECRETempty the calls go out unsigned, as they do today, so local development againstmock_mediator.pykeeps working. A mediator that requires signatures rejects such calls.MEDIATOR_URLnow has a trailing slash stripped for these calls, asverify_patchalready did.Tests
backend/tests/test_mediator_operator_signing.py(16 tests): known-answer signatures that the mediator's test suite asserts as well, recomputation of the signature from the bytes on the wire, binding to method and path, percent-encoding, a fresh nonce and timestamp per call, unsigned calls with no secret, 401/409/503 surfacing as errors, andverify_patchkeeping its own form.Backend suite: 2101 passed (2085 on
mainbefore this change, plus the 16 new tests), Python 3.11.I also ran the client against a local mediator built from the companion branch: signed calls pass authentication; a wrong secret or no signature gets 401.
🤖 Generated with Claude Code