I want to prevent my website from clickJacking attack. In which file and where to set X-Frame-Options for preventing clickJacking attack.
I want to prevent my website from clickJacking attack. In which file and where to set X-Frame-Options for preventing clickJacking attack.
You have 2 ways:
add_header X-Frame-Options "SAMEORIGIN";
Illuminate\Http\Middleware\FrameGuard onto the routes you want to protect.<?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;
}
}
To fix the problem on all your routes :
Add FrameGuard::class, on the protected $middleware in your app/http/Kernel.php
FrameGuard.php by default is set to "SAMEORIGIN", but you can change the second parameter of the following line with "DENY" or "ALLOW-FROM uri" (according to your needs) :
$response->headers->set('X-Frame-Options', 'SAMEORIGIN', false);