Skip to content

Commit

Permalink
security #cve-2021-32693 [SecurityHttp] Fix "Authentication granted w…
Browse files Browse the repository at this point in the history
…ith multiple firewalls" (wouterj)

This PR was merged into the 5.3 branch.
  • Loading branch information
nicolas-grekas committed Jun 17, 2021
2 parents 746321a + 04c9d1a commit 6bf4c31
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Firewall/ContextListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function authenticate(RequestEvent $event)
$request = $event->getRequest();
$session = $request->hasPreviousSession() && $request->hasSession() ? $request->getSession() : null;

$request->attributes->set('_security_firewall_run', true);
$request->attributes->set('_security_firewall_run', $this->sessionKey);

if (null !== $session) {
$usageIndexValue = $session instanceof Session ? $usageIndexReference = &$session->getUsageIndex() : 0;
Expand Down Expand Up @@ -169,7 +169,7 @@ public function onKernelResponse(ResponseEvent $event)

$request = $event->getRequest();

if (!$request->hasSession() || !$request->attributes->get('_security_firewall_run', false)) {
if (!$request->hasSession() || $request->attributes->get('_security_firewall_run') !== $this->sessionKey) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/Firewall/ContextListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function testOnKernelResponseWithoutSession()
$tokenStorage = new TokenStorage();
$tokenStorage->setToken(new UsernamePasswordToken('test1', 'pass1', 'phpunit'));
$request = new Request();
$request->attributes->set('_security_firewall_run', true);
$request->attributes->set('_security_firewall_run', '_security_session');
$session = new Session(new MockArraySessionStorage());
$request->setSession($session);

Expand Down Expand Up @@ -212,7 +212,7 @@ public function testOnKernelResponseListenerRemovesItself()
$listener = new ContextListener($tokenStorage, [], 'key123', null, $dispatcher);

$request = new Request();
$request->attributes->set('_security_firewall_run', true);
$request->attributes->set('_security_firewall_run', '_security_key123');
$request->setSession($session);

$event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST, new Response());
Expand Down Expand Up @@ -370,7 +370,7 @@ protected function runSessionOnKernelResponse($newToken, $original = null)
{
$session = new Session(new MockArraySessionStorage());
$request = new Request();
$request->attributes->set('_security_firewall_run', true);
$request->attributes->set('_security_firewall_run', '_security_session');
$request->setSession($session);
$requestStack = new RequestStack();
$requestStack->push($request);
Expand Down

0 comments on commit 6bf4c31

Please sign in to comment.