Skip to content

Commit

Permalink
identity: Fix potential infinite recursion in server change detection
Browse files Browse the repository at this point in the history
Fixes #6986
  • Loading branch information
bep committed Feb 29, 2020
1 parent b0d8503 commit 6f48146
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ func NewPathIdentity(typ, pat string) PathIdentity {
// Identities stores identity providers.
type Identities map[Identity]Provider

func (ids Identities) search(id Identity) Provider {
if v, found := ids[id]; found {
func (ids Identities) search(depth int, id Identity) Provider {

if v, found := ids[id.GetIdentity()]; found {
return v
}

depth++

// There may be infinite recursion in templates.
if depth > 100 {
// Bail out.
return nil
}

for _, v := range ids {
switch t := v.(type) {
case IdentitiesProvider:
if nested := t.GetIdentities().search(id); nested != nil {
if nested := t.GetIdentities().search(depth, id); nested != nil {
return nested
}
}
Expand Down Expand Up @@ -127,5 +137,5 @@ func (im *identityManager) GetIdentities() Identities {
func (im *identityManager) Search(id Identity) Provider {
im.Lock()
defer im.Unlock()
return im.ids.search(id.GetIdentity())
return im.ids.search(0, id.GetIdentity())
}

0 comments on commit 6f48146

Please sign in to comment.