[Mime][String] Reject objects in typed-string properties during __unserialize#64345
Merged
nicolas-grekas merged 1 commit intoMay 23, 2026
symfony:7.4symfony/symfony:7.4from
nicolas-grekas:harden-unserialize-trampolines-7.4nicolas-grekas/symfony:harden-unserialize-trampolines-7.4Copy head branch name to clipboard
Merged
[Mime][String] Reject objects in typed-string properties during __unserialize#64345nicolas-grekas merged 1 commit intosymfony:7.4symfony/symfony:7.4from nicolas-grekas:harden-unserialize-trampolines-7.4nicolas-grekas/symfony:harden-unserialize-trampolines-7.4Copy head branch name to clipboard
nicolas-grekas merged 1 commit into
symfony:7.4symfony/symfony:7.4from
nicolas-grekas:harden-unserialize-trampolines-7.4nicolas-grekas/symfony:harden-unserialize-trampolines-7.4Copy head branch name to clipboard
Conversation
41893d3 to
d64ccd7
Compare
This was referenced May 27, 2026
Merged
Merged
Merged
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.
Same class of issue as #64343 on 6.4: a
__unserialize(array $data)that assigns$data[...]to a typedstring(or union-with-string) property lets PHP's type coercion invoke__toString()on any attacker-supplied object before the value is stored. A post-assignmentis_string()guard runs too late.This PR covers the surface that exists on 7.4 and is not addressed in #64343:
$dataString\UnicodeStringstring $stringMime\Part\TextPart?string $charset,string $subtype,?string $disposition,?string $name,string $encodingMime\Part\SMimePartiterable|string $body,string $type,string $subtypeUnion types that include
string(e.g.iterable|string) also trigger__toString()coercion; forSMimePart::$bodythe guard isinstanceof \Stringable && !is_iterable($body)since PHP prefers the iterable branch when an object satisfies both.Each
__unserialize()now validates the shape of the raw$databefore any assignment, throwingBadMethodCallExceptionon mismatch.UnicodeString's existing post-check is moved to run before the assignment;TextPartandSMimePartgain explicit pre-checks for every typed-string slot (in every key-prefix variant: bare,\0Class\0..., and\0*\0...).The 6.4 hardening for
Route,CompiledRoute,Window,SlidingWindow,TokenBucket, andEmaillands on 7.4 via the upmerge.