Twig has unguarded calls to `__toString()` when nesting an object into an array
Published 6 Nov 2024 · Updated 29 May 2025
Is your project on an affected twig/twig?
Affected packages
- Affected
- <3.11.2
- Fixed in
- 3.11.2
composer require twig/twig:^3.11.2- Affected
- >=3.12 <3.14.1
- Fixed in
- 3.14.1
composer require twig/twig:^3.14.1Details
Description
In a sandbox, an attacker can call __toString() on an object even if the __toString() method is not allowed by the security policy when the object is part of an array or an argument list (arguments to a function or a filter for instance).
Resolution
The sandbox mode now checks the __toString() method call on all objects.
The patch for this issue is available here for the 3.11.x branch, and here for the 3.x branch.
Credits
We would like to thank Jamie Schouten for reporting the issue and Fabien Potencier for providing the fix.
Is GHSA-6377-hfv9-hqf6 in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected twig/twig, and gives you the command that fixes it.
More advisories for twig/twig
- HighCVE-2026-49981Twig: Sandbox filter, tag and function allow-list bypass when sandbox state changes between renders for a cached `Template` · 1 Jul 2026
- MediumCVE-2026-48808Twig: Sandbox property allowlist bypass via the `column` filter under `SourcePolicyInterface` · 30 Jun 2026
- MediumCVE-2026-48807Twig: Sandbox `__toString()` policy bypass via `Traversable` in `join` and `replace` filters · 30 Jun 2026
- MediumCVE-2026-48806Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys · 30 Jun 2026
- LowCVE-2026-48805Twig: Sandbox state regression in deprecated internal wrappers in `src/Resources/core.php` · 30 Jun 2026
- HighCVE-2026-47732Twig: Sandbox: multiple `__toString()` policy bypasses via unguarded string coercion points · 5 Jun 2026
References
- Linkgithub.com/twigphp/Twig/security/advisories/GHSA-6377-hfv9-hqf6
- Advisorynvd.nist.gov/vuln/detail/CVE-2024-51754
- Linkgithub.com/twigphp/Twig/commit/2bb8c2460a2c519c498df9b643d5277117155a73
- Linkgithub.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2024-51754.yaml
- Packagegithub.com/twigphp/Twig
- Linklists.debian.org/debian-lts-announce/2025/05/msg00039.html
- Linksymfony.com/blog/unguarded-calls-to-__tostring-when-nesting-an-object-into-an-array
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.