32 lines
841 B
PHP
32 lines
841 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use App\Lib\Helpers\ToolboxHelper;
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
|
|
class XssSanitizer
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @phpcs:disable Squiz.Commenting.FunctionComment.IncorrectTypeHint
|
|
*/
|
|
public function handle(Request $request, Closure $next, mixed ...$params): mixed
|
|
{
|
|
// phpcs:enable phpcs:disable
|
|
$inputs = $request->all();
|
|
array_walk_recursive($inputs, function (&$input, $name) use ($params) {
|
|
if (in_array($name, $params)) {
|
|
$input = clean($input);
|
|
$input = ToolboxHelper::assertNoInternalUrls($name, $input);
|
|
} else {
|
|
$input = strip_tags($input);
|
|
}
|
|
});
|
|
$request->merge($inputs);
|
|
|
|
return $next($request);
|
|
}
|
|
}
|