Skip to content

Commit

Permalink
fix: never construct id token claim templates in parallel (#552)
Browse files Browse the repository at this point in the history
Closes #551
  • Loading branch information
AlbinoDrought authored Oct 11, 2020
1 parent dbe1987 commit 4f504d9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pipeline/mutate/mutator_id_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"fmt"
"net/http"
"net/url"
"sync"
"text/template"
"time"

Expand All @@ -49,9 +50,10 @@ type MutatorIDTokenRegistry interface {
}

type MutatorIDToken struct {
c configuration.Provider
r MutatorIDTokenRegistry
templates *template.Template
c configuration.Provider
r MutatorIDTokenRegistry
templates *template.Template
templatesLock sync.Mutex

tokenCache *ristretto.Cache
tokenCacheEnabled bool
Expand Down Expand Up @@ -152,7 +154,9 @@ func (a *MutatorIDToken) Mutate(r *http.Request, session *authn.AuthenticationSe
t := a.templates.Lookup(c.ClaimsTemplateID())
if t == nil {
var err error
a.templatesLock.Lock()
t, err = a.templates.New(c.ClaimsTemplateID()).Parse(c.Claims)
a.templatesLock.Unlock()
if err != nil {
return errors.Wrapf(err, `error parsing claims template in rule "%s"`, rl.GetID())
}
Expand Down

0 comments on commit 4f504d9

Please sign in to comment.