custom/plugins/SwagPlatformSecurity/src/Fixes/NEXT20309/SecurityFix.php line 43

Open in your IDE?
  1. <?php
  2. namespace Swag\Security\Fixes\NEXT20309;
  3. use Shopware\Core\Framework\Event\BeforeSendResponseEvent;
  4. use Swag\Security\Components\AbstractSecurityFix;
  5. use Symfony\Component\DependencyInjection\ContainerInterface;
  6. class SecurityFix extends AbstractSecurityFix
  7. {
  8.     /**
  9.      * @var ContainerInterface
  10.      */
  11.     protected $container;
  12.     public function __construct(ContainerInterface $container)
  13.     {
  14.         $this->container $container;
  15.     }
  16.     public static function getTicket(): string
  17.     {
  18.         return 'NEXT-20309';
  19.     }
  20.     public static function getMinVersion(): string
  21.     {
  22.         return '6.1.0';
  23.     }
  24.     public static function getMaxVersion(): string
  25.     {
  26.         return '6.4.8.2';
  27.     }
  28.     public static function getSubscribedEvents(): array
  29.     {
  30.         return [
  31.             BeforeSendResponseEvent::class => 'beforeSendResponse'
  32.         ];
  33.     }
  34.     public function beforeSendResponse(BeforeSendResponseEvent $event): void
  35.     {
  36.         $reverseProxyEnabled $this->container->hasParameter('storefront.reverse_proxy.enabled') && $this->container->getParameter('storefront.reverse_proxy.enabled');
  37.         if ($reverseProxyEnabled) {
  38.             return;
  39.         }
  40.         $response $event->getResponse();
  41.         $noStore $response->headers->getCacheControlDirective('no-store');
  42.         // We don't want that the client will cache the website, if no reverse proxy is configured
  43.         $response->headers->remove('cache-control');
  44.         $response->setPrivate();
  45.         if ($noStore) {
  46.             $response->headers->addCacheControlDirective('no-store');
  47.         } else {
  48.             $response->headers->addCacheControlDirective('no-cache');
  49.         }
  50.     }
  51. }