mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-01-24 07:08:35 +01:00
30 lines
840 B
PHP
30 lines
840 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Vite;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class AddContentSecurityPolicyHeaders
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next) : Response
|
|
{
|
|
if (config('2fauth.config.contentSecurityPolicy')) {
|
|
Vite::useCspNonce();
|
|
|
|
return $next($request)->withHeaders([
|
|
'Content-Security-Policy' => "script-src 'nonce-" . Vite::cspNonce() . "';style-src 'self' 'unsafe-inline';connect-src 'self';img-src 'self' data:;object-src 'none';",
|
|
]);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|