Skip to content

Commit

Permalink
filters/auth: reduce allocations for tokeninfo claims check
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Yastrebov <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov committed Dec 12, 2023
1 parent 5f706e5 commit 3ffc37a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions filters/auth/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,12 @@ func (f *tokenOidcFilter) validateAnyClaims(h map[string]interface{}) bool {
return false
}

keys := make([]string, 0, len(h))
for k := range h {
keys = append(keys, k)
for _, c := range f.claims {
if _, ok := h[c]; ok {
return true
}
}

return intersect(f.claims, keys)
return false
}

func (f *tokenOidcFilter) validateAllClaims(h map[string]interface{}) bool {
Expand All @@ -346,11 +346,12 @@ func (f *tokenOidcFilter) validateAllClaims(h map[string]interface{}) bool {
return false
}

keys := make([]string, 0, len(h))
for k := range h {
keys = append(keys, k)
for _, c := range f.claims {
if _, ok := h[c]; !ok {
return false
}
}
return all(f.claims, keys)
return true
}

type OauthState struct {
Expand Down

0 comments on commit 3ffc37a

Please sign in to comment.