all(); $sanitizedInput = $this->removeScripts($input); $request->replace($sanitizedInput); return $next($request); } protected function removeScripts(array $input) { foreach ($input as $key => $value) { if (is_array($value)) { $input[$key] = $this->removeScripts($value); } elseif (is_string($value)) { $input[$key] = $this->sanitizeString($value); } } return $input; } protected function sanitizeHtml(string $value) { $dom = new \DOMDocument(); $dom->loadHTML($value, LIBXML_HTML_NODEFDTD); $scriptTags = $dom->getElementsByTagName('script'); foreach ($scriptTags as $scriptTag) { $scriptTag->parentNode->removeChild($scriptTag); } $cleanContent = $dom->saveHTML(); return $cleanContent; } protected function sanitizeString(string $value) { $cleanValue = htmlspecialchars_decode($value); $cleanValue = preg_replace("/)<[^<]*)*<\/script>/i", '', $cleanValue); $cleanValue = preg_replace("/]*>(.*?)<\/script>/is", '', $cleanValue); return $cleanValue; } }