Closed
Description
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.