Skip to content

Commit 8cb817f

Browse files
committed
ElementHelper::cleanseQueryCriteria()
1 parent e1c226e commit 8cb817f

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
> Relational condition rules’ element ID templates are now rendered in a sandboxed Twig environment, when `enableTwigSandbox` is enabled.
77
88
- The `create()` Twig function now allows `craft\helpers\` classes to be created. ([#18376](https://github.com/craftcms/cms/discussions/18376))
9+
- Added `craft\helpers\ElementHelper::cleanseQueryCriteria()`.
910
- Fixed an error that could occur when editing an element with a Table field. ([#18408](https://github.com/craftcms/cms/pull/18408))
1011
- Fixed a [high-severity](https://github.com/craftcms/cms/security/policy#severity--remediation) RCE vulnerability. (GHSA-fp5j-j7j4-mcxc)
1112

src/controllers/ElementIndexesController.php

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -605,20 +605,7 @@ protected function elementQuery(): ElementQueryInterface
605605
}
606606

607607
// Remove unsupported criteria attributes
608-
unset(
609-
$criteria['where'],
610-
$criteria['orderBy'],
611-
$criteria['indexBy'],
612-
$criteria['select'],
613-
$criteria['selectOption'],
614-
$criteria['from'],
615-
$criteria['groupBy'],
616-
$criteria['join'],
617-
$criteria['having'],
618-
$criteria['union'],
619-
$criteria['withQueries'],
620-
$criteria['params'],
621-
);
608+
ElementHelper::cleanseQueryCriteria($criteria);
622609

623610
Craft::configure($query, Component::cleanseConfig($criteria));
624611
}

src/helpers/ElementHelper.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,4 +840,28 @@ public static function searchableAttributes(ElementInterface $element): array
840840
}
841841
return array_keys($searchableAttributes);
842842
}
843+
844+
/**
845+
* Removes values from a posted element query criteria, which would typically not be user-editable.
846+
*
847+
* @since 4.17.4
848+
*/
849+
public static function cleanseQueryCriteria(array $criteria): array
850+
{
851+
unset(
852+
$criteria['where'],
853+
$criteria['orderBy'],
854+
$criteria['indexBy'],
855+
$criteria['select'],
856+
$criteria['selectOption'],
857+
$criteria['from'],
858+
$criteria['groupBy'],
859+
$criteria['join'],
860+
$criteria['having'],
861+
$criteria['union'],
862+
$criteria['withQueries'],
863+
$criteria['params'],
864+
);
865+
return $criteria;
866+
}
843867
}

0 commit comments

Comments
 (0)