All reports
Low

Twig has unguarded calls to `__toString()` when nesting an object into an array

Affected versions

Version ranges need review.

Composertwig/twig
Affected versions
>=1.0.0,<2.0.0|>=2.0.0,<3.0.0|>=3.0.0,<3.11.2|>=3.12.0,<3.14.1
Fixed version
Not reported
Composertwig/twig
Affected versions
< 3.11.2
Fixed version
3.11.2
Composertwig/twig
Affected versions
>= 3.12, < 3.14.1
Fixed version
3.14.1

Exploitation

CVE-2024-51754

Probability of exploitation in the next 30 days: 0.43%

FIRST EPSS · 2026-11-20

Description

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.

Links

Credits

  • maantje
  • fabpot