fix: HMAC-bound challenge IDs for MCP transport + add description/externalId to ChargeRequest#38
Merged
brendanjryan merged 2 commits intomainfrom Feb 16, 2026
Merged
Conversation
…ernalId to ChargeRequest
Two spec compliance fixes:
1. MCP challenge IDs now use HMAC-SHA256 (HIGH severity)
- Replaced secrets.token_urlsafe(16) with generate_challenge_id()
in create_challenge() and verify_or_challenge()
- Added secret_key parameter to create_challenge(), verify_or_challenge(),
and the @pay decorator
- verify_or_challenge() now verifies echoed challenge IDs against
recomputed HMAC, matching the HTTP transport pattern
- Challenge IDs are cryptographically bound to realm, method, intent,
request, and expires per the MCP spec
2. Add description and externalId to ChargeRequest (LOW severity)
- Added optional description and externalId fields per charge intent
spec Section 5.1.2
Tests: 68 MCP + tempo tests passing, 161 total
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.
Summary
Two spec compliance fixes identified during audit of pympp against the MPP specifications.
1. MCP challenge IDs use HMAC-SHA256 instead of random tokens (HIGH severity)
Problem:
create_challenge()inmcp/verify.pyusedsecrets.token_urlsafe(16)for challenge IDs. The MCP spec requires challenge IDs to be cryptographically bound to realm, method, intent, request, and expires.Fix:
generate_challenge_id()frommpp.__init__(HMAC-SHA256)secret_keyparameter tocreate_challenge(),verify_or_challenge(), and the@paydecoratorverify_or_challenge()now verifies echoed challenge IDs against recomputed HMAC before proceeding to intent verification, matching the pattern used in the HTTP transport (server/verify.py)@paydecorator auto-detectssecret_keyfromMPP_SECRET_KEYenv var viadetect_secret_key()if not explicitly provided2. Add
descriptionandexternalIdtoChargeRequest(LOW severity)Problem: The charge intent spec (Section 5.1.2) defines
descriptionandexternalIdas optional request fields, but the Pydantic model was missing them.Fix: Added both as
str | None = Nonefields toChargeRequest.Tests
test_rejects_credential_with_invalid_challenge_idverifies forged IDs are rejectedtest_challenge_id_is_hmac_bound,test_challenge_id_deterministictest_charge_request_with_description,test_charge_request_with_external_id,test_charge_request_description_and_external_id_default_none,test_charge_request_serializes_optional_fields