Path: blob/1.0-develop/app/Http/Middleware/SetSecurityHeaders.php
14042 views
<?php12namespace Pterodactyl\Http\Middleware;34use Illuminate\Http\Request;56class SetSecurityHeaders7{8/**9* Ideally we move away from X-Frame-Options/X-XSS-Protection and implement a10* proper standard CSP, but I can guarantee that will break for a lot of folks11* using custom plugins and who knows what image embeds.12*13* We'll circle back to that at a later date when it can be more fully controlled14* by the admin to support those cases without too much trouble.15*/16private static array $headers = [17'X-Frame-Options' => 'DENY',18'X-Content-Type-Options' => 'nosniff',19'X-XSS-Protection' => '1; mode=block',20'Referrer-Policy' => 'no-referrer-when-downgrade',21];2223/**24* Enforces some basic security headers on all responses returned by the software.25* If a header has already been set in another location within the code it will be26* skipped over here.27*28* @param (\Closure(mixed): \Illuminate\Http\Response) $next29*/30public function handle(Request $request, \Closure $next): mixed31{32$response = $next($request);3334foreach (static::$headers as $key => $value) {35if (! $response->headers->has($key)) {36$response->headers->set($key, $value);37}38}3940return $response;41}42}434445