CVE-2024-51754: Twig/twig Twig Has Unguarded Calls To Vulnerability
LOWCVE-2024-51754 is a LOW (CVSS 2.2) twig has unguarded calls to vulnerability (CWE-668: Exposure of Resource to Wrong Sphere) affecting Twig/twig libraries in the Packagist ecosystem. The issue involves twig has unguarded calls to `__tostring()` when nesting an object into an array. Remediation is available by upgrading affected packages to version 3.11.2, 3.14.1.
CVE-2024-51754 at a Glance
Security Impact
CVSS: 2.2
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N).
How to Fix CVE-2024-51754
To remediate this vulnerability, upgrade all affected Twig/twig dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade twig/twig to 3.11.2
Upgrade twig/twig to 3.14.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for twig/twig
How to Check if You Are Affected
To determine whether your application is affected by CVE-2024-51754, inspect your project dependencies for Twig/twig:
inspect dependencies for twig/twig
Analyze the terminal output to locate any version of Twig/twig in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.11.2), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-668: Exposure of Resource to Wrong Sphere, where the product exposes a resource to the wrong control sphere, providing unintended actors with inappropriate access to the resource. In Twig/twig, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2024-51754 Affected Twig/twig Versions
2 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
twig/twig
|
Packagist |
< 3.11.2
|
3.11.2
|
|
twig/twig
|
Packagist |
≥ 3.12
< 3.14.1
|
3.14.1
|
References
Frequently Asked Questions
What is CVE-2024-51754?
Which Twig/twig versions are affected?
What version fixes CVE-2024-51754?
Is twig/twig affected?
What is the CVSS score of CVE-2024-51754?
What CWE is associated with CVE-2024-51754?
How can I check Packagist dependencies for CVE-2024-51754?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-6377-hfv9-hqf6",
"modified" : "2025-05-29T21:02:01Z",
"published" : "2024-11-06T19:52:31Z",
"aliases" : [ "CVE-2024-51754" ],
"summary" : "Twig has unguarded calls to `__toString()` when nesting an object into an array",
"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.",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N"
}, {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:H/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "Packagist",
"name" : "twig/twig"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.11.2"
} ]
} ]
}, {
"package" : {
"ecosystem" : "Packagist",
"name" : "twig/twig"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "3.12"
}, {
"fixed" : "3.14.1"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"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" : "WEB",
"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://lists.debian.org/debian-lts-announce/2025/05/msg00039.html"
}, {
"type" : "WEB",
"url" : "https://symfony.com/blog/unguarded-calls-to-__tostring-when-nesting-an-object-into-an-array"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-668" ],
"severity" : "LOW",
"github_reviewed" : true,
"github_reviewed_at" : "2024-11-06T19:52:31Z",
"nvd_published_at" : "2024-11-06T20:15:05Z"
}
}