Skip to content

fix(symfony): security regression when ResourceAccessChecker is decorated (#7896)#7897

Open
giosh94mhz wants to merge 1 commit intoapi-platform:4.3from
giosh94mhz:security_object_regression
Open

fix(symfony): security regression when ResourceAccessChecker is decorated (#7896)#7897
giosh94mhz wants to merge 1 commit intoapi-platform:4.3from
giosh94mhz:security_object_regression

Conversation

@giosh94mhz
Copy link
Copy Markdown
Contributor

@giosh94mhz giosh94mhz commented Mar 31, 2026

Q A
Branch? 4.3
Tickets Closes #7896
License MIT
Doc PR

Commit 359a128 introduced a regression when ResourceAccessChecker is decorated, and security/securityPostDenormalize are using object in is_granted expression.

The issue arise since AccessCheckerProvider violates the Liskov substitution principle by assuming that if the (previously unknown) interface ObjectVariableCheckerInterface is not defined, then the pre_read optimization can be used without an object instance.

NOTE: this is a security evaluation regression that actually will blocks more then required, so not a security issue on the project itself.

The solution (in addition to this PR)

To preserve the implementation I had to implement ObjectVariableCheckerInterface in my codebased (which is not optimal, maybe should be documented or refactored). This is a workaround also for versions 4.3.0 => 4.3.3.

<?php

namespace Acme\ApiPlatform;

use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
use ApiPlatform\Symfony\Security\ObjectVariableCheckerInterface;

/** @note the references to `ObjectVariableCheckerInterface` and `usesObjectVariable` */
readonly class ResourceAccessCheckerDecorator implements ResourceAccessCheckerInterface, ObjectVariableCheckerInterface
{
    public function __construct(
        private ResourceAccessCheckerInterface&ObjectVariableCheckerInterface $resourceAccessChecker
    )
    {}

    public function isGranted(string $resourceClass, string $expression, array $extraVariables = []): bool
    {
        $extraVariables['my'] = $things;

        return $this->resourceAccessChecker->isGranted($resourceClass, $expression, $extraVariables);
    }

    public function usesObjectVariable(string $expression, array $variables = []): bool
    {
        $variables['my'] = null;
        return $this->resourceAccessChecker->usesObjectVariable($expression, $variables);
    }
}

@giosh94mhz giosh94mhz changed the base branch from main to 4.3 March 31, 2026 10:54
…ated (api-platform#7896)

Commit 359a128 introduced a regression
when ResourceAccessChecker is decorated, and
security/securityPostDenormalize are using object in is_granted
expression.

The issue arise since AccessCheckerProvider violates the Liskov
substitution principle by assuming that if the (previously unknown)
interface ObjectVariableCheckerInterface is not defined, then the
pre_read optimization can be used without an object instance.
@giosh94mhz giosh94mhz force-pushed the security_object_regression branch from 817d0e4 to 0e709bb Compare March 31, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression 4.3: Symfony security is called with null object

2 participants