Laravel での入力フィルタリングに関する完全な記事があります。役立つかもしれませんhttp://usman.it/xss-filter-laravel/。この記事からの抜粋を次に示します。
グローバルな XSS クリーンを自分で行うことができます。頻繁に必要になる共通メソッドを記述するためのライブラリがない場合は、新しいライブラリ Common を application/library に作成するようお願いします。この 2 つのメソッドを Common ライブラリに追加します。
/*
* Method to strip tags globally.
*/
public static function global_xss_clean()
{
// Recursive cleaning for array [] inputs, not just strings.
$sanitized = static::array_strip_tags(Input::get());
Input::merge($sanitized);
}
public static function array_strip_tags($array)
{
$result = array();
foreach ($array as $key => $value) {
// Don't allow tags on key either, maybe useful for dynamic forms.
$key = strip_tags($key);
// If the value is an array, we will just recurse back into the
// function to keep stripping the tags out of the array,
// otherwise we will set the stripped value.
if (is_array($value)) {
$result[$key] = static::array_strip_tags($value);
} else {
// I am using strip_tags(), you may use htmlentities(),
// also I am doing trim() here, you may remove it, if you wish.
$result[$key] = trim(strip_tags($value));
}
}
return $result;
}
次に、このコードを before フィルターの先頭 (application/routes.php 内) に挿入します。
//Our own method to defend XSS attacks globally.
Common::global_xss_clean();