fix(serializer): accept union-typed IRI collections on denormalization#8339
Merged
soyuka merged 1 commit intoJun 22, 2026
Merged
Conversation
The type-confusion guard added in 6bcbeb2 (GHSA-9rjg-x2p2-h68h) validates an IRI's resolved resource against a single declared class via is_a(). For a collection typed array<Foo|Bar>, createAndValidateAttributeValue resolves one class for the whole collection (isSatisfiedBy short-circuits at the first union member), so an IRI pointing to the second member (/api/bars/2) is rejected and the whole collection fails - there is no union retry loop on the collection path (api-platform#8335). Validate the resolved item against the declared relation Type via Type::isSatisfiedBy instead of a single class string. The relation native type is threaded through context['relation_native_type']; the guard falls back to is_a() when absent, keeping the single-class and legacy-type paths unchanged. The security guard still rejects IRIs resolving outside the declared union. Sibling of api-platform#8329 (scalar union, fixed in api-platform#8333) on the collection path. Closes api-platform#8335
Member
Author
|
lowest failures are expected. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The type-confusion guard added in 6bcbeb2 (GHSA-9rjg-x2p2-h68h) validates an IRI's resolved resource against a single declared class via
is_a($item, $resourceClass).For a collection typed
array<Foo|Bar>,AbstractItemNormalizer::createAndValidateAttributeValueresolves one class for the whole collection —UnionType::isSatisfiedByshort-circuits at the first member, so$className = Foo. An IRI pointing to the second member (/api/bars/2) then resolves to aBar, failsis_a(Bar, Foo), and the whole collection is rejected with a misleading 422. Unlike the scalar union case, the collection path has no$isMultipleTypesretry loop, so there is no fallback.This is the sibling of #8329 (scalar union, fixed in #8333) on the collection path.
Fix
Validate the resolved item against the declared relation Type via
Type::isSatisfiedByinstead of a single class string — TypeInfo already models union/intersection membership, so no class list needs to be hand-rolled.The declared relation native type is threaded through
context['relation_native_type'](collection value type for collections,$tfor scalar relations).getResourceFromIriuses it when present and falls back tois_a()otherwise, leaving the single-class and legacy-type paths unchanged.The security guard still rejects an IRI whose resource resolves outside the declared union.
Tests
AbstractItemNormalizerTest::testUnionTypeCollectionDenormalizationAcceptsAnyMember— reproduces the exactarray<Foo|Bar>stack, fails before / passes after. Full Serializer component suite green (104 tests).tests/Functional/UnionIriCollectionTest— POSTs IRIs of each union member into anarray<Foo|Bar>collection, expects 201 with both resolved.