Answer the question
In order to leave comments, you need to log in
Yii2, how to deal with XSS correctly?
The thing is:
Let's say I have a SignupForm model, the rules are written in it, they say the login and password are required, trim it, etc. etc., but there is one hindrance:
When you enter the <script>alert("hacked");script> code into one of the fields (let's say in about) - it will go directly to the database, and then when we will display this field this user, then this alert will pop up on his page when visiting him. So far, I have solved this problem in a very noobish way, in all views I have written Html::encode() for each parameter (which is just like routine). But I'm more than sure that you can simply make sure that this data gets into the database already safe when entering data in the SignupForm model itself. How to do it professionally? Register a validator, perhaps? I would like a correct example, thanks
Answer the question
In order to leave comments, you need to log in
public function rules()
{
return [
['field1','field2'],'filter','filter'=>'\yii\helpers\HtmlPurifier::process']
];
}
so far I have solved this problem in a very noob way, in all views I have written Html::encode()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question