Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Mime][String] Reject objects in typed-string properties during __unserialize#64345

Merged
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
May 23, 2026
Merged

[Mime][String] Reject objects in typed-string properties during __unserialize#64345
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

@nicolas-grekas
Copy link
Copy Markdown
Member

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

Same class of issue as #64343 on 6.4: a __unserialize(array $data) that assigns $data[...] to a typed string (or union-with-string) property lets PHP's type coercion invoke __toString() on any attacker-supplied object before the value is stored. A post-assignment is_string() guard runs too late.

This PR covers the surface that exists on 7.4 and is not addressed in #64343:

Class Typed-string slots assigned from raw $data
String\UnicodeString string $string
Mime\Part\TextPart ?string $charset, string $subtype, ?string $disposition, ?string $name, string $encoding
Mime\Part\SMimePart iterable|string $body, string $type, string $subtype

Union types that include string (e.g. iterable|string) also trigger __toString() coercion; for SMimePart::$body the guard is instanceof \Stringable && !is_iterable($body) since PHP prefers the iterable branch when an object satisfies both.

Each __unserialize() now validates the shape of the raw $data before any assignment, throwing BadMethodCallException on mismatch. UnicodeString's existing post-check is moved to run before the assignment; TextPart and SMimePart gain 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, and Email lands on 7.4 via the upmerge.

@carsonbot carsonbot added this to the 7.4 milestone May 23, 2026
@carsonbot carsonbot changed the title [String][Mime] Reject objects in typed-string properties during __unserialize [Mime][String] Reject objects in typed-string properties during __unserialize May 23, 2026
@nicolas-grekas nicolas-grekas force-pushed the harden-unserialize-trampolines-7.4 branch from 41893d3 to d64ccd7 Compare May 23, 2026 15:23
@nicolas-grekas nicolas-grekas merged commit 2a61eaf into symfony:7.4 May 23, 2026
4 of 14 checks passed
This was referenced May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.