Skip to content

Commit

Permalink
Add nil guard for claimDest slice
Browse files Browse the repository at this point in the history
  • Loading branch information
osamingo committed Sep 1, 2022
1 parent d482642 commit 47c3cdf
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (v *Validator) ValidateToken(ctx context.Context, tokenString string) (inte
}

claimDest := []interface{}{&jwt.Claims{}}
if v.customClaims != nil {
if v.customClaims != nil && v.customClaims() != nil {
claimDest = append(claimDest, v.customClaims())
}

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

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

0 comments on commit 47c3cdf

Please sign in to comment.