Skip to content

Instantly share code, notes, and snippets.

@doulmi
Created February 24, 2017 08:36
Show Gist options
  • Save doulmi/822f9c08f988fd48b73ffad77a07a53d to your computer and use it in GitHub Desktop.
Save doulmi/822f9c08f988fd48b73ffad77a07a53d to your computer and use it in GitHub Desktop.
Protect from form input XSS attack
public static function stripXSS()
{
$sanitized = static::cleanArray(Input::get());
Input::merge($sanitized);
}
public static function cleanArray($array)
{
$result = array();
foreach ($array as $key => $value) {
$key = strip_tags($key);
if (is_array($value)) {
$result[$key] = static::cleanArray($value);
} else {
$result[$key] = trim(strip_tags($value)); // Remove trim() if you want to.
}
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment