Skip to content

Commit

Permalink
Merge pull request from GHSA-w8vh-p74j-x9xp
Browse files Browse the repository at this point in the history
* Fixed Oauth1/2 and OpenID Connect state/noce check

* Updated changelog for GHSA-w8vh-p74j-x9xp

---------

Co-authored-by: Alexander Makarov <[email protected]>
  • Loading branch information
rhertogh and samdark authored Dec 16, 2023
1 parent 721ed97 commit dabddf2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Yii Framework 2 authclient extension Change Log

- Bug #364: Use issuer claim from OpenID Configuration (radwouters)
- Enh #367: Throw more specific `ClientErrorResponseException` when the response code in `BaseOAuth::sendRequest()` is a 4xx (rhertogh)
- Enh GHSA-w8vh-p74j-x9xp: Improved security for OAuth1, OAuth2 and OpenID Connect clients by using timing attack safe string comparsion (rhertogh)
- Enh GHSA-rw54-6826-c8j5: Improved security for OAuth2 client by requiring an `authCodeVerifier` if PKCE is enabled and clearing it after usage (rhertogh)


Expand Down
2 changes: 1 addition & 1 deletion src/OAuth1.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function fetchAccessToken($oauthToken = null, OAuthToken $requestToken =
}
}

if (strcmp($requestToken->getToken(), $oauthToken) !== 0) {
if (!Yii::$app->getSecurity()->compareString($requestToken->getToken(), $oauthToken)) {
throw new HttpException(400, 'Invalid auth state parameter.');
}

Expand Down
6 changes: 5 additions & 1 deletion src/OAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ public function fetchAccessToken($authCode, array $params = [])
$authState = $this->getState('authState');
$incomingRequest = Yii::$app->getRequest();
$incomingState = $incomingRequest->get('state', $incomingRequest->post('state'));
if (!isset($incomingState) || empty($authState) || strcmp($incomingState, $authState) !== 0) {
if (
!isset($incomingState)
|| empty($authState)
|| !Yii::$app->getSecurity()->compareString($incomingState, $authState)
) {
throw new HttpException(400, 'Invalid auth state parameter.');
}
$this->removeState('authState');
Expand Down
6 changes: 5 additions & 1 deletion src/OpenIdConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,11 @@ protected function createToken(array $tokenConfig = [])

if ($this->getValidateAuthNonce()) {
$authNonce = $this->getState('authNonce');
if (!isset($jwsData['nonce']) || empty($authNonce) || strcmp($jwsData['nonce'], $authNonce) !== 0) {
if (
!isset($jwsData['nonce'])
|| empty($authNonce)
|| !Yii::$app->getSecurity()->compareString($jwsData['nonce'], $authNonce)
) {
throw new HttpException(400, 'Invalid auth nonce');
} else {
$this->removeState('authNonce');
Expand Down

0 comments on commit dabddf2

Please sign in to comment.