Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix(auth): block OIDC token exchange without PKCE verifier

Andras Bacsaia1dbde341219
diff --git a/app/Auth/Oidc/Socialite/OidcProvider.php b/app/Auth/Oidc/Socialite/OidcProvider.php
index b9fc16f9c0..383b0cc910 100644
--- a/app/Auth/Oidc/Socialite/OidcProvider.php
+++ b/app/Auth/Oidc/Socialite/OidcProvider.php
@@ -209,9 +209,11 @@ class OidcProvider extends AbstractProvider implements ProviderInterface
$fields = $this->getTokenFields($code);
if ($this->getConfig()->usePkce) {
$verifier = $this->pullOidcFlowValue($this->verifierSessionKey((string) $this->request->input('state')));
- if ($verifier !== null) {
- $fields['code_verifier'] = $verifier;
+ if ($verifier === null) {
+ throw new OidcException('OIDC login session expired. Please try again.');
}
+
+ $fields['code_verifier'] = $verifier;
}
$response = $this->getHttpClient()->post($this->getTokenUrl(), [
diff --git a/app/Livewire/SettingsOauth.php b/app/Livewire/SettingsOauth.php
index 8b4c902d5f..d038d9a956 100644
--- a/app/Livewire/SettingsOauth.php
+++ b/app/Livewire/SettingsOauth.php
@@ -5,6 +5,7 @@ namespace App\Livewire;
use App\Models\InstanceSettings;
use App\Models\OauthSetting;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
+use Illuminate\Http\RedirectResponse;
use Illuminate\Validation\ValidationException;
use Livewire\Component;
@@ -55,7 +56,7 @@ class SettingsOauth extends Component
return $rules;
}
- public function mount(?string $provider = null)
+ public function mount(?string $provider = null): ?RedirectResponse
{
if (! isInstanceAdmin()) {
return redirect()->route('home');
@@ -73,6 +74,8 @@ class SettingsOauth extends Component
if ($this->selectedProvider !== null && ! array_key_exists($this->selectedProvider, $this->oauth_settings_map)) {
abort(404);
}
+
+ return null;
}
private function updateOauthSettings(?string $provider = null): void
diff --git a/tests/Unit/OidcProviderPkceTest.php b/tests/Unit/OidcProviderPkceTest.php
index 9726f08b0c..b92ff58ffe 100644
--- a/tests/Unit/OidcProviderPkceTest.php
+++ b/tests/Unit/OidcProviderPkceTest.php
@@ -1,5 +1,6 @@
<?php
+use App\Auth\Oidc\Exceptions\OidcException;
use App\Auth\Oidc\OidcConfig;
use App\Auth\Oidc\OidcDiscoveryDocument;
use App\Auth\Oidc\OidcDiscoveryService;
@@ -128,7 +129,7 @@ it('sends a fresh oidc pkce verifier during token exchange', function () {
->and($session->has('oidc.code_verifier.state-value'))->toBeFalse();
});
-it('does not send an expired oidc pkce verifier during token exchange', function () {
+it('throws a session expired error for an expired oidc pkce verifier during token exchange', function () {
$session = oidc_provider_session();
$session->put('oidc.code_verifier.state-value', [
'value' => 'expired-verifier',
@@ -144,9 +145,4 @@ it('does not send an expired oidc pkce verifier during token exchange', function
$provider->setHttpClient(new Client(['handler' => $handler]));
$provider->getAccessTokenResponse('authorization-code');
-
- parse_str((string) $history[0]['request']->getBody(), $tokenRequestFields);
-
- expect($tokenRequestFields)->not->toHaveKey('code_verifier')
- ->and($session->has('oidc.code_verifier.state-value'))->toBeFalse();
-});
+})->throws(OidcException::class, 'OIDC login session expired. Please try again.');