scanner: reject duplicate BIP21 parameter keys (#63) - #151
Tyagiquamar wants to merge 3 commits 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:
…ncatenated URIs (synonymdev#63) Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
|
Thank you for the detailed review and reference links. All three items have been addressed in commit \27b3d92:
All 28 scanner unit tests pass cleanly in Docker. |
pwltr
left a comment
There was a problem hiding this comment.
The original three findings are addressed, but two BIP 321 compliance issues remain:
-
popandreq-popare treated as separate singleton keys. TheHashSettracks their literal names independently, so?pop=callback1&req-pop=callback2succeeds. BIP 321 treats these as the same proof-of-payment field and explicitly lists that combination as invalid. Please map both names to one canonical singleton identity and add the specification's mixed-key example as a regression test. -
Rejecting every additional
?rejects valid query data.query.contains('?')rejects inputs such as?message=Why?. BIP 321 definesqcharusing the RFC 3986 query grammar, excluding only=and&; RFC 3986 explicitly permits?as data inside the query component. The embedded-secondary-bitcoin:check already catches the issue #63 payload without this blanket restriction.
I reproduced both cases with focused tests against commit 27b3d92; both failed. The existing 28 scanner tests pass locally, including the exact #63 regression, and the updated scanner files pass rustfmt --check.
References:
…mark query data (synonymdev#63) Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
|
Thank you for the follow-up review and exact references. Both remaining BIP 321 compliance findings have been addressed in commit
Test & Check Results:
|
pwltr
left a comment
There was a problem hiding this comment.
No remaining findings. Approved.
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