Skip to content

Commit

Permalink
Using jwt's native ErrInvalidType instead of `json.UnsupportedTypeE…
Browse files Browse the repository at this point in the history
…rror` (#316)

Previously, when parsing claim values, we used `json.UnsupportedTypeError` to denote if a claim string value is not of the correct type. However, this could lead to panics if a nil value is present and the `Error` function of the `json.UnsupportedTypeError` is called, which does not check for nil types.

Instead, we just now use `ErrInvalidType` similar to the map claims.

Fixes #315
  • Loading branch information
oxisto committed Jun 9, 2023
1 parent 5e00fbc commit 0da1691
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"math"
"reflect"
"strconv"
"time"
)
Expand Down Expand Up @@ -121,14 +120,14 @@ func (s *ClaimStrings) UnmarshalJSON(data []byte) (err error) {
for _, vv := range v {
vs, ok := vv.(string)
if !ok {
return &json.UnsupportedTypeError{Type: reflect.TypeOf(vv)}
return ErrInvalidType
}
aud = append(aud, vs)
}
case nil:
return nil
default:
return &json.UnsupportedTypeError{Type: reflect.TypeOf(v)}
return ErrInvalidType
}

*s = aud
Expand Down

0 comments on commit 0da1691

Please sign in to comment.