CVE-2024-51754: Unguarded calls to __toString() when nesting an object into an array in Twig

Published Nov 6, 2024
·
Updated

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.

Other sources

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.

Debian

Affected Software

3 affected componentsFixes available
debian/php-twig<=2.14.3-1+deb11u2, <=2.14.3-1+deb11u3, <=3.5.1-1+deb12u1
3.20.0-2
composer/twig/twig>=3.12<3.14.1
3.14.1
composer/twig/twig<3.11.2
3.11.2

Event History

Nov 6, 2024
CVE Published
via MITRE·07:28 PM
Data Sourced
via MITRE·07:28 PM
DescriptionSeverityWeakness
Advisory Published
via GitHub·07:52 PM
Data Sourced
via NVD·08:15 PM
DescriptionSeverityWeakness
Apr 28, 2025
Data Sourced
via Ubuntu·04:40 PM
RemedyDescriptionSeverityAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2024-51754?

The severity of CVE-2024-51754 is classified as medium, indicating potential risk to affected applications.

2

How do I fix CVE-2024-51754?

To fix CVE-2024-51754, update the twig/twig package to version 3.14.1 or 3.11.2 as per the resolution guidelines.

3

Which versions of twig/twig are affected by CVE-2024-51754?

CVE-2024-51754 affects twig/twig versions between 3.12.0 and 3.14.1, as well as all versions below 3.11.2.

4

Can CVE-2024-51754 be exploited in a sandbox environment?

Yes, CVE-2024-51754 can be exploited in a sandbox environment where an attacker can call the __toString() method on an object.

5

What is the nature of the vulnerability in CVE-2024-51754?

CVE-2024-51754 is a vulnerability that allows an attacker to bypass security policies related to the __toString() method in specific contexts.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203