GHSA-pr2w-4gpj-cpq4: Twig: Sandbox: multiple `__toString()` policy bypasses via unguarded string coercion points
Summary
Twig's sandbox (a security feature that restricts what templates can do) had multiple vulnerabilities where certain language constructs could bypass security checks and call `__toString()` methods (special functions that convert objects to strings) on objects without permission. Attackers could exploit this through conditional expressions, comparison operators, tests, and several other Twig features to access object data that should have been blocked.
Solution / Mitigation
The sandbox was fixed by wrapping every child node that will be converted to a string at runtime. A new `Twig\Node\CoercesChildrenToStringInterface` allows nodes to declare which children need protection, core nodes now implement this interface, spread arguments are checked via `SandboxExtension::ensureSpreadAllowed()`, and dynamic attribute names are checked at runtime inside `CoreExtension::getAttribute()`.
Vulnerability Details
EPSS: 0.0%
Yes
June 5, 2026
Classification
Affected Packages
Original source: https://github.com/advisories/GHSA-pr2w-4gpj-cpq4
First tracked: June 5, 2026 at 08:00 PM
Classified by LLM (prompt v3) · confidence: 95%