Skip to content

Allow config option to throw 403 when securityPostDenormalize fails for an API propertyΒ #7198

Closed
@dwgebler

Description

@dwgebler

Description
At the moment, when implementing securityPostDenormalize at the property level in a POST, PATCH or PUT request, if a field is in the request body for which the user does not meet the security expression, the field is silently reverted to its previous or default value in AbstractItemNormalizer:

        foreach (array_keys($data) as $attribute) {
            $attribute = $this->nameConverter ? $this->nameConverter->denormalize((string) $attribute) : $attribute;
            if (!\in_array($attribute, $propertyNames, true)) {
                continue;
            }

            if (!$this->canAccessAttributePostDenormalize($object, $previousObject, $attribute, $context)) {
                if (null !== $previousObject) {
                    $this->setValue($object, $attribute, $this->propertyAccessor->getValue($previousObject, $attribute));
                } else {
                    $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $attribute, $options);
                    $this->setValue($object, $attribute, $propertyMetadata->getDefault());
                }
            }
        }

It might be good if we had a config option in the package api_platform.yaml or in the ApiProperty attribute to instead instruct API Platform to throw an appropriate exception and return a 403 or maybe 422 in these cases, depending on use-case.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions