diff --git a/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php b/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php
index ff2a03d26deae9f263fbb9f967456a7a7a07b3a9..d1b209a4a3f28dddfbd4e4aa8767d5691bc31e08 100644
--- a/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php
+++ b/lib/classes/JsonApi/JsonApiIntegration/QueryChecker.php
@@ -104,15 +104,15 @@ class QueryChecker
 
     protected function checkSorting(ErrorCollection $errors, QueryParserInterface $queryParser): void
     {
-        if (null !== $queryParser->getSorts() && null !== $this->sortParameters) {
-            foreach ($queryParser->getSorts() as $sortParameter) {
-                if (!array_key_exists($sortParameter->getField(), $this->sortParameters)) {
-                    $errors->addQueryParameterError(
-                        QueryParser::PARAM_SORT,
-                        sprintf('Sort parameter %s is not allowed.', $sortParameter->getField())
-                    );
-                }
-            }
+        $withinAllowed = $this->keysWithinAllowed(
+            iterator_to_array($queryParser->getSorts()),
+            $this->sortParameters
+        );
+        if (!$withinAllowed) {
+            $errors->addQueryParameterError(
+                QueryParser::PARAM_SORT,
+                'Sort parameter should contain only allowed values.'
+            );
         }
     }