Refuse claims at too-short derivation paths
What changed, and why it matters
This update hardens a Bitcoin signing device (SeedSigner) against trick transactions. Previously, a malicious or broken PSBT file could claim that the user's master key or an unusually short key path should be used to sign a payment. The device would have accepted that path and could have signed something the user did not expect. Now the software rejects such PSBTs with a clear warning and discards the transaction. The change is defensive: it does not fix a known theft, but it closes a risky edge case where the wrong key could be used.
Treat this as a security hardening patch and include it in the next release. Users building from source should update to a revision that includes this commit. No immediate incident response is required unless an older device is known to have signed an unexpected master-key or one-level-path transaction.
Security signals we found
New validation exception for unsupported derivation paths
Rejects master-key (empty path) claims on inputs and outputs
Rejects one-level derivation path claims on inputs
Held-finding precedence preserves reporting of forged ownership claims
UI blocks continuation and only allows discarding the transaction
Test cases demonstrate embit would sign master-key input before this patch
Evidence from the diff
The commit adds PSBTUnsupportedDerivationPathError and rejects derivation-path claims that are too short for normal wallet use: the empty path (master key, m/) on any input or output, and a one-level path (e.g., m/5) on an input. The check is performed after the per-scope claim loops, so a forged/stranger claim in the same scope is still reported as the more serious ownership-claim error. The parser catches the new exception, holds it as a held finding, and the UI redirects to a new warning screen that only allows discarding the PSBT. Tests cover master-key claims on inputs and outputs, one-level input claims, and precedence of forged claims.
Changed components
src/seedsigner/models/psbt_parser.pysrc/seedsigner/views/psbt_views.pytests/test_psbt_parser.pytests/test_flows_psbt.pytests/screenshot_generator/generator.pyInspect captured patch +186 / −9
### src/seedsigner/models/psbt_parser.py
@@ -190,6 +190,20 @@ class PSBTExtraneousInputScriptError(PSBTVerificationError):
pass
+class PSBTUnsupportedDerivationPathError(PSBTVerificationError):
+ """
+ An input or output claims one of this seed's keys at a derivation path too short for
+ any wallet to use:
+ * the empty path, which is the master key itself. That key is a derivation root
+ rather than a key any wallet spends from or receives at.
+ * on an input, a path of one level, too short to hold both a branch and an
+ address index.
+
+ We don't try to decide whether this is an attack or a mistake.
+ """
+ pass
+
+
class PSBTUnsupportedScriptPathError(PSBTVerificationError):
"""
This seed can sign an input only through a taproot script path spend, because the
@@ -397,6 +411,8 @@ def parse(self):
These findings are held:
* a false claim on an input.
* an input or output with entries in both derivation path maps.
+ * an input or output claiming one of our keys at a derivation path too short
+ for any wallet to use.
* an output claiming more derivation path entries than it can use.
* an input that this seed can sign only through a taproot script path spend.
@@ -578,7 +594,7 @@ def _parse_inputs(self, child_key_derivation_cache: dict):
# Verify every entry on this input that claims our fingerprint
try:
verified_derivation_paths = PSBTParser._get_seed_derivation_paths(inp, self.root, child_key_derivation_cache)
- except (PSBTInputOwnershipClaimError, PSBTMixedDerivationPathTypesError) as e:
+ except (PSBTInputOwnershipClaimError, PSBTMixedDerivationPathTypesError, PSBTUnsupportedDerivationPathError) as e:
# Held rather than raised (see parse()), and this input is treated as
# not ours.
self.held_findings.append(e)
@@ -1603,9 +1619,12 @@ def _get_seed_derivation_paths(scope: InputScope | OutputScope, root: bip32.HDKe
derives from our seed. What those entries mean for the psbt is determined
elsewhere.
- The path itself is still whatever the psbt supplied: it can be any length or
- shape, since any path that derives from the seed will pass. Whether the path is
- one the user's wallet would ever look at is a separate question.
+ The path itself is still whatever the psbt supplied, so a last check refuses one
+ too short for any wallet to use: the empty path, which is the master key itself,
+ and on an input a path of one level. Each raises
+ PSBTUnsupportedDerivationPathError. Any longer path that derives from the seed
+ passes, whatever its shape. Whether the path is one the user's wallet would ever
+ look at is a separate question.
"""
seed_fingerprint = root.my_fingerprint
verified_derivation_paths = []
@@ -1635,6 +1654,20 @@ def _check_claim(public_key: PublicKey, derivation_path_obj: DerivationPath, is_
if scope.bip32_derivations and scope.taproot_bip32_derivations:
raise PSBTMixedDerivationPathTypesError("Scope declares both ecdsa and taproot derivation paths")
+ # Also checked after the loops, for the same reason
+ for verified_derivation_path in verified_derivation_paths:
+ if len(verified_derivation_path.derivation) == 0:
+ # A path with no levels is the master key itself. That key is a derivation
+ # root, never a spending key. No wallet writes an entry at that path. We
+ # refuse the psbt rather than skip the entry, on inputs and outputs alike
+ # (embit would sign an input built on it).
+ raise PSBTUnsupportedDerivationPathError("The psbt claims this seed's master key, which is not a spending key")
+
+ if len(verified_derivation_path.derivation) == 1 and isinstance(scope, InputScope):
+ # A one-level path is too short to hold both a branch and an address
+ # index. No wallet spends from a path that short.
+ raise PSBTUnsupportedDerivationPathError(f"Input claims this seed at {bip32.path_to_str(verified_derivation_path.derivation)}, a path too short for a wallet")
+
return verified_derivation_paths
@@ -1658,7 +1691,7 @@ def _verify_claimed_output_derivation_paths(self, child_key_derivation_cache: di
for i, out in enumerate(self.psbt.outputs):
try:
verified_derivation_paths = PSBTParser._get_seed_derivation_paths(out, self.root, child_key_derivation_cache)
- except PSBTMixedDerivationPathTypesError as e:
+ except (PSBTMixedDerivationPathTypesError, PSBTUnsupportedDerivationPathError) as e:
self._hold_output_finding(i, e)
verified_derivation_paths = []
self.verified_output_derivation_paths.append(verified_derivation_paths)
### src/seedsigner/views/psbt_views.py
@@ -8,7 +8,8 @@
PSBTMalformedOpReturnError, PSBTMissingInputScriptError, PSBTMissingInputUtxoError,
PSBTMixedDerivationPathTypesError, PSBTNegativeFeeError, PSBTOutputOwnershipClaimError,
PSBTOutputOwnershipContradictionError, PSBTParser, PSBTSeedCannotSignError,
- PSBTSurplusDerivationPathsError, PSBTUnsupportedScriptPathError)
+ PSBTSurplusDerivationPathsError, PSBTUnsupportedDerivationPathError,
+ PSBTUnsupportedScriptPathError)
from seedsigner.models.settings import SettingsConstants
from seedsigner.gui.components import FontAwesomeIconConstants, GUIConstants, SeedSignerIconConstants
from seedsigner.gui.screens.screen import (RET_CODE__BACK_BUTTON, ButtonListScreen, ButtonOption, LargeIconStatusScreen, WarningScreen, DireWarningScreen, QRDisplayScreen)
@@ -134,6 +135,10 @@ def __init__(self):
self.set_redirect(Destination(PSBTMalformedOpReturnView, clear_history=True))
return
+ except PSBTUnsupportedDerivationPathError:
+ self.set_redirect(Destination(PSBTUnsupportedDerivationPathView, clear_history=True))
+ return
+
except PSBTMissingInputScriptError:
self.set_redirect(Destination(PSBTMissingInputScriptView, clear_history=True))
return
@@ -447,8 +452,7 @@ def run(self):
verified_derivation_path = change_data.get("verified_derivation_path")
is_change_derivation_path = PSBTParser.is_change_branch(verified_derivation_path)
- # TODO: Refuse a path too short to carry a branch and an address index; until then
- # this can raise on a malformed psbt.
+ # TODO: Refuse a path too short to carry a branch and an address index
derivation_path_addr_index = verified_derivation_path[-1]
if is_change_derivation_path:
@@ -698,6 +702,36 @@ def run(self):
+class PSBTUnsupportedDerivationPathView(View):
+ """
+ Reached when a psbt claims one of this seed's keys at a derivation path too short for
+ any wallet to use, such as the seed's master key itself (see
+ PSBTUnsupportedDerivationPathError).
+
+ We do not try to decide whether this is an attack or a mistake; no standard wallet
+ writes a claim at a path that short either way. We do not allow the user to continue,
+ but only give this the "Warning" level.
+ """
+ DISCARD = ButtonOption("Discard transaction")
+
+ def run(self):
+ self.run_screen(
+ WarningScreen,
+ title=_("Transaction Problem"),
+ status_headline=None,
+ # TRANSLATOR_NOTE: The transaction/psbt has an error but does not seem to be malicious.
+ text=_("This transaction uses a key of yours that this device will not sign with."),
+ button_data=[self.DISCARD],
+ show_back_button=False,
+ )
+
+ # We're done with this PSBT. Route back to MainMenuView, which clears all
+ # ephemeral data (except in-memory seeds).
+ # Set clear_history to disable returning via BACK button.
+ return Destination(MainMenuView, clear_history=True)
+
+
+
class PSBTOutputOwnershipContradictionView(View):
"""
Reached when the psbt's account of who an output pays contradicts the script that
### tests/screenshot_generator/generator.py
@@ -454,6 +454,7 @@ def mock_version_to_most_recent_release():
ScreenshotConfig(psbt_views.PSBTSurplusDerivationPathsView),
ScreenshotConfig(psbt_views.PSBTMixedDerivationPathTypesView),
ScreenshotConfig(psbt_views.PSBTMalformedOpReturnView),
+ ScreenshotConfig(psbt_views.PSBTUnsupportedDerivationPathView),
ScreenshotConfig(psbt_views.PSBTOutputOwnershipContradictionView),
ScreenshotConfig(psbt_views.PSBTInputOwnershipContradictionView),
ScreenshotConfig(psbt_views.PSBTMissingInputScriptView),
### tests/test_flows_psbt.py
@@ -397,6 +397,27 @@ def test_malformed_op_return_terminates_signing_flow(self):
])
+ def test_master_key_claim_terminates_signing_flow(self):
+ """
+ The psbt claims this seed on an output at a derivation path with no levels, which
+ is the seed's master key. That key is a derivation root rather than one any wallet
+ receives at. No standard wallet writes an entry at that path.
+
+ It ends the flow at its own warning before any transaction detail is rendered.
+ """
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", root_for_seed(PSBTTestData.seed).get_public_key())
+
+ self._load_psbt_for_signing(psbt)
+
+ self.run_sequence([
+ FlowStep(psbt_views.PSBTSelectSeedView, screen_return_value=0),
+ FlowStep(psbt_views.PSBTOverviewView, is_redirect=True),
+ FlowStep(psbt_views.PSBTUnsupportedDerivationPathView, button_data_selection=psbt_views.PSBTUnsupportedDerivationPathView.DISCARD),
+ FlowStep(MainMenuView),
+ ])
+
+
def test_missing_input_script_terminates_signing_flow(self):
"""
The psbt leaves out the witness script that a p2wsh input commits to.
### tests/test_psbt_parser.py
@@ -18,7 +18,8 @@
PSBTMalformedOpReturnError, PSBTMissingInputScriptError, PSBTMissingInputUtxoError,
PSBTMixedDerivationPathTypesError, PSBTNegativeFeeError, PSBTOutputOwnershipClaimError,
PSBTOutputOwnershipContradictionError, PSBTParser, PSBTSeedCannotSignError,
- PSBTSurplusDerivationPathsError, PSBTUnsupportedScriptPathError)
+ PSBTSurplusDerivationPathsError, PSBTUnsupportedDerivationPathError,
+ PSBTUnsupportedScriptPathError)
from seedsigner.models.seed import Seed
from seedsigner.models.settings_definition import SettingsConstants
@@ -1415,8 +1416,10 @@ def test__parse__held_findings_wait_for_an_output_contradiction(self):
PSBTOutputOwnershipContradictionError:
* p2wpkh input: a throwaway false claim
* p2wpkh input: entries in both derivation path maps
+ * p2wpkh input: a claim on this seed's master key
* p2tr input: our only key in a script tree leaf
* p2wpkh output: entries in both derivation path maps
+ * p2wpkh output: a claim on this seed's master key
* p2wpkh output: more derivation path entries than it can use
* p2tr output: more than one internal key claim
* p2wsh output: more derivation path entries than its script has keys
@@ -1465,6 +1468,13 @@ def claim_a_stranger_on_the_change(psbt: PSBT):
with pytest.raises(PSBTOutputOwnershipContradictionError):
self._parse(psbt)
+ # p2wpkh input: a claim on this seed's master key
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.inputs[0], "m", self._root().get_public_key())
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
# p2tr input: our only key in a script tree leaf
leaf_derivation_path = "m/86h/1h/0h/0/0"
leaf_public_key = self._root().derive(leaf_derivation_path).get_public_key()
@@ -1490,6 +1500,15 @@ def claim_a_stranger_on_the_change(psbt: PSBT):
with pytest.raises(PSBTOutputOwnershipContradictionError):
self._parse(psbt)
+ # p2wpkh output: a claim on this seed's master key
+ psbt = self._psbt_with_change()
+ other_output = create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_CHANGE, 10_000)
+ claim_seed_owns_key(other_output, "m", self._root().get_public_key())
+ psbt.outputs.insert(0, other_output)
+ claim_a_stranger_on_the_change(psbt)
+ with pytest.raises(PSBTOutputOwnershipContradictionError):
+ self._parse(psbt)
+
# p2wpkh output: more derivation path entries than it can use
psbt = self._psbt_with_change()
other_output = create_output(PSBTTestData.SINGLE_SIG_NATIVE_SEGWIT_CHANGE, 10_000)
@@ -1748,6 +1767,75 @@ def test__parse__accepts_a_cosigner_seed_on_a_multisig(self):
assert psbt_parser.verified_input_derivation_paths[0] != []
+ def test__parse__refuses_a_claim_at_a_derivation_path_too_short_for_a_wallet(self):
+ """
+ A derivation path entry with no levels at all points at the seed's master key.
+ That key is a derivation root, not one any wallet spends from or receives at. No
+ wallet writes an entry at that path, though embit would sign an input built on it
+ anyway. A path of one level is too short to hold both a branch and an address
+ index. No wallet spends from a path that short either.
+
+ So the parse should refuse the psbt with PSBTUnsupportedDerivationPathError:
+ * an input claiming the master key
+ * an output claiming the master key
+ * an input claiming a key at a one-level path
+
+ A forged claim should report as PSBTOutputOwnershipClaimError instead, whether it
+ is at the empty path itself or listed after a true claim on the master key.
+ """
+ root = self._root()
+ master_public_key = root.get_public_key()
+ one_level_public_key = root.derive("m/5").get_public_key()
+
+ # input: claim the master key, on an input that the master key really does
+ # control
+ psbt = self._psbt_with_change()
+ psbt.inputs[0].bip32_derivations.clear()
+ psbt.inputs[0].witness_utxo.script_pubkey = script.p2wpkh(master_public_key)
+ # Drop the non_witness_utxo, which describes the original coin and contradicts
+ # the witness_utxo altered above.
+ psbt.inputs[0].non_witness_utxo = None
+ claim_seed_owns_key(psbt.inputs[0], "m", master_public_key)
+
+ # embit is willing to sign it
+ assert deepcopy(psbt).sign_with(root) > 0
+
+ with pytest.raises(PSBTUnsupportedDerivationPathError):
+ self._parse(psbt)
+
+ # output: claim the master key, with the input left honest
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", master_public_key)
+ with pytest.raises(PSBTUnsupportedDerivationPathError):
+ self._parse(psbt)
+
+ # input: claim a key at a one-level path, on an input that key really does
+ # control
+ psbt = self._psbt_with_change()
+ psbt.inputs[0].bip32_derivations.clear()
+ psbt.inputs[0].witness_utxo.script_pubkey = script.p2wpkh(one_level_public_key)
+ # Drop the non_witness_utxo, which describes the original coin and contradicts
+ # the witness_utxo altered above.
+ psbt.inputs[0].non_witness_utxo = None
+ claim_seed_owns_key(psbt.inputs[0], "m/5", one_level_public_key)
+ with pytest.raises(PSBTUnsupportedDerivationPathError):
+ self._parse(psbt)
+
+ # output: claim the master key over someone else's key. The forged claim is the
+ # more serious finding, so that is the one reported.
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", foreign_public_key())
+ with pytest.raises(PSBTOutputOwnershipClaimError):
+ self._parse(psbt)
+
+ # output: a true claim on the master key, then a forged claim listed after it
+ psbt = self._psbt_with_change()
+ claim_seed_owns_key(psbt.outputs[0], "m", master_public_key)
+ claim_seed_owns_key(psbt.outputs[0], "m/84h/1h/0h/1/9", foreign_public_key())
+ with pytest.raises(PSBTOutputOwnershipClaimError):
+ self._parse(psbt)
+
+
def test_a_psbt_with_no_utxos_is_rejected_rather_than_crashing(self):
"""
The psbt's inputs leave out the utxos they spend, so the psbt is malformed andWhy this scored 66/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.