Proper data binding prevents injection. Stripping tags prevents XSS http://php.net/manual/en/function.strip-tags.php Using the CSRF token prevents CSRF.
Do we need to validate user input using regex to prevent SQL injection?
I was reading this article:
https://www.cloudways.com/blog/prevent-xss-exploits-using-laravel-validation-and-sanitization/
This guy tells to prevent user from inputting malicious code in posts or comment etc it's advisable to use regex in the validation like this:
'names' => 'required|max:255|regex:[A-Za-z1-9 ]',
In my code I have a comment controller that I was validating like this:
$rules = array(
'post_id' => 'required',
'body' => 'required'
);
I tried to input this code in the post <script>alert("boom")</script> and the result is that the post succeed but empty so I guess laravel is deleting that input.
Am I right or am I missing something?
Anyway I changed the rules to:
$rules = array(
'post_id' => 'required|integer',
'body' => 'required|regex:[A-Za-z1-9 ]'
);
And post doesn't work anymore. I get "undefined", removing regex from validation makes it work again.
Please or to participate in this conversation.