{"id":"CVE-2024-51754","aliases":["GHSA-6377-hfv9-hqf6"],"url":"https://o3.security/vulnerability/CVE-2024-51754","summary":"Unguarded calls to __toString() when nesting an object into an array in Twig","details":"### Description\n\nIn 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).\n\n### Resolution\n\nThe sandbox mode now checks the `__toString()` method call on all objects.\n\nThe patch for this issue is available [here](https://github.com/twigphp/Twig/commit/cafc608ece310e62a35a76f17e25c04ab9ed05cc) for the 3.11.x branch, and [here](https://github.com/twigphp/Twig/commit/d4a302681bca9f7c6ce2835470d53609cdf3e23e) for the 3.x branch.\n\n### Credits\n\nWe would like to thank Jamie Schouten for reporting the issue and Fabien Potencier for providing the fix.","published":"2024-11-06T19:28:17.553Z","modified":"2026-08-12T03:51:40.300372351Z","cvss":{"score":2.2,"severity":"LOW","vector":"CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N"},"epss":{"score":0.00444,"percentile":0.36556,"asOf":"2026-08-08"},"cisaKev":null,"exploitsKnown":0,"affectedPackages":[{"ecosystem":"Packagist","name":"twig/twig","fixedVersion":"3.11.2"},{"ecosystem":"Packagist","name":"twig/twig","fixedVersion":"3.14.1"}],"fix":{"url":"https://github.com/twigphp/Twig/commit/2bb8c2460a2c519c498df9b643d5277117155a73","label":"twigphp/Twig@2bb8c24"},"references":[{"type":"WEB","url":"https://lists.debian.org/debian-lts-announce/2025/05/msg00039.html"},{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2024/51xxx/CVE-2024-51754.json"},{"type":"ADVISORY","url":"https://github.com/twigphp/Twig/security/advisories/GHSA-6377-hfv9-hqf6"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-51754"},{"type":"FIX","url":"https://github.com/twigphp/Twig/commit/2bb8c2460a2c519c498df9b643d5277117155a73"},{"type":"WEB","url":"https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2024-51754.yaml"},{"type":"PACKAGE","url":"https://github.com/twigphp/Twig"},{"type":"WEB","url":"https://symfony.com/blog/unguarded-calls-to-__tostring-when-nesting-an-object-into-an-array"}],"provenance":{"sources":["OSV.dev","FIRST.org (EPSS)"],"lastVerified":"2026-08-12T03:51:40.300372351Z"}}