feat(client): add an Authorize hook to verify challenges before auto-payment - #128
Open
EfeDurmaz16 wants to merge 1 commit into
Open
feat(client): add an Authorize hook to verify challenges before auto-payment#128EfeDurmaz16 wants to merge 1 commit into
EfeDurmaz16 wants to merge 1 commit into
Conversation
…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.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
client.Transportauto-pays the first matching challenge:RoundTripcallsCreateCredentialwith 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 trustdescription(Security Considerations, "Amount Verification"). mpp-go is the only SDK without such a hook: mppx hasonChallenge, mpp-rs haschallenge.receivedhandlers, pympp hason_challenge_received.This adds the smallest surface for it: an optional
Authorize func(ctx context.Context, challenge *mpp.Challenge) errorfield onTransport, plus aWithAuthorizeoption forClient.Dousers. Nil keeps current behavior byte-for-byte. Returning an error declines the payment:CreateCredentialnever 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:
Challengehas 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
CreateCredentialcalls and no retry; an approving hook sees the matched challenge; the option plumbs throughClient.Do.go build,go vet, andgo test ./...pass locally. Changelog fragment included (minor).