Skip to content

Commit

Permalink
Improve filter validation
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Aug 19, 2024
1 parent 5b99e71 commit 8fc2c6a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Validator/RequestValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ private function validateLimit(Request $request): void
private function validateFilters(Request $request): void
{
// this will throw if the filters parameter is not an array
$request->query->all('filters');
/** @var array<string, array<array-key, array{code?: string, value?: string}>> $allFiltersByType */
$allFiltersByType = $request->query->all('filters');
foreach ($allFiltersByType as $filtersByType) {
foreach ($filtersByType as $filter) {
if (!array_key_exists('code', $filter) ||
!array_key_exists('value', $filter) ||
$filter['code'] === '' ||
$filter['value'] === ''
) {
throw new BadRequestException('Invalid filter format');
}
}
}
}
}

0 comments on commit 8fc2c6a

Please sign in to comment.