Repository navigation
Encode literal + and match keys case-insensitively - #13
Closed
caarloshenriq wants to merge 1 commit into
Closed
caarloshenriq wants to merge 1 commit into
caarloshenriq wants to merge 1 commit into
Conversation
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.
14 tasks done
Member
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.
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