Skip to content

Sign backend calls to the mediator's operator routes - #54

Merged
widrss merged 1 commit into
mainfrom
feat/operator-route-auth
Nov 18, 2026
Merged

widrss merged 1 commit into
mainfrom
feat/operator-route-auth

Conversation

@widrss

@widrss widrss commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

The backend now signs its calls to the mediator's operator routes: POST /mediate/{escrow_id} (trigger_mediation, trigger_training_mediation) and GET /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:

Header Value
X-A2ASE-Timestamp unix seconds
X-A2ASE-Nonce secrets.token_urlsafe(24), new for every request
X-A2ASE-Signature v2= + hex HMAC-SHA256 keyed with MEDIATOR_WEBHOOK_SECRET

Signed bytes:

v2\n{timestamp}\n{nonce}\n{METHOD}\n{target}\n{body}
  • target is the route path the mediator sees (/mediate/<id>, /audits/<id>). A path prefix in MEDIATOR_URL is not signed, so a proxy that strips the prefix still hands the mediator a request that verifies.
  • The escrow ID is percent-encoded with 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.
  • The JSON body is serialized once, and those bytes are both signed and sent.

verify_patch is 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 main over HTTP and the calls behaved as before.

If the mediator change is deployed first, the currently deployed backend's unsigned calls to /mediate and /audits get 401 until this is deployed.

With MEDIATOR_WEBHOOK_SECRET empty the calls go out unsigned, as they do today, so local development against mock_mediator.py keeps working. A mediator that requires signatures rejects such calls.

MEDIATOR_URL now has a trailing slash stripped for these calls, as verify_patch already 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, and verify_patch keeping its own form.

Backend suite: 2101 passed (2085 on main before 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

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>
@widrss
widrss merged commit 7b2ec27 into main Nov 18, 2026
2 checks passed
@widrss
widrss deleted the feat/operator-route-auth branch November 18, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant