]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/ApplyCspRules.php
Updated translator & dependency attribution before release v25.05.1
[bookstack] / app / Http / Middleware / ApplyCspRules.php
1 <?php
2
3 namespace BookStack\Http\Middleware;
4
5 use BookStack\Util\CspService;
6 use Closure;
7 use Illuminate\Http\Request;
8
9 class ApplyCspRules
10 {
11     protected CspService $cspService;
12
13     public function __construct(CspService $cspService)
14     {
15         $this->cspService = $cspService;
16     }
17
18     /**
19      * Handle an incoming request.
20      *
21      * @param Request $request
22      * @param Closure $next
23      *
24      * @return mixed
25      */
26     public function handle($request, Closure $next)
27     {
28         view()->share('cspNonce', $this->cspService->getNonce());
29         if ($this->cspService->allowedIFrameHostsConfigured()) {
30             config()->set('session.same_site', 'none');
31         }
32
33         $response = $next($request);
34
35         $cspHeader = $this->cspService->getCspHeader();
36         $response->headers->set('Content-Security-Policy', $cspHeader, false);
37
38         return $response;
39     }
40 }
Morty Proxy This is a proxified and sanitized view of the page, visit original site.