-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Handle invalid mapping type property type #60296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 7.2
Are you sure you want to change the base?
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
355794e
to
ebad77f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test case for this?
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
$discriminatorResolver = new ClassDiscriminatorFromClassMetadata($loaderMock); | ||
$normalizer = new AbstractObjectNormalizerDummy($factory, null, new PhpDocExtractor(), $discriminatorResolver); | ||
$serializer = new Serializer([$normalizer]); | ||
$normalizer->setSerializer($serializer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes a denormalizer is required
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KorvinSzanto can you please check pending comments?
When using
#[MapRequestPayload]
along with a type that uses a#[DescriminatorMap]
it's possible for a user to craft a payload that triggers aTypeError
by passing the wrong type for the "type" property.For example, a class that has:
and a request comes in with:
will trigger a 500 because
AbstractObjectNormalizer
doesn't validate the field type before passing it to->getClassForType
which typehints for string.This PR adds a conditional that filters anything other than strings or objects that have a __toString method.