fix(signer): match BIP32 origin via matches, not string prefix#81
Open
evanlinjin wants to merge 1 commit into
Open
fix(signer): match BIP32 origin via matches, not string prefix#81evanlinjin wants to merge 1 commit into
matches, not string prefix#81evanlinjin wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #81 +/- ##
==========================================
+ Coverage 54.01% 54.64% +0.63%
==========================================
Files 12 12
Lines 1620 1625 +5
Branches 62 61 -1
==========================================
+ Hits 875 888 +13
+ Misses 716 712 -4
+ Partials 29 25 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
3e7e399 to
58fa5e5
Compare
`get_key` decided whether a key origin covered a `KeyRequest::Bip32` derivation by stringifying both paths and using `starts_with`. Since `DerivationPath` renders components as `/`-joined decimals, this matched on character boundaries rather than components: `m/1` spuriously matched `m/10`, and an unhardened origin matched its hardened sibling. The signer could then return a private key for a derivation the descriptor never meant to expose. Delegate the check to miniscript's `DescriptorXKey::matches`, which confirms the key actually represents the request (handling the key origin and wildcard), then strip the origin prefix and derive the remainder. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
58fa5e5 to
d696e79
Compare
matches, not string prefix
2 tasks
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.
Description
Signer::get_keydecided whether a key origin(fingerprint, path)covered aKeyRequest::Bip32derivation by stringifying both paths and usingstarts_with:Because
DerivationPathrenders itsChildNumbercomponents as/-joined decimals, this matched on character boundaries rather than path components. That produces false positives whenever the origin's stringified form is a substring of the request's:m/1vs requestm/10("10".starts_with("1"))m/84'/1'/0'/1vs requestm/84'/1'/0'/10.../0vs hardened request.../0'When a spurious match fires and the two paths share a component count,
skip(path.len())leaves an emptyto_derive, so the signer returns the private key at the origin path while claiming to satisfy an unrelated request — leaking a key the descriptor was never meant to expose.This PR delegates the origin/derivation matching to miniscript's
DescriptorXKey::matches, which confirms the key actually represents the request (accounting for the key origin and wildcard) instead of doing a raw prefix check. On a match it strips the origin prefix and derives the remainder from the xkey.Notes to the reviewers
matchesperforms an equality check (modulo the wildcard), so it is stricter than the previous prefix logic: it rejects requests that share the origin as a prefix but fall outside what the descriptor declares (e.g. the account-level key itself, or a sibling of the wildcard branch). This is the intended behavior.Tests:
get_key_bip32_string_prefix_not_path_prefix— originm/84'/1'/0'/1, requestm/84'/1'/0'/10: old code returnsSome(key at origin), fixed code returnsNone.get_key_bip32_rejects_paths_outside_descriptor— confirms a request equal to the origin and a sibling of the wildcard branch both returnNone.Original bug reported via
llm-code-review(CWE-697). Discovered by Project Loupe.Follow-up: remove
Signeronce upstream is fixedSigneronly exists because miniscript's ownGetKeyfor key maps mis-derives BIP32 requests for descriptors that carry key-origin info (theKeyMapWrapperin 12.3.x derives the full path without stripping the origin; 13.0.0 strips the wrong amount). The upstream fix is rust-miniscript#872, which is not yet released. Once it ships in a release we can bump our minimum minor version ofminiscriptto, we should dropbdk_tx::Signerentirely and use miniscript'sGetKeyimpl directly.Changelog notice
Fixed:
Signermatched a BIP32 key origin against a derivation request by string prefix instead of path-component prefix, which could cause it to return a private key for an unrelated derivation path.Before submitting
🤖 Generated with Claude Code