How do you think about security in laravel 4 ? I mean how laravel is managing xss attacks ?
In codeigniter you have someting like xss_clean($_GET['yourValue']) to clean user input fom xss code.
How laravel manage those kind of problems ? You get user values using Input::get('yourValue') but how do you apply an xss filter to it ? It comes with this functionality out of the box or what ?
Laravel Middleware to protect your app against Cross-site scripting (XSS). It sanitizes request input by utilising the Laravel Security package, and it can sanatize Blade echo statements as well.
XSS filters work by finding typical patterns that may be used as XSS attack vectors and removing such code fragments from user input data. Patterns are most often found using regular expressions.
It enables attackers to bypass client-side security mechanisms normally imposed on web content by modern web browsers by injecting malicious script into web pages viewed by other users.
The following suggestions can help safeguard your users against XSS attacks: Sanitize user input: Validate to catch potentially malicious user-provided input. Encode output to prevent potentially malicious user-provided data from triggering automatic load-and-execute behavior by a browser.
You can use App::before
event to filter all of your inputs like this
App::before(function($request)
{
Input::merge(array_strip_tags(Input::all()));
}
The array_strip_tags
function is given below, I've put it in a helper file to call it directly, you may use it as a helper function or as a library but it's easy to use it as a helper function, just create a helper file inside app/start/
folder and give it a name, for example custom_helper.php
and include it inside global.php
file like this
require '/custom_helpers.php';
Function array_strip_tags
function array_strip_tags($array)
{
$result = array();
foreach ($array as $key => $value) {
$key = strip_tags($key);
if (is_array($value)) {
$result[$key] = array_strip_tags($value);
}
else {
$result[$key] = strip_tags($value);
}
}
return $result;
}
This is copied from an working project of mine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With