From 0da169122f7861093fb3b297ee6d2533199f6762 Mon Sep 17 00:00:00 2001 From: Christian Banse Date: Fri, 9 Jun 2023 14:54:51 +0200 Subject: [PATCH] Using jwt's native `ErrInvalidType` instead of `json.UnsupportedTypeError` (#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 --- types.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/types.go b/types.go index b82b388..b2655a9 100644 --- a/types.go +++ b/types.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "math" - "reflect" "strconv" "time" ) @@ -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