Skip to content

Instantly share code, notes, and snippets.

@cinkagan
Created January 11, 2021 23:41
Show Gist options
  • Save cinkagan/e436cd1e49104051b955eeaf6eaf7118 to your computer and use it in GitHub Desktop.
Save cinkagan/e436cd1e49104051b955eeaf6eaf7118 to your computer and use it in GitHub Desktop.
Laravel Query String Xss Security Middleware
<?php
namespace App\Http\Middleware;
use Illuminate\Support\Facades\Redirect;
use Closure;
class XSS
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$url = str_replace($request->url(), "", $request->fullUrl());
$input = $request->all();
array_walk_recursive($input, function (&$input) {
$input = strip_tags($input);
});
if (preg_match('/[\'^£$%&*()}{@#~><>|_+¬-]/', $url))
return redirect($request->url() . "/" . preg_replace('/[\'^£$%&*()}{@#~><>|_+¬-]/',"",strip_tags($url)));
$request->merge($input);
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment