Skip to content

feat(client): add an Authorize hook to verify challenges before auto-payment - #128

Open
EfeDurmaz16 wants to merge 1 commit into
tempoxyz:mainfrom
EfeDurmaz16:feat/client-authorize-hook
Open

feat(client): add an Authorize hook to verify challenges before auto-payment#128
EfeDurmaz16 wants to merge 1 commit into
tempoxyz:mainfrom
EfeDurmaz16:feat/client-authorize-hook

Conversation

@EfeDurmaz16

Copy link
Copy Markdown
Contributor

client.Transport auto-pays the first matching challenge: RoundTrip calls CreateCredential with no interception point, so an application cannot verify amount, recipient, or asset before its wallet signs. The core spec makes that verification a client MUST and says clients MUST NOT trust description (Security Considerations, "Amount Verification"). mpp-go is the only SDK without such a hook: mppx has onChallenge, mpp-rs has challenge.received handlers, pympp has on_challenge_received.

This adds the smallest surface for it: an optional Authorize func(ctx context.Context, challenge *mpp.Challenge) error field on Transport, plus a WithAuthorize option for Client.Do users. Nil keeps current behavior byte-for-byte. Returning an error declines the payment: CreateCredential never runs and the caller gets the server's original 402 unmodified, the same semantics as the existing no-matching-method path.

Not a spend cap on purpose: Challenge has no top-level amount (amounts live in method-specific request maps), and rail-level budgets already have a home in Tempo access keys. The client-side MUST needs a seam, not a policy engine.

Composes with #118: if the multi-challenge retry loop lands, the hook guards each candidate.

Tests: declined payment returns the untouched 402 with zero CreateCredential calls and no retry; an approving hook sees the matched challenge; the option plumbs through Client.Do. go build, go vet, and go test ./... pass locally. Changelog fragment included (minor).

…payment

The transport auto-pays the first matching non-expired challenge with no
interception point: RoundTrip calls CreateCredential unconditionally, so
an application cannot verify the requested amount, recipient, or asset
before its wallet signs. The core spec makes that verification a client
MUST (draft-httpauth-payment-00, Security Considerations, Amount
Verification) and says clients must not trust the challenge description.
Every sibling SDK exposes such a hook (mppx onChallenge, mpp-rs
challenge.received handlers, pympp on_challenge_received); mpp-go is the
only one without an interception surface.

Add an optional Authorize func(ctx, *mpp.Challenge) error field on
Transport, plus a WithAuthorize option so Client.Do users can reach it.
The hook runs after origin validation and before the 402 body is
drained; returning an error declines the payment and returns the
server's original 402 response unmodified, exactly like the
no-matching-method path. A nil hook preserves current behavior
byte-for-byte.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

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