Skip to content

Commit 776a26f

Browse files
cicnavipradtke
authored andcommitted
Apply PKCE downgrade protection from upstream
1 parent f76e1af commit 776a26f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/Server/Grants/AuthCodeGrant.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,18 @@ public function respondToAccessTokenRequest(
352352
throw OAuthServerException::invalidRequest('code', 'Cannot decrypt the authorization code', $e);
353353
}
354354

355+
$codeVerifier = $this->getRequestParameter('code_verifier', $request, null);
356+
357+
// If a code challenge isn't present but a code verifier is, reject the request to block PKCE downgrade attack
358+
if ($this->shouldCheckPkce($client) && empty($authCodePayload->code_challenge) && $codeVerifier !== null) {
359+
throw OAuthServerException::invalidRequest(
360+
'code_challenge',
361+
'code_verifier received when no code_challenge is present'
362+
);
363+
}
364+
355365
// Validate code challenge
356366
if (!empty($authCodePayload->code_challenge)) {
357-
$codeVerifier = $this->getRequestParameter('code_verifier', $request, null);
358-
359367
if ($codeVerifier === null) {
360368
throw OAuthServerException::invalidRequest('code_verifier');
361369
}

0 commit comments

Comments
 (0)