Skip to content

Commit

Permalink
Improve order validation in list_devices function to prevent SQL inje…
Browse files Browse the repository at this point in the history
…ction (#15885)
  • Loading branch information
Jellyfrog committed Apr 16, 2024
1 parent 36dc9d3 commit 83fe4b1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions includes/html/api_functions.inc.php
Expand Up @@ -313,12 +313,10 @@ function list_devices(Illuminate\Http\Request $request)
$query = $request->get('query');
$param = [];

if (empty($order)) {
$order = 'hostname';
}

if (stristr($order, ' desc') === false && stristr($order, ' asc') === false) {
$order = 'd.`' . $order . '` ASC';
if (preg_match('/^([a-z_]+)(?: (desc|asc))?$/i', $order, $matches)) {
$order = "d.`$matches[1]` " . ($matches[2] ?? 'ASC');
} else {
$order = 'd.`hostname` ASC';
}

$select = ' d.*, GROUP_CONCAT(dd.device_id) AS dependency_parent_id, GROUP_CONCAT(dd.hostname) AS dependency_parent_hostname, `location`, `lat`, `lng` ';
Expand Down

0 comments on commit 83fe4b1

Please sign in to comment.