I don't know how it would be - the perPage value is cast as an int in the limit operation; and mathematical operation in take operation will not pass thru non-numeric values.
Apr 5, 2022
28
Level 1
Is QueryBuilder's paginate() method vulnerable to SQL injection ?
Recently, I've been working on a project that involves fetching data from a database using QueryBuilder class using the following code:
$page = $request->page;
$perpage = $request->perpage;
$builder = DB::table('users');
$builder->orderByDesc("id");
$builder->whereNull("deleted_at");
if ($request->has("keyword")) {
$search = $request->keyword;
$builder->where(function ($builder) use ($search) {
$builder->where("id", $search);
$builder->orWhere("fullname", "LIKE", "%" . $search . "%");
$builder->orWhere("email", "LIKE", "%" . $search . "%");
$builder->orWhere("mobile_number", "LIKE", "%" . $search . "%");
});
}
$users = $builder->paginate(page: $page, perPage: $perpage);
However, during the penetration testing, the report says that perPage parameter is vulnerable to SQL injection vulnerability
Can this really happen here or Laravel would escape the values ?
Thanks in advance
Please or to participate in this conversation.