-
Notifications
You must be signed in to change notification settings - Fork 202
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace *jwt.validateClaimsWithLeeway with custom validation func #176
Conversation
+ refactor validator pkg
33c3d1d
to
5cd381b
Compare
req.Header.Set("Authorization", "Bearer "+token) | ||
|
||
rr := httptest.NewRecorder() | ||
|
||
mainHandler := setupHandler(testServer.URL, []string{}) | ||
mainHandler := setupHandler(testServer.URL, []string{"my-audience"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was incorrectly set to validate no audience.
@@ -26,5 +26,5 @@ jobs: | |||
uses: codecov/codecov-action@v3 | |||
with: | |||
files: coverage.out | |||
fail_ci_if_error: true | |||
fail_ci_if_error: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick toggle to not fail the CI build if we fail to upload codecov.
v.signatureAlgorithm, | ||
token.Headers[0].Algorithm, | ||
) | ||
if err = validateSigningMethod(string(v.signatureAlgorithm), token.Headers[0].Algorithm); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to refactor this func so that the steps read better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
馃憦馃徏
foundAudience := false | ||
for _, value := range expectedClaims.Audience { | ||
if actualClaims.Audience.Contains(value) { | ||
foundAudience = true | ||
break | ||
} | ||
} | ||
if !foundAudience { | ||
return jwt.ErrInvalidAudience |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mainly the fix for the multiple audiences described in #148
return validatedClaims, nil | ||
} | ||
|
||
func validateClaimsWithLeeway(actualClaims jwt.Claims, expected jwt.Expected, leeway time.Duration) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this also include the sub and jti validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although that original func does include them, we were never actually using them for the validation. We're only setting as expected the audience, issuer and the time based claims.
Re:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that in other SDKs we do validate the sub claim: https://github.com/auth0/Auth0.swift/blob/master/Auth0/IDTokenValidator.swift#L56
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can add that validation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(if applicable, of course).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we can't introduce that right now without a breaking change. The expectedClaims
are a private internal property inside the validator and we set it with the passed in issuer and audience when constructing the validator. We'll have to change this func https://github.com/auth0/go-jwt-middleware/blob/master/validator/validator.go#L59 to allow for the subject as well. I'll note this down for a potential upcoming v3 perhaps, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just left a comment regarding the sub and jti claims.
馃摑 Checklist
馃敡 Changes
We are replacing the *jwt.validateClaimsWithLeeway func with our own logic to fix the issue with multiple audiences within the 3rd party pkg as it seems we are not getting a new release. This was preferred right now to swapping the jwt library used under the hood as that would be a bigger undertaking that we'll defer for later, perhaps a v3.
馃摎 References
馃敩 Testing