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 d815189

Browse filesBrowse files
committed
Implementation v2
1 parent f73a5f5 commit d815189
Copy full SHA for d815189

File tree

7 files changed

+52
-312
lines changed
Filter options

7 files changed

+52
-312
lines changed

‎src/Symfony/Bundle/FrameworkBundle/EventListener/DisableSessionSubscriber.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/EventListener/DisableSessionSubscriber.php
-51Lines changed: 0 additions & 51 deletions
This file was deleted.

‎src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Resources/config/session.xml
+2-9Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
<argument type="service" id="session.flash_bag" />
1818
</service>
1919

20-
<service id="disableable_session" class="Symfony\Component\HttpFoundation\Session\DisableableSessionProxy" decorates="session">
21-
<argument type="service" id="disableable_session.inner"/>
22-
</service>
23-
2420
<service id="Symfony\Component\HttpFoundation\Session\SessionInterface" alias="session" />
2521
<service id="Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface" alias="session.storage" />
2622
<service id="SessionHandlerInterface" alias="session.handler" />
@@ -70,12 +66,9 @@
7066
<argument type="service_locator">
7167
<argument key="session" type="service" id="session" on-invalid="ignore" />
7268
<argument key="initialized_session" type="service" id="session" on-invalid="ignore_uninitialized" />
69+
<argument key="logger" type="service" id="logger" on-invalid="ignore" />
7370
</argument>
74-
</service>
75-
76-
<service id="session.disable_listener" class="Symfony\Bundle\FrameworkBundle\EventListener\DisableSessionSubscriber">
77-
<tag name="kernel.event_subscriber" />
78-
<argument type="service" id="session" />
71+
<argument>%kernel.debug%</argument>
7972
</service>
8073

8174
<!-- for BC -->

‎src/Symfony/Component/HttpFoundation/Request.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Request.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException;
1515
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
16-
use Symfony\Component\HttpFoundation\Session\DisableableSessionProxy;
1716
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1817

1918
/**
@@ -750,14 +749,14 @@ public function hasPreviousSession()
750749
* like whether the session is started or not. It is just a way to check if this Request
751750
* is associated with a Session instance.
752751
*
753-
* @return bool true when the Request contains an enabled Session object, false otherwise
752+
* @return bool true when the Request contains a Session object, false otherwise
754753
*/
755754
public function hasSession()
756755
{
757-
return null !== $this->session && !($this->session instanceof DisableableSessionProxy && $this->session->isDisabled());
756+
return null !== $this->session;
758757
}
759758

760-
public function setSession(?SessionInterface $session)
759+
public function setSession(SessionInterface $session)
761760
{
762761
$this->session = $session;
763762
}

‎src/Symfony/Component/HttpFoundation/Session/DisableableSessionProxy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/DisableableSessionProxy.php
-238Lines changed: 0 additions & 238 deletions
This file was deleted.

‎src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1919
use Symfony\Component\HttpKernel\Event\RequestEvent;
2020
use Symfony\Component\HttpKernel\Event\ResponseEvent;
21+
use Symfony\Component\HttpKernel\Exception\UnexpectedSessionUsageException;
2122
use Symfony\Component\HttpKernel\KernelEvents;
2223

2324
/**
@@ -40,11 +41,13 @@ abstract class AbstractSessionListener implements EventSubscriberInterface
4041
const NO_AUTO_CACHE_CONTROL_HEADER = 'Symfony-Session-NoAutoCacheControl';
4142

4243
protected $container;
44+
protected $debug;
4345
private $sessionUsageStack = [];
4446

45-
public function __construct(ContainerInterface $container = null)
47+
public function __construct(ContainerInterface $container = null, bool $debug = true)
4648
{
4749
$this->container = $container;
50+
$this->debug = $debug;
4851
}
4952

5053
public function onKernelRequest(RequestEvent $event)
@@ -83,6 +86,10 @@ public function onKernelResponse(ResponseEvent $event)
8386
}
8487

8588
if ($session instanceof Session ? $session->getUsageIndex() !== end($this->sessionUsageStack) : $session->isStarted()) {
89+
if (true === $event->getRequest()->attributes->get('_stateless', false)) {
90+
$this->reportUnexpectedSessionUse();
91+
}
92+
8693
if ($autoCacheControl) {
8794
$response
8895
->setExpires(new \DateTime())
@@ -145,4 +152,20 @@ public static function getSubscribedEvents(): array
145152
* @return SessionInterface|null A SessionInterface instance or null if no session is available
146153
*/
147154
abstract protected function getSession();
155+
156+
/**
157+
* Report that the session was unexpectedly used.
158+
*
159+
* @throws UnexpectedSessionUsageException
160+
*/
161+
private function reportUnexpectedSessionUse(): void
162+
{
163+
if ($this->debug) {
164+
throw new UnexpectedSessionUsageException();
165+
}
166+
167+
if ($this->container->has('logger')) {
168+
$this->container->get('logger')->warning('Session was used in a stateless mode');
169+
}
170+
}
148171
}

0 commit comments

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