How is the search implemented in the StudentController; it looks like you have missed an opportunity to properly sanitise and parameterize the user-provided search text?
I got sql injection attack for one of my routes in laravel
Hi guys, my routes are protected by spatie roles and permission. for example a route called student and protected by admin role as middleware. now the attacker tried to access this route and i got the following error through sentry. does it means he already has access to do the method in the controller ? because this method contains a scope search that was vulnerable for SQL injection.
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'll reply to your query as soon as possible, but this can take up to 48 hours. Al' at line 1
File "/app/Http/Controllers/StudentController.php", line 44, in App\Http\Controllers\StudentController::index
->paginate()
File "/public/index.php", line 51
$response = $kernel->handle(
...
(69 additional frame(s) were not displayed)
Illuminate\Database\QueryException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'll reply to your query as soon as possible, but this can take up to 48 hours. Al' at line 1 (SQL: select count(*)....
@demonz the middleware is intended to prevent access to the Route's action before it is executed, so auth and/or role middleware have been satisfied in this case, unless there is another unprotected route that delegates to StudentController@index?
Why do you think this action was malicious; do you know that it was not the SuperAdmin performing the action?
Aside, your whereRaw syntax does not parameterized the search, but you can modify it:
$search = "%{$search}%";
$query->whereRaw("CONCAT(first_name, ' ', second_name, ' ', last_name) LIKE ?", [
$search]);
Please or to participate in this conversation.