XSSProtection Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class XSSProtection
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!in_array(strtolower($request->method()), ['put', 'post'])) {
return $next($request);
}
$input = $request->all();
array_walk_recursive($input, function (&$input) {
if (is_string($input)) {
$input = htmlspecialchars($input);
}
});
$request->merge($input);
return $next($request);
}
}