Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security] Prevent creating session in stateless firewalls#51350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
chalasr merged 1 commit intosymfony:6.3fromSeb33300:6.3-stateless
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -91,7 +91,9 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio

$this->logger?->debug('Authentication failure, redirect triggered.', ['failure_path' => $options['failure_path']]);

$request->getSession()->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, $exception);
if (!$request->attributes->getBoolean('_stateless')) {
$request->getSession()->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, $exception);
}

return $this->httpUtils->createRedirectResponse($request, $options['failure_path']);
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,7 +103,7 @@ protected function determineTargetUrl(Request $request): string
}

$firewallName = $this->getFirewallName();
if (null !== $firewallName && $targetUrl = $this->getTargetPath($request->getSession(), $firewallName)) {
if (null !== $firewallName &&!$request->attributes->getBoolean('_stateless') &&$targetUrl = $this->getTargetPath($request->getSession(), $firewallName)) {
$this->removeTargetPath($request->getSession(), $firewallName);

return $targetUrl;
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,7 @@ protected function setUp(): void

$this->session = $this->createMock(SessionInterface::class);
$this->request = $this->createMock(Request::class);
$this->request->attributes = new ParameterBag(['_stateless' => false]);
$this->request->expects($this->any())->method('getSession')->willReturn($this->session);
$this->exception = $this->getMockBuilder(AuthenticationException::class)->onlyMethods(['getMessage'])->getMock();
}
Expand DownExpand Up@@ -89,6 +90,17 @@ public function testExceptionIsPersistedInSession()
$handler->onAuthenticationFailure($this->request, $this->exception);
}

public function testExceptionIsNotPersistedInSessionOnStatelessRequest()
{
$this->request->attributes = new ParameterBag(['_stateless' => true]);

$this->session->expects($this->never())
->method('set')->with(SecurityRequestAttributes::AUTHENTICATION_ERROR, $this->exception);

$handler = new DefaultAuthenticationFailureHandler($this->httpKernel, $this->httpUtils, [], $this->logger);
$handler->onAuthenticationFailure($this->request, $this->exception);
}

public function testExceptionIsPassedInRequestOnForward()
{
$options = ['failure_forward' => true];
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -56,6 +56,25 @@ public function testRequestRedirectionsWithTargetPathInSessions()
$this->assertSame('http://localhost/admin/dashboard', $handler->onAuthenticationSuccess($requestWithSession, $token)->getTargetUrl());
}

public function testStatelessRequestRedirections()
{
$session = $this->createMock(SessionInterface::class);
$session->expects($this->never())->method('get')->with('_security.admin.target_path');
$session->expects($this->never())->method('remove')->with('_security.admin.target_path');
$statelessRequest = Request::create('/');
$statelessRequest->setSession($session);
$statelessRequest->attributes->set('_stateless', true);

$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
$urlGenerator->expects($this->any())->method('generate')->willReturn('http://localhost/login');
$httpUtils = new HttpUtils($urlGenerator);
$token = $this->createMock(TokenInterface::class);
$handler = new DefaultAuthenticationSuccessHandler($httpUtils);
$handler->setFirewallName('admin');

$this->assertSame('http://localhost/', $handler->onAuthenticationSuccess($statelessRequest, $token)->getTargetUrl());
}

public static function getRequestRedirections()
{
return [
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp