Commit de2a7ab
committed
bug symfony#60296 [Serializer] Handle invalid mapping type property type (KorvinSzanto)
This PR was squashed before being merged into the 7.2 branch.
Discussion
----------
[Serializer] Handle invalid mapping type property type
| Q | A
| ------------- | ---
| Branch? | 7.2
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues |
| License | MIT
When using `#[MapRequestPayload]` along with a type that uses a `#[DescriminatorMap]` it's possible for a user to craft a payload that triggers a `TypeError` by passing the wrong type for the "type" property.
For example, a class that has:
```php
#[DiscriminatorMap('field', ['a' => AController::class, 'b' => BController::class])]
```
and a request comes in with:
```
Content-Type: application/json
{"field":{}}
```
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.
Commits
-------
6ab0182 [Serializer] Handle invalid mapping type property typeFile tree
4 files changed
+73
-1
lines changed- src/Symfony/Component/Serializer
- Normalizer
- Tests
- Fixtures/Attributes
- Normalizer
4 files changed
+73
-1
lines changedLines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1184 | 1184 | | |
1185 | 1185 | | |
1186 | 1186 | | |
| 1187 | + | |
| 1188 | + | |
| 1189 | + | |
| 1190 | + | |
1187 | 1191 | | |
1188 | 1192 | | |
1189 | 1193 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
Lines changed: 67 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
531 | 598 | | |
532 | 599 | | |
533 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
455 | | - | |
| 455 | + | |
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
| |||
0 commit comments