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

Appearance settings

Commit 19c656e

Browse filesBrowse files
[Security/Http] ensure session is started when tracking it
1 parent 46e441f commit 19c656e
Copy full SHA for 19c656e

File tree

2 files changed

+22
-2
lines changed
Filter options

2 files changed

+22
-2
lines changed

‎src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall/ContextListener.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ public function authenticate(RequestEvent $event)
115115

116116
if (null !== $session) {
117117
$usageIndexValue = method_exists(Request::class, 'getPreferredFormat') && $session instanceof Session ? $usageIndexReference = &$session->getUsageIndex() : 0;
118-
$sessionId = $session->getId();
118+
$sessionId = $request->cookies->get($session->getName());
119119
$token = $session->get($this->sessionKey);
120120

121-
if ($this->sessionTrackerEnabler && $session->getId() === $sessionId) {
121+
if ($this->sessionTrackerEnabler && \in_array($sessionId, [true, $session->getId()], true)) {
122122
$usageIndexReference = $usageIndexValue;
123123
}
124124
}

‎src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,26 @@ public function testDeauthenticatedEvent()
344344
$this->assertNull($tokenStorage->getToken());
345345
}
346346

347+
/**
348+
* @requires function \Symfony\Component\HttpFoundation\Request::getPreferredFormat
349+
*/
350+
public function testWithPreviousNotStartedSession()
351+
{
352+
$session = new Session(new MockArraySessionStorage());
353+
354+
$request = new Request();
355+
$request->setSession($session);
356+
$request->cookies->set('MOCKSESSID', true);
357+
358+
$usageIndex = $session->getUsageIndex();
359+
360+
$tokenStorage = new TokenStorage();
361+
$listener = new ContextListener($tokenStorage, [], 'context_key', null, null, null, [$tokenStorage, 'getToken']);
362+
$listener(new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST));
363+
364+
$this->assertSame($usageIndex, $session->getUsageIndex());
365+
}
366+
347367
protected function runSessionOnKernelResponse($newToken, $original = null)
348368
{
349369
$session = new Session(new MockArraySessionStorage());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.