Skip to content

Commit f278004

Browse files
committed
bug #7555 Add authorization checks to the renderFilters() action (javiereguiluz)
This PR was merged into the 4.x branch. Discussion ---------- Add authorization checks to the renderFilters() action Similar to #7548 and the fix is the same. Commits ------- be7b6c4 Add authorization checks to the renderFilters() action
2 parents f231f15 + be7b6c4 commit f278004

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/Controller/AbstractCrudController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,12 @@ public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityD
556556

557557
public function renderFilters(AdminContext $context): KeyValueStore
558558
{
559+
// not a typo; the filter form is a sub-component of the INDEX page,
560+
// so we reuse the INDEX action for permission checks here
561+
if (!$this->isGranted(Permission::EA_EXECUTE_ACTION, ['action' => Action::INDEX, 'entity' => null, 'entityFqcn' => $context->getEntity()->getFqcn()])) {
562+
throw new ForbiddenActionException($context);
563+
}
564+
559565
$fields = new FieldCollection($this->configureFields(Crud::PAGE_INDEX));
560566
$this->container->get(FieldFactory::class)->processFields($context->getEntity(), $fields, Crud::PAGE_INDEX);
561567
$filters = $this->container->get(FilterFactory::class)->create($context->getCrud()->getFiltersConfig(), $context->getEntity()->getFields(), $context->getEntity());

tests/Functional/Security/RolePermissionTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,40 @@ public static function provideRolesForAutocompleteAction(): \Generator
170170
yield 'admin role can access autocomplete with INDEX permission' => ['admin', Response::HTTP_OK];
171171
yield 'super_admin role can access autocomplete with INDEX permission' => ['super_admin', Response::HTTP_OK];
172172
}
173+
174+
/**
175+
* @dataProvider provideRolesForRenderFiltersAction
176+
*/
177+
public function testRenderFiltersActionPermission(string $username, int $expectedStatusCode): void
178+
{
179+
if (Response::HTTP_FORBIDDEN === $expectedStatusCode) {
180+
$this->expectException(ForbiddenActionException::class);
181+
$this->client->catchExceptions(false);
182+
}
183+
184+
$renderFiltersUrl = $this->getCrudUrl(
185+
'renderFilters',
186+
null,
187+
[],
188+
SecuredDashboardController::class,
189+
ProtectedCategoryCrudController::class,
190+
);
191+
192+
$this->client->request(
193+
'GET',
194+
$renderFiltersUrl,
195+
[],
196+
[],
197+
['PHP_AUTH_USER' => $username, 'PHP_AUTH_PW' => '1234']
198+
);
199+
200+
static::assertResponseStatusCodeSame($expectedStatusCode);
201+
}
202+
203+
public static function provideRolesForRenderFiltersAction(): \Generator
204+
{
205+
yield 'user role cannot access renderFilters without INDEX permission' => ['user', Response::HTTP_FORBIDDEN];
206+
yield 'admin role can access renderFilters with INDEX permission' => ['admin', Response::HTTP_OK];
207+
yield 'super_admin role can access renderFilters with INDEX permission' => ['super_admin', Response::HTTP_OK];
208+
}
173209
}

0 commit comments

Comments
 (0)