src/AppBundle/EventSubscriber/CSPSubscriber.php line 12

Open in your IDE?
  1. <?php
  2. namespace AppBundle\EventSubscriber;
  3. use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  4. use Symfony\Component\HttpKernel\KernelEvents;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class CSPSubscriber implements EventSubscriberInterface
  7. {
  8.     public function onKernelResponse(FilterResponseEvent $event)
  9.     {
  10.         $response $event->getResponse();
  11.         $policy "default-src 'self' 'unsafe-inline';"
  12.             "script-src 'self' 'unsafe-inline' 'unsafe-eval' code.jquery.com " .
  13.             "ajax.googleapis.com maps.googleapis.com maps.gstatic.com " .
  14.             "www.googletagmanager.com www.google-analytics.com " .
  15.             "ssl.google-analytics.com www.googleadservices.com" .
  16.             "stats.g.doubleclick.net googleads.g.doubleclick.net " .
  17.             "https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/ " .
  18.             "c.seznam.cz;"
  19.             "frame-src https://www.google.com/recaptcha/ https://www.google.com/maps/ https://www.rezidencesmichovcity.cz/ https://tour.vrspace.cz/ seznam.cz;"
  20.             "style-src 'self' 'unsafe-inline' code.jquery.com fonts.googleapis.com c.seznam.cz;"
  21.             "font-src 'self' 'unsafe-inline' data: fonts.gstatic.com;"
  22.             "child-src 'self' 'unsafe-inline' www.google.com tour.vrspace.cz www.rezidencesmichovcity.cz;"
  23.             "img-src 'self' data: www.googletagmanager.com www.google-analytics.com c.imedia.cz c.seznam.cz h.seznam.cz www.google.com www.google.cz stats.g.doubleclick.net;"
  24.             "connect-src 'self' www.google-analytics.com stats.g.doubleclick.net;";
  25.         $response->headers->set("Content-Security-Policy"$policy);
  26.         $response->headers->set("Strict-Transport-Security""max-age=63072000");
  27.         $response->headers->set("X-Frame-Options""DENY");
  28.         $response->headers->set("X-Content-Type-Options""nosniff");
  29.         $response->headers->set("X-XSS-Protection""1; mode=block");
  30.     }
  31.     public static function getSubscribedEvents()
  32.     {
  33.         return [
  34.             KernelEvents::RESPONSE => 'onKernelResponse'
  35.         ];
  36.     }
  37. }