Created
January 11, 2021 23:41
-
-
Save cinkagan/e436cd1e49104051b955eeaf6eaf7118 to your computer and use it in GitHub Desktop.
Laravel Query String Xss Security Middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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