我希望防止我的网站被点击劫持攻击。在哪个文件中以及在哪里设置X-Frame-Options以防止点击劫持攻击。
我希望防止我的网站被点击劫持攻击。在哪个文件中以及在哪里设置X-Frame-Options以防止点击劫持攻击。
你有两种方式:
add_header X-Frame-Options "SAMEORIGIN";
Illuminate\Http\Middleware\FrameGuard
应用到需要保护的路由上。<?php
namespace Illuminate\Http\Middleware;
use Closure;
class FrameGuard
{
/**
* Handle the given request and get the response.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return \Symfony\Component\HttpFoundation\Response
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$response->headers->set('X-Frame-Options', 'SAMEORIGIN', false);
return $response;
}
}
要解决所有路由上的问题:
在app/http/Kernel.php
中的protected $middleware
中添加FrameGuard::class,
默认情况下,FrameGuard.php设置为"SAMEORIGIN"
,但您可以根据需要更改以下行的第二个参数为"DENY"
或"ALLOW-FROM uri"
:
$response->headers->set('X-Frame-Options', 'SAMEORIGIN', false);
X-Frame-Options
。https://gist.github.com/EduardoSP6/221c75332de2dbebebe98bf51f80ddb5 - Waqleh