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 Eloquent's create()
method to insert data into database ($fillable
/$guarded
properties are set in the models). As it turns out, I can freely put something like this in any form's text input:
<script>alert('Hacking Sony in 3...2...')</script>
and the value will be inserted in the database. Then, when echo
ing it - the alert is shown.
Possible solutions
Now, Laravel is a really nice framework, so I would assume there must be something to prevent XSS out of the box. However, I can't find out what that is.
If I'm wrong, what is the optimal way to handle the issue?
- Do I use fancy regex validation to disallow specific characters?
- Do I use
mysql_real_escape_string()
on every Input::get()
I use?
- Do I
strip_tags()
?
View-level escaping is not enough
I know I can use Blade's triple curly brackets to escape strings in the views, that's not the point, though. Makes much more sense to me not to let those sneaky bastards into the database in the first place.
Anyone faced this problem already?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…