I need to add security for ajax get method in Laravel 5. For POST, PUT and DELETE Laravel token is good. But How can I add security in ajax get request.
Security
If an hacker try to access an ajax page directly form another domain. I need to check the domain name and restrict.
I have added middleware but I am not sure Is this the correct way?
<?php
namespace App\Http\Middleware;
use Closure;
class AjaxMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ((!$request->ajax()) || ($request->url() != url()->current())){
return response('Forbidden.', 403);
}
return $next($request);
}
}