mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-12-05 17:22:06 +03:00
OIDC: Updated state handling to prevent loss from other requests
Which was occuring in chrome, where background requests to the PWA manifest, or opensearch, endpoint caused OIDC to fail due to lost state since it was only flashed to the session. This persists it with a manual TTL. Added tests to cover. Manually tested against Azure. For #5929
This commit is contained in:
@@ -138,7 +138,7 @@ class OidcTest extends TestCase
|
||||
{
|
||||
// Start auth
|
||||
$this->post('/oidc/login');
|
||||
$state = session()->get('oidc_state');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1];
|
||||
|
||||
$transactions = $this->mockHttpClient([$this->getMockAuthorizationResponse([
|
||||
'email' => 'benny@example.com',
|
||||
@@ -190,6 +190,35 @@ class OidcTest extends TestCase
|
||||
$this->assertSessionError('Login using SingleSignOn-Testing failed, system did not provide successful authorization');
|
||||
}
|
||||
|
||||
public function test_callback_works_even_if_other_request_made_by_session()
|
||||
{
|
||||
$this->mockHttpClient([$this->getMockAuthorizationResponse([
|
||||
'email' => 'benny@example.com',
|
||||
'sub' => 'benny1010101',
|
||||
])]);
|
||||
|
||||
$this->post('/oidc/login');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1];
|
||||
|
||||
$this->get('/');
|
||||
|
||||
$resp = $this->get("/oidc/callback?code=SplxlOBeZQQYbYS6WxSbIA&state={$state}");
|
||||
$resp->assertRedirect('/');
|
||||
}
|
||||
|
||||
public function test_callback_fails_if_state_timestamp_is_too_old()
|
||||
{
|
||||
$this->post('/oidc/login');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1];
|
||||
session()->put('oidc_state', (time() - 60 * 4) . ':' . $state);
|
||||
|
||||
$this->get('/');
|
||||
|
||||
$resp = $this->get("/oidc/callback?code=SplxlOBeZQQYbYS6WxSbIA&state={$state}");
|
||||
$resp->assertRedirect('/login');
|
||||
$this->assertSessionError('Login using SingleSignOn-Testing failed, system did not provide successful authorization');
|
||||
}
|
||||
|
||||
public function test_dump_user_details_option_outputs_as_expected()
|
||||
{
|
||||
config()->set('oidc.dump_user_details', true);
|
||||
@@ -797,7 +826,7 @@ class OidcTest extends TestCase
|
||||
{
|
||||
// Start auth
|
||||
$resp = $this->post('/oidc/login');
|
||||
$state = session()->get('oidc_state');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1];
|
||||
|
||||
$pkceCode = session()->get('oidc_pkce_code');
|
||||
$this->assertGreaterThan(30, strlen($pkceCode));
|
||||
@@ -825,7 +854,7 @@ class OidcTest extends TestCase
|
||||
{
|
||||
config()->set('oidc.display_name_claims', 'first_name|last_name');
|
||||
$this->post('/oidc/login');
|
||||
$state = session()->get('oidc_state');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1];
|
||||
|
||||
$client = $this->mockHttpClient([
|
||||
$this->getMockAuthorizationResponse(['name' => null]),
|
||||
@@ -973,7 +1002,7 @@ class OidcTest extends TestCase
|
||||
]);
|
||||
|
||||
$this->post('/oidc/login');
|
||||
$state = session()->get('oidc_state');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1];
|
||||
$client = $this->mockHttpClient([$this->getMockAuthorizationResponse([
|
||||
'groups' => [],
|
||||
])]);
|
||||
@@ -999,7 +1028,7 @@ class OidcTest extends TestCase
|
||||
protected function runLogin($claimOverrides = [], $additionalHttpResponses = []): TestResponse
|
||||
{
|
||||
$this->post('/oidc/login');
|
||||
$state = session()->get('oidc_state');
|
||||
$state = explode(':', session()->get('oidc_state'), 2)[1] ?? '';
|
||||
$this->mockHttpClient([$this->getMockAuthorizationResponse($claimOverrides), ...$additionalHttpResponses]);
|
||||
|
||||
return $this->get('/oidc/callback?code=SplxlOBeZQQYbYS6WxSbIA&state=' . $state);
|
||||
|
||||
Reference in New Issue
Block a user