3 namespace BookStack\Http\Middleware;
6 use Symfony\Component\HttpFoundation\Response;
9 * Sets CSP headers to restrict the hosts that BookStack can be
10 * iframed within. Also adjusts the cookie samesite options
11 * so that cookies will operate in the third-party context.
13 class ControlIframeSecurity
16 * Handle an incoming request.
18 * @param \Illuminate\Http\Request $request
19 * @param \Closure $next
22 public function handle($request, Closure $next)
24 $iframeHosts = collect(explode(' ', config('app.iframe_hosts', '')))->filter();
25 if ($iframeHosts->count() > 0) {
26 config()->set('session.same_site', 'none');
29 $iframeHosts->prepend("'self'");
31 $response = $next($request);
32 $cspValue = 'frame-ancestors ' . $iframeHosts->join(' ');
33 $response->headers->set('Content-Security-Policy', $cspValue);