Skip to content

Commit

Permalink
Merge pull request #221 from d-hat/CVE-2020-35381
Browse files Browse the repository at this point in the history
Attempt to fix #219 and introduce a test.  The only error that can easily be returned in this case is `KeyPathNotFoundError`, which is reasonable if you squint (a malformed key can not be found).

Note I'm far from fluent in golang so this should be reviewed with some care 😄
  • Loading branch information
buger authored Jan 8, 2021
2 parents e015c37 + 1e1db9e commit df3ea76
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ func searchKeys(data []byte, keys ...string) int {
case '[':
// If we want to get array element by index
if keyLevel == level && keys[level][0] == '[' {
aIdx, err := strconv.Atoi(keys[level][1 : len(keys[level])-1])
var keyLen = len(keys[level])
if keyLen < 3 || keys[level][0] != '[' || keys[level][keyLen-1] != ']' {
return -1
}
aIdx, err := strconv.Atoi(keys[level][1 : keyLen-1])
if err != nil {
return -1
}
Expand Down
12 changes: 12 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,18 @@ var getStringTests = []GetTest{
path: []string{"c"},
isErr: true,
},
{
desc: `empty array index`,
json: `[""]`,
path: []string{"[]"},
isFound: false,
},
{
desc: `malformed array index`,
json: `[""]`,
path: []string{"["},
isFound: false,
},
}

var getUnsafeStringTests = []GetTest{
Expand Down

0 comments on commit df3ea76

Please sign in to comment.