fix(op): Add mitigation for PKCE downgrade attack

This commit is contained in:
Ayato 2025-04-29 11:53:48 +09:00
parent b917cdc2e3
commit f8c3a2c6aa
No known key found for this signature in database
GPG key ID: 56E05AE09DBA012D
2 changed files with 11 additions and 6 deletions

View file

@ -80,12 +80,9 @@ func AuthorizeCodeClient(ctx context.Context, tokenReq *oidc.AccessTokenRequest,
} }
codeChallenge := request.GetCodeChallenge() codeChallenge := request.GetCodeChallenge()
if codeChallenge != nil { err = AuthorizeCodeChallenge(tokenReq.CodeVerifier, codeChallenge)
err = AuthorizeCodeChallenge(tokenReq.CodeVerifier, codeChallenge) if err != nil {
return nil, nil, err
if err != nil {
return nil, nil, err
}
} }
if tokenReq.ClientAssertionType == oidc.ClientAssertionTypeJWTAssertion { if tokenReq.ClientAssertionType == oidc.ClientAssertionTypeJWTAssertion {

View file

@ -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 // AuthorizeCodeChallenge authorizes a client by validating the code_verifier against the previously sent
// code_challenge of the auth request (PKCE) // code_challenge of the auth request (PKCE)
func AuthorizeCodeChallenge(codeVerifier string, challenge *oidc.CodeChallenge) error { 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 == "" { if codeVerifier == "" {
return oidc.ErrInvalidRequest().WithDescription("code_challenge required") return oidc.ErrInvalidRequest().WithDescription("code_challenge required")
} }