Skip to content

Commit 721ed97

Browse files
authored
Merge pull request from GHSA-rw54-6826-c8j5
* Oauth2 replay attack mitigation for PKCE * Oauth2 PKCE downgrate attack mitigation * Updated changelog for GHSA-rw54-6826-c8j5
1 parent 0d1c388 commit 721ed97

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Yii Framework 2 authclient extension Change Log
55
------------------------
66

77
- Bug #364: Use issuer claim from OpenID Configuration (radwouters)
8-
- Enh: #367: Throw more specific `ClientErrorResponseException` when the response code in `BaseOAuth::sendRequest()` is a 4xx (rhertogh)
8+
- Enh #367: Throw more specific `ClientErrorResponseException` when the response code in `BaseOAuth::sendRequest()` is a 4xx (rhertogh)
9+
- Enh GHSA-rw54-6826-c8j5: Improved security for OAuth2 client by requiring an `authCodeVerifier` if PKCE is enabled and clearing it after usage (rhertogh)
910

1011

1112
2.2.14 November 18, 2022

src/OAuth2.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,14 @@ public function fetchAccessToken($authCode, array $params = [])
131131
];
132132

133133
if ($this->enablePkce) {
134-
$defaultParams['code_verifier'] = $this->getState('authCodeVerifier');
134+
$authCodeVerifier = $this->getState('authCodeVerifier');
135+
if (empty($authCodeVerifier)) {
136+
// Prevent PKCE Downgrade Attack
137+
// https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#name-pkce-downgrade-attack
138+
throw new HttpException(409, 'Invalid auth code verifier.');
139+
}
140+
$defaultParams['code_verifier'] = $authCodeVerifier;
141+
$this->removeState('authCodeVerifier');
135142
}
136143

137144
$request = $this->createRequest()

0 commit comments

Comments
 (0)