Skip to content

Commit

Permalink
Fail DecodeHash on \r or \n in base64 data
Browse files Browse the repository at this point in the history
Return ErrInvalidHash on any.
  • Loading branch information
scop committed Nov 13, 2023
1 parent ef1a6e0 commit 587f314
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions argon2id.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ func DecodeHash(hash string) (params *Params, salt, key []byte, err error) {
if err != nil {
return nil, nil, nil, err
}
if bytes.ContainsAny(rest, "\r\n") { // base64 decoder ignores these
return nil, nil, nil, ErrInvalidHash
}

var i int
if i = bytes.IndexByte(rest, '$'); i == -1 {
Expand Down
6 changes: 6 additions & 0 deletions argon2id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func TestDecodeHash(t *testing.T) {
t.Fatalf("trailing %s value junk should fail decode", c)
}
}

i := strings.LastIndex(bugHash, "$")
_, _, _, err = DecodeHash(bugHash[:i] + "\r$\n" + bugHash[i+1:])
if err == nil {
t.Fatalf(`\r and \n in base64 data should fail decode`)
}
}

func TestCheckHash(t *testing.T) {
Expand Down

0 comments on commit 587f314

Please sign in to comment.