Skip to content

Commit

Permalink
NEXT-34113 - Clear cookies on 404 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim authored and philipreinken committed Mar 5, 2024
1 parent 8767a98 commit 3477e4a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 257 deletions.
1 change: 1 addition & 0 deletions DependencyInjection/services.xml
Expand Up @@ -182,6 +182,7 @@
<argument type="service" id="Shopware\Core\Framework\DataAbstractionLayer\Cache\EntityCacheKeyGenerator"/>
<argument type="service" id="Shopware\Core\Framework\Adapter\Cache\CacheInvalidator"/>
<argument type="service" id="event_dispatcher"/>
<argument>%session.storage.options%</argument>

<tag name="kernel.event_subscriber"/>
<tag name="kernel.reset" method="reset"/>
Expand Down
14 changes: 13 additions & 1 deletion Framework/Routing/NotFound/NotFoundSubscriber.php
Expand Up @@ -42,10 +42,13 @@ class NotFoundSubscriber implements EventSubscriberInterface, ResetInterface
*/
private bool $handled = false;

private string $sessionName;

/**
* @internal
*
* @param AbstractCacheTracer<Response> $cacheTracer
* @param array{name?: string} $sessionOptions
*/
public function __construct(
private readonly HttpKernelInterface $httpKernel,
Expand All @@ -55,8 +58,10 @@ public function __construct(
private readonly AbstractCacheTracer $cacheTracer,
private readonly EntityCacheKeyGenerator $generator,
private readonly CacheInvalidator $cacheInvalidator,
private readonly EventDispatcherInterface $eventDispatcher
private readonly EventDispatcherInterface $eventDispatcher,
array $sessionOptions = []
) {
$this->sessionName = $sessionOptions['name'] ?? 'session-';
}

public static function getSubscribedEvents(): array
Expand Down Expand Up @@ -123,6 +128,13 @@ public function onError(ExceptionEvent $event): void
$response->setContext(null);
}

// Remove session cookie from 404 pages, injected by the Symfony session listener
foreach ($response->headers->getCookies() as $cookie) {
if ($cookie->getName() === $this->sessionName) {
$response->headers->removeCookie($cookie->getName(), $cookie->getPath(), $cookie->getDomain());
}
}

return $response;
});

Expand Down
34 changes: 0 additions & 34 deletions Test/Framework/Routing/NotFound/NotFoundPageCacheKeyEventTest.php

This file was deleted.

34 changes: 0 additions & 34 deletions Test/Framework/Routing/NotFound/NotFoundPageTagsEventTest.php

This file was deleted.

188 changes: 0 additions & 188 deletions Test/Framework/Routing/NotFound/NotFoundSubscriberTest.php

This file was deleted.

0 comments on commit 3477e4a

Please sign in to comment.