Skip to content

Commit

Permalink
Fix relative path validation regex in validateRelativePath
Browse files Browse the repository at this point in the history
  • Loading branch information
moshe-blox committed Jan 21, 2024
1 parent 9ccffcf commit e8475ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/hd_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion core/master_derivable_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit e8475ad

Please sign in to comment.