Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HdonCr/Allow multiple audiences #427

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

hdonCr
Copy link

@hdonCr hdonCr commented Dec 24, 2024

Allow for multiple expected audiences as requested in issue 342.

@oxisto
Copy link
Collaborator

oxisto commented Dec 24, 2024

Hi! Looks like we have two PRs now for the same issue :) I will take some time after the holidays with @mfridman to see which direction we will follow.

@@ -55,6 +55,13 @@ type Validator struct {
// string will disable aud checking.
expectedAud string

//expectedAuds contains the audiences this token expects. Supplying an empty
// []string will disable auds checking.
expectedAuds []string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we could merge this with the expectedAud above

expectedAuds []string

// expectedAudsMatchAll specifies whether all expected audiences must match all auds from claim
expectedAudsMatchAll bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a name like matchAllAud

@@ -126,6 +133,13 @@ func (v *Validator) Validate(claims Claims) error {
}
}

// If we have expected audiences, we also require the audiences claim
if len(v.expectedAuds) != 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be > 0 just to be safe

//
// Additionally, if any error occurs while retrieving the claim, e.g., when its
// the wrong type, an ErrTokenUnverifiable error will be returned.
func (v *Validator) verifyAudiences(claims Claims, cmps []string, required bool, matchAllAuds bool) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems to be very complex, I wonder if we could streamline this implementation a little bit. Furthermore, it should be possible to include the previous implementation of verifyAudience in this as well - or rather merge the two since one is just a special case of the other.

for _, a := range aud {

// Perform constant time comparison
result := subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quite a large duplicate code fragment, this is essentially what the existing verifyAudience does. why not use it?

for _, cmp := range cmps {

// Perform constant time comparison
result := subtle.ConstantTimeCompare([]byte(a), []byte(cmp)) != 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants