fix(op): Add mitigation for PKCE downgrade attack
This commit is contained in:
parent
b917cdc2e3
commit
f8c3a2c6aa
2 changed files with 11 additions and 6 deletions
|
@ -80,12 +80,9 @@ func AuthorizeCodeClient(ctx context.Context, tokenReq *oidc.AccessTokenRequest,
|
|||
}
|
||||
|
||||
codeChallenge := request.GetCodeChallenge()
|
||||
if codeChallenge != nil {
|
||||
err = AuthorizeCodeChallenge(tokenReq.CodeVerifier, codeChallenge)
|
||||
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
err = AuthorizeCodeChallenge(tokenReq.CodeVerifier, codeChallenge)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if tokenReq.ClientAssertionType == oidc.ClientAssertionTypeJWTAssertion {
|
||||
|
|
|
@ -132,6 +132,14 @@ func AuthorizeClientIDSecret(ctx context.Context, clientID, clientSecret string,
|
|||
// AuthorizeCodeChallenge authorizes a client by validating the code_verifier against the previously sent
|
||||
// code_challenge of the auth request (PKCE)
|
||||
func AuthorizeCodeChallenge(codeVerifier string, challenge *oidc.CodeChallenge) error {
|
||||
if challenge == nil {
|
||||
if codeVerifier != "" {
|
||||
return oidc.ErrInvalidRequest().WithDescription("code_verifier unexpectedly provided")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if codeVerifier == "" {
|
||||
return oidc.ErrInvalidRequest().WithDescription("code_challenge required")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue