]> BookStack Code Mirror - bookstack/blob - app/Http/Middleware/ControlIframeSecurity.php
Added notice for lack of shelf permission cascade
[bookstack] / app / Http / Middleware / ControlIframeSecurity.php
1 <?php
2
3 namespace BookStack\Http\Middleware;
4
5 use Closure;
6
7 /**
8  * Sets CSP headers to restrict the hosts that BookStack can be
9  * iframed within. Also adjusts the cookie samesite options
10  * so that cookies will operate in the third-party context.
11  */
12 class ControlIframeSecurity
13 {
14     /**
15      * Handle an incoming request.
16      *
17      * @param \Illuminate\Http\Request $request
18      * @param \Closure                 $next
19      *
20      * @return mixed
21      */
22     public function handle($request, Closure $next)
23     {
24         $iframeHosts = collect(explode(' ', config('app.iframe_hosts', '')))->filter();
25         if ($iframeHosts->count() > 0) {
26             config()->set('session.same_site', 'none');
27         }
28
29         $iframeHosts->prepend("'self'");
30
31         $response = $next($request);
32         $cspValue = 'frame-ancestors ' . $iframeHosts->join(' ');
33         $response->headers->set('Content-Security-Policy', $cspValue);
34
35         return $response;
36     }
37 }