From 19e1e3f55366acd10a7a6de498a14cbccbcdd9b5 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 3 Oct 2024 23:08:08 +0200 Subject: [PATCH] fix(crypto/ledger): Improve error message when deriving paths (backport #22116) (#22117) Co-authored-by: Ezequiel Raynaudo Co-authored-by: Julien Robert --- CHANGELOG.md | 1 + crypto/ledger/ledger_secp256k1.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b91d5e05e..987a341302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (runtime) [#21704](https://github.com/cosmos/cosmos-sdk/pull/21704) Move `upgradetypes.StoreLoader` to runtime and alias it in upgrade for backward compatibility. * (sims)[#21613](https://github.com/cosmos/cosmos-sdk/pull/21613) Add sims2 framework and factory methods for simpler message factories in modules * (modules) [#21963](https://github.com/cosmos/cosmos-sdk/pull/21963) Duplicatable metrics are no more collected in modules. They were unecessary overhead. +* (crypto/ledger) [#22116](https://github.com/cosmos/cosmos-sdk/pull/22116) Improve error message when deriving paths using index >100 ### Bug Fixes diff --git a/crypto/ledger/ledger_secp256k1.go b/crypto/ledger/ledger_secp256k1.go index 67dcc73981..3449d0bfd1 100644 --- a/crypto/ledger/ledger_secp256k1.go +++ b/crypto/ledger/ledger_secp256k1.go @@ -341,6 +341,12 @@ func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (types.PubKey, error func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (types.PubKey, string, error) { publicKey, addr, err := device.GetAddressPubKeySECP256K1(path.DerivationPath(), hrp) if err != nil { + // Check special case if user is trying to use an index > 100 + if path.AddressIndex > 100 { + return nil, "", fmt.Errorf("%w: cannot derive paths where index > 100: %s "+ + "This is a security measure to avoid very hard to find derivation paths introduced by a possible attacker. "+ + "You can disable this by setting expert mode in your ledger device. Do this at your own risk", err, path) + } return nil, "", fmt.Errorf("%w: address rejected for path %s", err, path) }