Skip to content

Commit 211d812

Browse files
committed
Merge #12 Fix OIDC state mismatch
2 parents f8e68b3 + 90f1381 commit 211d812

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/Controller/LoginController.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,21 @@ public function login(int $providerId, string $redirectUrl = null) {
227227
return $this->buildErrorTemplateResponse($message, Http::STATUS_NOT_FOUND, ['provider_not_found' => $providerId]);
228228
}
229229

230-
$state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
231-
$this->session->set(self::STATE, $state);
232-
$this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
230+
// check if oidc state is present in session data
231+
if ($this->session->exists(self::STATE)) {
232+
$state = $this->session->get(self::STATE);
233+
$nonce = $this->session->get(self::NONCE);
234+
} else {
235+
$state = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
236+
$this->session->set(self::STATE, $state);
237+
$this->session->set(self::REDIRECT_AFTER_LOGIN, $redirectUrl);
238+
239+
$nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
240+
$this->session->set(self::NONCE, $nonce);
233241

234-
$nonce = $this->random->generate(32, ISecureRandom::CHAR_DIGITS . ISecureRandom::CHAR_UPPER);
235-
$this->session->set(self::NONCE, $nonce);
242+
$this->session->set(self::PROVIDERID, $providerId);
243+
}
236244

237-
$this->session->set(self::PROVIDERID, $providerId);
238245
$this->session->close();
239246

240247
// get attribute mapping settings
@@ -523,6 +530,10 @@ public function code(string $state = '', string $code = '', string $scope = '',
523530
$this->userSession->createSessionToken($this->request, $user->getUID(), $user->getUID());
524531
$this->userSession->createRememberMeToken($user);
525532

533+
// remove code login session values
534+
$this->session->remove(self::STATE);
535+
$this->session->remove(self::NONCE);
536+
526537
// Set last password confirm to the future as we don't have passwords to confirm against with SSO
527538
$this->session->set('last-password-confirm', strtotime('+4 year', time()));
528539

0 commit comments

Comments
 (0)