Skip to content

Commit

Permalink
Apply PKCE downgrade protection from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Marko Ivančić authored and pradtke committed Mar 20, 2023
1 parent f76e1af commit 776a26f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/Server/Grants/AuthCodeGrant.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,18 @@ public function respondToAccessTokenRequest(
throw OAuthServerException::invalidRequest('code', 'Cannot decrypt the authorization code', $e);
}

$codeVerifier = $this->getRequestParameter('code_verifier', $request, null);

// If a code challenge isn't present but a code verifier is, reject the request to block PKCE downgrade attack
if ($this->shouldCheckPkce($client) && empty($authCodePayload->code_challenge) && $codeVerifier !== null) {
throw OAuthServerException::invalidRequest(
'code_challenge',
'code_verifier received when no code_challenge is present'
);
}

// Validate code challenge
if (!empty($authCodePayload->code_challenge)) {
$codeVerifier = $this->getRequestParameter('code_verifier', $request, null);

if ($codeVerifier === null) {
throw OAuthServerException::invalidRequest('code_verifier');
}
Expand Down

0 comments on commit 776a26f

Please sign in to comment.