How and where can XSS protection be applied in Laravel?

前端 未结 6 1964
孤城傲影
孤城傲影 2020-12-14 19:08

I wonder how (if anyhow) is XSS protection provided in Laravel. I couldn\'t find anything about it in the documentation.

Problem

I am using

6条回答
  •  情深已故
    2020-12-14 19:43

    You also filter input before validation like, First create /app/Common/Utility.php

     $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;
        }
    }
    

    And use in your controller like this

    use App\Common\Utility;
    public function store()
    {
        Utility::stripXSS();
        // Remaining Codes
    }
    

    This code will clean your input before validation

提交回复
热议问题