CVE-2024-51754
Unguarded calls to __toString() when nesting an object into an array in Twig
Reported by github_m · Published November 6, 2024
twig/twig is fixed in 3.14.1 and 3.11.2 (Packagist)
Twig is a template language for PHP. 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). This issue has been patched in versions 3.11.2 and 3.14.1. All users are advised to upgrade. There are no known workarounds for this issue.
Fixed versions
Upgrade to a fixed version or later. Language registries are listed first, then Linux distributions, then vendor products.
| Package | Ecosystem | Fixed in |
|---|---|---|
| twig/twig | Packagist | 3.14.1, 3.11.2 |
Risk scores
Affected products
| Vendor | Product | Versions |
|---|---|---|
| twigphp | Twig | < 3.11.2, >= 3.12.0, < 3.14.1 |
| twig | twig | 0, 3.12 |
| twigphp | Twig | 0, 3.12.0 |
Timeline
- Nov 6, 2024 CVE Published
- Nov 6, 2024 Coalition ESS Score (16 in total, the first dated here)
- Nov 7, 2024 EPSS Score (30 in total, the first dated here)
- Jan 1, 2026 Security Advisory
- Jun 17, 2026 CVE Updated
Query this with the API
The same record, from the CLI:
vulnetix vdb vuln CVE-2024-51754
vulnetix vdb fixes CVE-2024-51754
Or with curl, using the org id and key from your account page:
curl -s -H "Authorization: ApiKey ${VULNETIX_ORG_ID}:${VULNETIX_API_KEY}" \
"https://api.vdb.vulnetix.com/v2/vuln/CVE-2024-51754/fixes/registry"
The Community plan is free and allows 50 queries a day. Get a free API key · API quickstart
References
- https://github.com/twigphp/Twig/security/advisories/GHSA-6377-hfv9-hqf6 x_refsource_CONFIRM
- https://github.com/twigphp/Twig/commit/2bb8c2460a2c519c498df9b643d5277117155a73 x_refsource_MISC
- https://lists.debian.org/debian-lts-announce/2025/05/msg00039.html url
- https://nvd.nist.gov/vuln/detail/CVE-2024-51754 advisory
- https://github.com/advisories/GHSA-6377-hfv9-hqf6 advisory
- https://github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2024-51754.yaml url
- https://github.com/twigphp/Twig url
- https://symfony.com/blog/unguarded-calls-to-__tostring-when-nesting-an-object-into-an-array url