Skip to content

Commit

Permalink
fix: fixed invalid ordering errors
Browse files Browse the repository at this point in the history
  • Loading branch information
righel committed Sep 11, 2023
1 parent 53e16ce commit d6ad402
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions app/Model/AppModel.php
Expand Up @@ -3989,4 +3989,32 @@ public function _remoteIp()
}
return $_SERVER['REMOTE_ADDR'] ?? null;
}

public function find($type = 'first', $query = array()) {
if (!empty($query['order']) && $this->validOrderClause($query['order']) === false) {
throw new InvalidArgumentException('Invalid order clause');
}

return parent::find($type, $query);
}

private function validOrderClause($order){
$pattern = '/^[\w\_\-\.\(\) ]+$/';
if(is_string($order) && preg_match($pattern, $order)){
return true;
}

if (is_array($order)) {
foreach ($order as $key => $value) {
if (is_string($key) && is_string($value) && preg_match($pattern, $key) && in_array(strtolower($value), ['asc', 'desc'])) {
return true;
}
if(is_numeric($key) && is_string($value) && preg_match($pattern, $value)){
return true;
}
}
}

return false;
}
}

0 comments on commit d6ad402

Please sign in to comment.