Skip to content

Commit

Permalink
Validate token_type case-insensitively (#256)
Browse files Browse the repository at this point in the history
* Validate token_type case-insensitive

Signed-off-by: Joseph Petitti <[email protected]>

* Fix indentation

Signed-off-by: Joseph Petitti <[email protected]>

---------

Signed-off-by: Joseph Petitti <[email protected]>
  • Loading branch information
jojonium authored May 13, 2024
1 parent 98a764d commit 0d8008e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/authz/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func performIDPRequest(log telemetry.Logger, client *http.Client, uri string, fo
// https://openid.net/specs/openid-connect-core-1_0.html#TokenResponse
func isValidIDPNewTokensResponse(log telemetry.Logger, config *oidcv1.OIDCConfig, tokenResponse *idpTokensResponse) bool {
// token_type must be Bearer
if tokenResponse.TokenType != "Bearer" {
if !strings.EqualFold(tokenResponse.TokenType, "Bearer") {
log.Info("token type is not Bearer in token response", "token-type", tokenResponse.TokenType)
return false
}
Expand All @@ -553,7 +553,7 @@ func isValidIDPNewTokensResponse(log telemetry.Logger, config *oidcv1.OIDCConfig
// https://openid.net/specs/openid-connect-core-1_0.html#RefreshTokenResponse
func isValidIDPRefreshTokenResponse(log telemetry.Logger, tokenResponse *idpTokensResponse) bool {
// token_type must be Bearer
if tokenResponse.TokenType != "Bearer" {
if !strings.EqualFold(tokenResponse.TokenType, "Bearer") {
log.Info("token type is not Bearer in token response", "token-type", tokenResponse.TokenType)
return false
}
Expand Down
18 changes: 18 additions & 0 deletions internal/authz/oidc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,24 @@ func TestOIDCProcess(t *testing.T) {
requireStoredState(t, store, sessionID, false)
},
},
{
name: "IDP server returns lowercase 'bearer' token, succeeds",
req: withSessionHeader,
storedTokenResponse: expiredTokenResponse,
mockTokensResponse: &idpTokensResponse{
IDToken: validIDToken,
AccessToken: "access-token",
TokenType: "bearer",
ExpiresIn: 10,
},
responseVerify: func(t *testing.T, resp *envoy.CheckResponse) {
require.Equal(t, int32(codes.OK), resp.GetStatus().GetCode())
require.NotNil(t, resp.GetOkResponse())
requireTokensInResponse(t, resp.GetOkResponse(), basicOIDCConfig, validIDToken, "access-token")
requireStoredTokens(t, store, sessionID, true)
requireStoredTokens(t, store, newSessionID, false)
},
},
{
name: "succeed",
req: withSessionHeader,
Expand Down

0 comments on commit 0d8008e

Please sign in to comment.