Skip to content

Commit 58938e2

Browse files
committed
Really sanitize orderBy and groupBy values
1 parent 1548e29 commit 58938e2

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

MysqliDb.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public function orderBy($orderByField, $orderbyDirection = "DESC")
339339
{
340340
$allowedDirection = Array ("ASC", "DESC");
341341
$orderbyDirection = strtoupper (trim ($orderbyDirection));
342-
$orderByField = filter_var($orderByField, FILTER_SANITIZE_STRING);
342+
$orderByField = preg_replace ("/[^-a-z0-9\.\(\),]+/i",'', $orderByField);
343343

344344
if (empty($orderbyDirection) || !in_array ($orderbyDirection, $allowedDirection))
345345
die ('Wrong order direction: '.$orderbyDirection);
@@ -359,7 +359,7 @@ public function orderBy($orderByField, $orderbyDirection = "DESC")
359359
*/
360360
public function groupBy($groupByField)
361361
{
362-
$groupByField = filter_var($groupByField, FILTER_SANITIZE_STRING);
362+
$groupByField = preg_replace ("/[^-a-z0-9\.\(\),]+/i",'', $groupByField);
363363

364364
$this->_groupBy[] = $groupByField;
365365
return $this;

tests.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function createTable ($name, $data) {
181181

182182
$db->join("users u", "p.userId=u.id", "LEFT");
183183
$db->where("u.login",'user2');
184+
$db->orderBy("CONCAT(u.login, u.firstName)");
184185
$products = $db->get ("products p", null, "u.login, p.productName");
185186
if ($db->count != 2) {
186187
echo "Invalid products count on join ()";

0 commit comments

Comments
 (0)