Skip to content

Commit 47c3cdf

Browse files
committed
Add nil guard for claimDest slice
1 parent d482642 commit 47c3cdf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

validator/validator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (v *Validator) ValidateToken(ctx context.Context, tokenString string) (inte
113113
}
114114

115115
claimDest := []interface{}{&jwt.Claims{}}
116-
if v.customClaims != nil {
116+
if v.customClaims != nil && v.customClaims() != nil {
117117
claimDest = append(claimDest, v.customClaims())
118118
}
119119

@@ -150,7 +150,8 @@ func (v *Validator) ValidateToken(ctx context.Context, tokenString string) (inte
150150
}
151151

152152
if v.customClaims != nil {
153-
validatedClaims.CustomClaims, _ = claimDest[1].(CustomClaims)
153+
// The second argument is not receive because it is guaranteed in L.116.
154+
validatedClaims.CustomClaims = claimDest[1].(CustomClaims)
154155
if err = validatedClaims.CustomClaims.Validate(ctx); err != nil {
155156
return nil, fmt.Errorf("custom claims not validated: %w", err)
156157
}

0 commit comments

Comments
 (0)