Skip to content

Encode literal + and match keys case-insensitively - #13

Closed
caarloshenriq wants to merge 1 commit into
payjoin:masterfrom
caarloshenriq:fix/plus-encoding-case-insensitive-keys
Closed

caarloshenriq wants to merge 1 commit into
payjoin:masterfrom
caarloshenriq:fix/plus-encoding-case-insensitive-keys

Conversation

@caarloshenriq

Copy link
Copy Markdown

Part of #12

Two independent BIP21 round-trip bugs, both reachable from a wallet scanning an ordinary QR code and both silent (no parse error, no indication anything was lost):

  • Serializing a decoded value that contains a literal '+' wrote it back out unescaped. RFC 3986 permits that, but many BIP21 readers apply the application/x-www-form-urlencoded convention where '+' means space, so a re-emitted URI could hand such a reader a space where the sender wrote a plus. Always percent-encode '+' as %2B on output; this crate never decodes it as a space either way, so nothing about parsing changes.

  • Top-level keys (amount, label, message) and the req- prefix check were matched against the parameter key verbatim. QR codes in alphanumeric mode are uppercase-only, so a wallet scanning '?AMOUNT=1&PJ=...' got a URI that parsed successfully with amount, and every extras parameter, silently dropped. Match case- insensitively instead, and hand the lowercased key to Extras deserialization so an implementation matching a literal lowercase key (payjoin's PayjoinExtras, for example) needs no change of its own to see it. The zero-copy deserialize_borrowed path is kept for the common already-lowercase case; only a key containing an uppercase byte pays for the clone that deserialize_temp needs.

Both are covered by new tests, and neither changes on-the-wire behavior for lowercase input.

Disclosure: co-authored by Claude

Two independent BIP21 round-trip bugs, both reachable from a wallet
scanning an ordinary QR code and both silent (no parse error, no
indication anything was lost):

- Serializing a decoded value that contains a literal '+' wrote it
  back out unescaped. RFC 3986 permits that, but many BIP21 readers
  apply the application/x-www-form-urlencoded convention where '+'
  means space, so a re-emitted URI could hand such a reader a space
  where the sender wrote a plus. Always percent-encode '+' as %2B on
  output; this crate never decodes it as a space either way, so
  nothing about parsing changes.

- Top-level keys (amount, label, message) and the req- prefix check
  were matched against the parameter key verbatim. QR codes in
  alphanumeric mode are uppercase-only, so a wallet scanning
  '?AMOUNT=1&PJ=...' got a URI that parsed successfully with amount,
  and every extras parameter, silently dropped. Match case-
  insensitively instead, and hand the lowercased key to Extras
  deserialization so an implementation matching a literal lowercase
  key (payjoin's PayjoinExtras, for example) needs no change of its
  own to see it. The zero-copy deserialize_borrowed path is kept for
  the common already-lowercase case; only a key containing an
  uppercase byte pays for the clone that deserialize_temp needs.

Both are covered by new tests, and neither changes on-the-wire
behavior for lowercase input.
@DanGould

DanGould commented Oct 8, 2026

Copy link
Copy Markdown
Member

I'd rather include this in #16 straight to 0.2 rather than fix this and release an 0.1.1. If I misunderstood what this attempts, I'm happy to re-open it.

Superseded by #16

@DanGould DanGould closed this Oct 8, 2026
@caarloshenriq
caarloshenriq deleted the fix/plus-encoding-case-insensitive-keys branch October 14, 2026 19:02
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.

2 participants