Description
API Platform version(s) affected: >=3.1.0
Description
I don't really know if it's a bug, but in the AccessCheckerProvider, the provider is executed before any security check. I may have missed something, but IMHO, we may have:
- a security failure if the provider is executing something the user is not allowed to do.
- a perf killer if the provider is executing long stuff whereas in the end, the response will be "you can't access this endpoint"
So I have to rewrite the security in some of my providers to check the access rights in order to avoid what I mentioned above
How to reproduce
Any code such as this small one:
#[ApiResource(
operations: [
new GetCollection(
security: 'is_granted("TEST")',
provider: TestProvider:class,
),
]
)]
class Test
{
}
Possible Solution
In AccessCheckerProvider.php, this line is executed before any security check:
$body = $this->decorated->provide($operation, $uriVariables, $context);
By the way, I really don't know the impacts for this part a few lines below :(
if (!$this->resourceAccessChecker->isGranted($operation->getClass(), $isGranted, $resourceAccessCheckerContext)) {
Additional Context