Skip to content

Commit

Permalink
fix(EntityListManager): Validate ordering field name before QueryBuil…
Browse files Browse the repository at this point in the history
…der rejects it
  • Loading branch information
ambroisemaupate committed Sep 13, 2023
1 parent cf17707 commit 76cc4b4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,12 @@ public function getPageCount(): int
{
return (int) ceil($this->getItemCount() / $this->getItemPerPage());
}

protected function validateOrderingFieldName(string $field): void
{
// check if field is a valid name without any SQL injection
if (\preg_match('/^[a-zA-Z0-9_.]+$/', $field) !== 1) {
throw new \InvalidArgumentException('Field name is not valid.');
}
}
}
1 change: 1 addition & 0 deletions lib/RoadizCoreBundle/src/ListManager/EntityListManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public function handle(bool $disabled = false)
$this->request->query->get('field') &&
$this->request->query->get('ordering')
) {
$this->validateOrderingFieldName($this->request->query->get('field'));
$this->orderingArray = [
$this->request->query->get('field') => $this->request->query->get('ordering')
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function handle(bool $disabled = false)
$this->request->query->get('field') &&
$this->request->query->get('ordering')
) {
$this->validateOrderingFieldName($this->request->query->get('field'));
$this->queryBuilder->addOrderBy(
sprintf('%s.%s', $this->identifier, $this->request->query->get('field')),
$this->request->query->get('ordering')
Expand Down

0 comments on commit 76cc4b4

Please sign in to comment.