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

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

Unguarded calls to toString() when nesting an object into an array

— Packagist

Affected Software

11 affected componentsFixes available
composer/twig/twig>=3.12<3.14.1
3.14.1
composer/twig/twig<3.11.2
3.11.2
composer/twig/twig>=1.0.0, <2.0.0
composer/twig/twig>=2.0.0, <3.0.0
composer/twig/twig>=3.0.0, <3.11.2
3.11.2
composer/twig/twig>=3.12.0, <3.14.1
3.14.1
debian/php-twig<3.5.1-1+deb12u3
3.5.1-1+deb12u3
debian/php-twig<3.14.2-1
3.14.2-1
debian/php-twig<3.14.2-1
3.14.2-1
debian/php-twig
3.5.1-1+deb12u33.27.0-0+deb13u13.30.0-1
IBM API Connect V12 OnPrem<=v12.1.0.0 - v12.1.1.2

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade composer/twig/twig to a version that resolves this vulnerability.

    Fixed in 3.14.1
  2. Upgrade

    Upgrade composer/twig/twig to a version that resolves this vulnerability.

    Fixed in 3.11.2
  3. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.5.1-1+deb12u3
  4. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.14.2-1
  5. Upgrade

    Upgrade debian/php-twig to a version that resolves this vulnerability.

    Fixed in 3.5.1-1+deb12u3Fixed in 3.27.0-0+deb13u1Fixed in 3.30.0-1
  6. Upgrade

    Upgrade Twig to a version that resolves this vulnerability.

    Fixed in 3.11.2
  7. Upgrade

    Upgrade Twig to a version that resolves this vulnerability.

    Fixed in 3.14.1

Event History

Nov 6, 2024
Advisory Published
via Packagist·08:00 AM
Data Sourced
via Packagist·08:00 AM
DescriptionSeverityAffected Software
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
Data Sourced
via OSV·08:15 PM
DescriptionSeverityAffected Software
Oct 8, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software

Parent advisories

This vulnerability appears in the following advisories.

Peer vulnerabilities

Found alongside the following vulnerabilities.

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