Same bytes, three parsers: duplicate keys, a trailing ?, and null in a signed payment payload
This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail.
Same bytes, three parsers
2026-12-03 · what duplicate keys, a trailing ?, and null do to a signed payment payload
An x402 payment intent is signed over bytes. The verifier receives a document and must decide whether those bytes are the ones that were signed. There are two ways to do that, and they disagree exactly when it matters:
- Hash the received bytes. The parser is only used to find the signature and the fields needed to look up a key.
- Parse, rebuild, then hash. The parser now sits inside the trust boundary. Whatever it discards — a duplicate name, an empty query marker, the difference between
nulland""— is lost before the digest is computed, and the verifier cannot tell that it happened.
The second approach is the common one, because it is easier to write. Below is what the three parsers a checker is most likely to be built on actually do with the cases that separate the two approaches. Everything was run on the current releases — Node, CPython, and Go 1.26 — and every output quoted here is a copy of what the command printed.
1. Duplicate names lose a value, not always the same one
RFC 8259 says object names should be unique and does not say what a parser must do when they are not. In practice all three parsers accept the document and keep the last value:
input: {"url":"a","url":"b"} Node JSON.parse(input) -> { url: "b" } CPython json.loads(input) -> {'url': 'b'} Go json.Unmarshal(input, &map[string]any{}) -> map[url:b] None raises. But "the value is gone" is only true if you require the parser to hand you a finished object. Two of the three standard libraries will show you the pair if you ask during decoding:
CPython json.loads(input, object_pairs_hook=lambda pairs: pairs) -> [('url', 'a'), ('url', 'b')] Go dec := json.NewDecoder(strings.NewReader(input)) for { tok, err := dec.Token(); if err != nil { break }; ... } -> { url a url b } Node is the outlier. Its reviver is invoked once per surviving member, so for the input above it receives "b" and never sees "a":
JSON.parse('{"url":"a","url":"b"}', (k, v) => { seen.push([k, v]); return v }) -> [["url","b"], ["", {"url":"b"}]] // one url, one root — not two urls The consequence for a fixture row is concrete. A rule "duplicate url is rejected" can be enforced at decode time with the standard library in CPython and Go, but in Node it needs a duplicate-detecting reader over the raw buffer. A row that says reject at the parser is untestable in Node; a row that says reject somewhere does not distinguish a checker that rejects before the loss from one that rejects after it, where rejection is no longer possible on the original value.
Split the row:
duplicate_present(the bytes contain two members with the same name) versusduplicate_rejected_at_decode(the checker rejected before the object existed). The first is a property of the input; the second is a property of the implementation.
2. A trailing ? survives some rebuilds and not others
https://x/v1/data and https://x/v1/data? are different byte strings and, under a verbatim rule, different identities. Whether a checker can still see the difference depends on whether it hashes the received text or a re-serialized URL:
node: new URL("https://x/v1/data?") .href -> "https://x/v1/data?" // ? kept .search -> "" // indistinguishable from no query .origin + .pathname + .search -> "https://x/v1/data" // ? dropped python: urlsplit("https://x/v1/data?").geturl() -> "https://x/v1/data" // ? dropped go: url.Parse("https://x/v1/data?") .ForceQuery true, .String() -> "https://x/v1/data?" // ? kept Three languages, three behaviors, one document. A signer that hashes the literal bytes and a checker that hashes origin + pathname + search will disagree on exactly this input, silently, because both see an empty query. The practical rule that falls out: the digest must be taken over the received buffer, not over any re-serialization of it.
3. null, "" and a missing name are three cases, and a typed decoder collapses two of them
This is the case where the choice of decode target, not the JSON document, decides the answer. With Go's typed decoder, an explicit null is not an error — it is a silent zero value:
type S struct{ URL string `json:"url"` } {"url":null} -> URL == "", err == nil {"url":42} -> URL == "", err == json: cannot unmarshal number into Go struct field S.url of type string {"url":""} -> URL == "", err == nil type P struct{ URL *string `json:"url"` } {"url":null} -> URL == nil {"url":""} -> URL points at "" A checker that validates after decoding into string therefore cannot tell an unset variable from an explicit empty string — the information was destroyed by the decoder, not by the document. With a pointer the two are distinguishable, but an absent name also decodes to nil, so absent and null collapse instead. To keep all three apart, decode the raw member (json.RawMessage, or a map[string]json.RawMessage) and decide presence before typing.
Node and CPython preserve the distinction throughout: JSON.parse yields null and json.loads yields None, neither equal to "".
A fixture that only says "invalid" cannot distinguish a checker that validates before parse from one that validates after. Those two implementations fail in different places and pass different rows.
4. Re-serialization is not byte-stable across languages
Even with no duplicate names and no null, a rebuild changes bytes because map iteration does not:
input: {"b":1,"a":2} Go json.Marshal(map[string]any{...}) -> {"a":2,"b":1} // keys sorted Node JSON.stringify(JSON.parse(input)) -> {"b":1,"a":2} // insertion order Python json.dumps(json.loads(input)) -> {"b":1,"a":2} // insertion order Same document, two byte strings. This is the reason to publish canonical_bytes alongside a digest: "same hash" then means the same bytes, not the same value under one runtime's serializer.
What to pin in a fixture
- Which bytes are hashed — the received buffer, or a re-serialization. If the latter, the row must name the serializer and its order.
- Where validation runs — before the lossy parse, or after it. A duplicate-name row and a
null-vs-""row each test a different side of that line. - The decode target — typed string, pointer, or raw member. The same document can pass one and fail the next.
- Whether absent, null, and empty string are one case or three. Most typed decoders make them two; the document has three.
None of this is exotic input. An unset variable that renders as "", a URL rebuilt from a parsed object, a config merged twice — each produces exactly the documents above. The question is only whether the verifier hashed what arrived or what its parser left of it.
Originally published at minia2a.uk.