Skip to content

fix(headers): accept method identifiers with digits, colons, underscores, hyphens - #414

Closed
ygd58 wants to merge 1 commit into
tempoxyz:mainfrom
ygd58:fix/method-identifier-charset
Closed

ygd58 wants to merge 1 commit into
tempoxyz:mainfrom
ygd58:fix/method-identifier-charset

Conversation

@ygd58

@ygd58 ygd58 commented Sep 10, 2026

Copy link
Copy Markdown

What

parse_www_authenticate rejected any method identifier containing a character other than an ASCII lowercase letter (method_raw.chars().all(|c| c.is_ascii_lowercase())), so canonical identifiers like x402 or tempo-v2 were rejected outright — before challenge selection or payment could even occur. Canonical mppx (Challenge.ts's deserialize validator) accepts the method-name ABNF ^[a-z][a-z0-9:_-]*$: a lowercase letter, followed by any number of lowercase letters, digits, colons, underscores, or hyphens.

Flagged by the cross-SDK audit as AGR-2026-092 — high severity.

Fix

Add is_valid_method_name implementing that exact grammar and use it in place of the letters-only check. The digit-prefix and non-letter-first rejections (an identifier can't start with anything but a lowercase letter) are unchanged — only the previously-blanket "every character must be a-z" requirement is relaxed to the full canonical charset for characters after the first.

A pre-existing test asserted the bug

test_parse_www_authenticate_rejects_invalid_method_name_dash explicitly asserted that "tempo-v2" should be rejected. Per the ABNF above, hyphens are valid after the first character, so this assertion was backwards. Replaced it with test_parse_www_authenticate_accepts_hyphen_in_method_name (same input, corrected expectation) and added test_parse_www_authenticate_accepts_extension_characters_in_method_name covering colons, underscores, digits, and x402 specifically (the identifier named in the issue this fixes). The other three existing method-name tests (digit-prefix, non-letter/invalid-char, mixed-case) were already asserting correct behavior per the ABNF and are unchanged.

Testing

I could not run the test suite in my sandbox: cargo test always builds dev-dependencies (alloy-json-rpc, axum, tower, ...) regardless of --no-default-features, and one of their transitive dependencies (rand_pcg 0.10.2, confirmed even after deleting Cargo.lock and letting it re-resolve) requires Cargo >= 1.85 (edition2024), which I don't have available. I reviewed the change carefully by hand and traced every call site of is_valid_method_name (there's exactly one). Please run cargo test -p mpp headers::tests before merging, happy to fix anything that doesn't match.

Fixes tempoxyz/mpp-tools#218

…res, hyphens

parse_www_authenticate rejected any method identifier containing a
character other than an ASCII lowercase letter (method_raw.chars().all(|c|
c.is_ascii_lowercase())), so canonical identifiers like "x402" or
"tempo-v2" were rejected outright -- before challenge selection or
payment could even occur. Canonical mppx (Challenge.ts's deserialize
validator) accepts the method-name ABNF ^[a-z][a-z0-9:_-]*$: a
lowercase letter, followed by any number of lowercase letters, digits,
colons, underscores, or hyphens.

Add is_valid_method_name implementing that exact grammar and use it in
place of the letters-only check. The digit-prefix and non-letter-first
rejections (an identifier can't start with anything but a lowercase
letter) are unchanged -- only the previously-blanket "every character
must be a-z" requirement is relaxed to the full canonical charset for
characters after the first.

Found a pre-existing test,
test_parse_www_authenticate_rejects_invalid_method_name_dash, that
explicitly asserted the *bug*: "tempo-v2" should be rejected. Per the
ABNF above hyphens are valid after the first character, so this
assertion was backwards. Replaced it with
test_parse_www_authenticate_accepts_hyphen_in_method_name (same input,
corrected expectation) and added
test_parse_www_authenticate_accepts_extension_characters_in_method_name
covering colons, underscores, digits, and "x402" specifically (the
identifier named in the issue this fixes). The other three existing
method-name tests (digit-prefix, non-letter/invalid-char, mixed-case)
were already asserting correct behavior per the ABNF and are
unchanged.

I could not run the test suite in my sandbox: `cargo test` always
builds dev-dependencies (alloy-json-rpc, axum, tower, ...) regardless
of --no-default-features, and one of their transitive dependencies
(rand_pcg 0.10.2, via a fresh dependency resolution after deleting
Cargo.lock) requires Cargo >= 1.85 (edition2024) which I don't have
available. I reviewed the change carefully by hand and traced every
call site of is_valid_method_name (there's exactly one). Please run
`cargo test -p mpp headers::tests` before merging.

Fixes tempoxyz/mpp-tools#218 (AGR-2026-092)
@brendanjryan

Copy link
Copy Markdown
Collaborator

Superseded by #428, which retains this method-grammar fix, adds serde parity and broader tests, and is covered by tempoxyz/mpp-tools#240. Thank you for identifying this.

@ygd58

ygd58 commented Sep 21, 2026

Copy link
Copy Markdown
Author

Thanks for the broader fix — closing this in favor of #428.

brendanjryan added a commit to tempoxyz/mpp-tools that referenced this pull request Sep 21, 2026
## Motivation

Challenge-header behavior has drifted across SDKs because Unicode escape
and extension-method cases were absent from the shared vectors.

## Summary

- add BMP, astral, realm, literal escape, truncated escape, and raw
Latin-1 scenarios
- add the canonical extended method identifier scenario
- exercise parse, format, and round-trip behavior where applicable

## Key design considerations

- mppx wire behavior remains the golden reference
- SDK updates: [mpp-rs
#428](tempoxyz/mpp-rs#428), [mpp-go
#168](tempoxyz/mpp-go#168), and [pympp
#256](tempoxyz/pympp#256)
- original reports: [mpp-rs
#414](tempoxyz/mpp-rs#414), [mpp-rs
#418](tempoxyz/mpp-rs#418), [mpp-go
#154](tempoxyz/mpp-go#154), and [pympp
#247](tempoxyz/pympp#247)
- keep this draft until the pinned SDK revisions contain the
corresponding fixes

---------

Co-authored-by: Kanan <93033289+kriss39@users.noreply.github.com>
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.

[Agricola] AGR-2026-092: Valid method identifiers containing digits or separators are rejected

2 participants