Embedded resources reuse the parent's attribute cache key, bypassing property security for secured children
Description
AbstractItemNormalizer::normalize() only computes the serializer cache_key when none is present in the context:
if (!isset($context['cache_key'])) {
$context['cache_key'] = $this->isCacheKeySafe($context) ? $this->getCacheKey($format, $context) : false;
}Child contexts created for embedded relations inherit the parent's cache_key (Symfony AbstractObjectNormalizer::createChildContext() appends -attr), so isCacheKeySafe() never runs for the embedded resource class. When the parent has no secured property and the embedded resource has a property guarded by ApiProperty(security:) or ApiProperty(policy:), the list of allowed attributes computed for the first embedded object is cached and reused for the following ones.
The same guard exists in the JSON:API (src/JsonApi/Serializer/ItemNormalizer.php) and HAL (src/Hal/Serializer/ItemNormalizer.php) item normalizers.
Impact
- Any runtime, including PHP-FPM, single request: all elements of one embedded to-many relation share the decision taken for the first element. A user reading a parent can see an object-level secured property of a child they do not own.
- Long-running runtimes (FrankenPHP worker mode, RoadRunner, Swoole): the cache entry outlives the request, so the decision taken for one user is served to another user requesting the same parent IRI.
The root-class check fixed in GHSA-cwhh-732q-p35c (5248f9a02) does not cover embedded children.
Reproduction (to be turned into a functional test)
A parent resource without secured properties, with a to-many relation to a child resource exposing #[ApiProperty(security: "object.owner == user.getUserIdentifier()")] $secret in the parent's read group. Child c1 owned by dunglas, c2 owned by admin. GET the parent as dunglas: children[1].secret is present, expected absent.
Patches
When cache_key is inherited, still evaluate isCacheKeySafe() for the current resource class and disable the cache when it is not safe, in AbstractItemNormalizer, the JSON:API and HAL item normalizers.
Workarounds
None at configuration level besides avoiding property-level security/policy on resources that are embedded in other resources.
Found internally while auditing request-scoped state for GHSA-xmq6-3c6q-fr8m.