scanner: reject duplicate BIP21 parameter keys (#63) - #151
Tyagiquamar wants to merge 1 commit into
Conversation
|
Hi, friendly ping for review on this PR when you have a moment. Happy to address any feedback. Thanks! |
|
Hi, just following up on this when you get a chance. The branch is up to date and checks are green. If it looks good from your side, it should be ready to merge. Happy to make any changes if needed. Thanks! |
There was a problem hiding this comment.
Requesting changes for three issues:
-
The test suite will not compile as written.
test_invalid_lightning_invoice_syncis synchronous but still uses#[tokio::test], whose target must be anasync fn. Please either restoreasyncor change the attribute to#[test]. -
This does not reproduce or fix #63. The issue input contains two concatenated
bitcoin:URIs and therefore two?characters.decode_onchainstill splits on every?and parses onlyparts[1], silently discardingparts[2]. The duplicate-key loop never sees the second URI. Please add the exact payload from #63 as a regression test and preserve/validate the complete query, for example by usingsplit_once('?')before rejecting the embedded secondbitcoin:URI.
This distinction is confirmed by both consumer apps. Android and iOS added matching January 19 workarounds that detect a second bitcoin: prefix in their scan and manual-entry paths, explicitly referencing bitkit-core#63. Those workarounds would still be required after this PR.
- Rejecting every repeated query key is too broad. BIP 21 does not state that all duplicate keys are invalid, and its replacement BIP 321 explicitly permits repeated payment-instruction keys and requires accepting repeated unknown keys. Singleton fields such as
amount,label,message, andpopshould reject duplicates, but this needs a per-key policy rather than blanketHashMaprejection. BIP 321 also treats query keys as case-insensitive.
Relevant references:
In src/modules/scanner/implementation.rs, decode_onchain() parsed BIP21 URI parameters by collecting them directly into a HashMap<String, String>.
Per BIP-0021 specification, duplicate parameter keys in a URI make the URI invalid. Collecting into a HashMap directly silently dropped earlier duplicate keys, overwriting them with the last key-value pair.
This PR updates query parameter parsing to check for duplicate keys, returning DecodingError::InvalidFormat if duplicate parameter keys are present.
Fixes #63
Testing