fix(x402): derive WWW-Authenticate realm from host, not full endpoint URL - #93
Merged
Conversation
…endpoint URL The Checkout auto-derived the MPP challenge realm from the full endpoint `url` (e.g. https://agents.example.com/purchase), so the emitted WWW-Authenticate realm carried the path. The Node SDK passes `new URL(APP_URL).host`; validators expect the realm to be the bare protection-space host. `_realm_from_url` normalizes the derived realm to the host (agents.example.com), restoring parity with the Node SDK. Falls back to the input unchanged when it has no parseable host. Bump to 2.5.11. Co-Authored-By: Claude Opus 4.8 <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.
Surfaced by
npx mppx@latest validateagainst store: the challenge realm washttps://agents.agentscore.com/purchase(full URL with path) while martin/sayer (Node) emit the bare host.Root cause: the Python Checkout auto-derived the MPP realm from the full endpoint
url. The Node SDK passesnew URL(APP_URL).host; the WWW-Authenticate realm should be the bare protection-space host._realm_from_urlnormalizes the derived realm to the host, restoring parity. Falls back to the input unchanged when it has no parseable host (already-bare host, relative path).Advisory-only (the challenge was fully valid and settles); this clears the validator warning and aligns the two SDKs.
Unit test covers full-URL, host:port, bare-host, and relative-path cases. Full suite green (1841 passed, 95.36% coverage), ruff + ty clean.
🤖 Generated with Claude Code