Laravel Validation And User Input Sanitization To Prevent XSS Exploits

Submitted by azazqadir - 10 months ago

XSS Exploit is a well-known vulnerability in a web app whereby an attacker can inject client-side code into a web page. This is can be done through user input areas such as search boxes, comments, posts, etc. Source: http://www.cloudways.com/blog/prevent-xss-exploits-using-laravel-validation-and-sanitization/

// Display All Tasks 
Route::get('/', function () {
   $tasks = Task::orderBy('created_at', 'asc')->get();
 
   return view('tasks', [
       'tasks' => $tasks
   ]);
});
 
// Add A New Task
Route::post('/task', function (Request $request) {
   $task = new Task;
   $task->name = $request->name;
   $task->save();
 
   return redirect('/');
});
 
// Delete An Existing Task
Route::delete('/task/{id}', function ($id) {
   Task::findOrFail($id)->delete();
 
   return redirect('/');
});
comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks