From e8475adda6a7df9174acb266300d63cf91ea4004 Mon Sep 17 00:00:00 2001 From: moshe-blox Date: Sun, 21 Jan 2024 11:54:37 +0200 Subject: [PATCH] Fix relative path validation regex in `validateRelativePath` --- core/hd_key_test.go | 7 +++++++ core/master_derivable_key.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/hd_key_test.go b/core/hd_key_test.go index 2bb896cf..d1479b21 100644 --- a/core/hd_key_test.go +++ b/core/hd_key_test.go @@ -220,6 +220,13 @@ func TestDerivableKeyRelativePathDerivation(t *testing.T) { err: errors.New("invalid relative path. Example: /1/2/3"), expectedKey: nil, }, + { + name: "bad path (too short 2)", + seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"), + path: "/0/9/", // after basePath + err: errors.New("invalid relative path. Example: /1/2/3"), + expectedKey: nil, + }, { name: "not a relative path", seed: _byteArray("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1fff"), diff --git a/core/master_derivable_key.go b/core/master_derivable_key.go index a2ffe9c6..fc20290c 100644 --- a/core/master_derivable_key.go +++ b/core/master_derivable_key.go @@ -88,6 +88,6 @@ func (master *MasterDerivableKey) Derive(relativePath string) (*HDKey, error) { } func validateRelativePath(relativePath string) bool { - match, _ := regexp.MatchString(`^\/\d+\/\d+\/?\d*$`, relativePath) + match, _ := regexp.MatchString(`^\/\d+(\/\d+)(\/\d+)?$`, relativePath) return match }