CVE-2024-51754
Low · 2.2CVSS
2.2
EPSS
0.4%
Published
Nov 6, 2024
CISA due date
—
Cloudanix analysis
A safety feature meant to limit what template code can do can be sidestepped when certain data is placed inside lists or passed to functions.
- Exploitation
- Remote Authenticated
- Attacker needs
- High Privilege
- Complexity
- High
- Impact
- Data Exposure
- Component
- Library
- Class
- Authorization Bypass
- Remediation
- Upgrade
- Effort
- Medium
- Patch risk
- Low
What it actually does
The flaw permits bypassing Twig sandbox security policies to invoke __toString() on objects when those objects appear inside arrays or as arguments to functions/filters.
Why it matters to the business
Applications relying on Twig sandboxing for untrusted templates face a risk of limited unauthorized data exposure through policy evasion, though the low severity and absence from known exploitation lists reduce immediate operational disruption.
How an attack unfolds
An attacker supplies a crafted template input that places a restricted object inside an array or argument list passed to a function or filter; the sandbox incorrectly allows the __toString() method to execute despite the security policy.
How to fix it
Upgrade twigphp/twig to version 3.11.2 or 3.14.1; the fixes are present in commit 5b580ec1882b54c98cbd8c0f8a3ca5d1904db6b1 and later releases.
How to confirm the fix worked
Confirm the installed Twig version meets or exceeds 3.11.2 or 3.14.1, then re-test the sandbox policy with objects placed inside arrays and argument lists to verify __toString() is now blocked.
Typical attack path
- Locate a Twig template rendered inside a sandbox with a restrictive security policy
- Craft input that embeds a policy-restricted object inside an array or as a function/filter argument
- Trigger template rendering that processes the array or argument list
- Observe the unintended __toString() invocation and resulting side effects
How to detect it
Examine application and template-rendering logs for repeated or anomalous processing of arrays containing objects in sandbox contexts; look for unexpected string conversions or method calls that policy rules should have prevented.
What your security team should do
- Upgrade all Twig installations to the patched versions without delay
- Audit existing sandbox policies and template inputs that pass arrays or arguments
- Add automated version checks and regression tests for sandbox behavior in CI pipelines
The record
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.
Affected packages
| Ecosystem | Package | Introduced | Fixed |
|---|---|---|---|
| Packagist | twig/twig | 0 | 3.11.2 |
| Packagist | twig/twig | 3.12 | 3.14.1 |
| Debian:11 | php-twig | 0 | No fix |
| Debian:12 | php-twig | 0 | No fix |
| Debian:13 | php-twig | 0 | 3.14.2-1 |
| Ubuntu:20.04:LTS | php-twig | 0 | No fix |
| Ubuntu:22.04:LTS | php-twig | 0 | No fix |
| Ubuntu:24.04:LTS | php-twig | 0 | No fix |
| Ubuntu:24.10 | php-twig | 0 | No fix |
| Ubuntu:Pro:16.04:LTS | twig | 0 | No fix |
| Ubuntu:Pro:18.04:LTS | twig | 0 | No fix |
| Ubuntu:Pro:20.04:LTS | php-twig | 0 | 2.12.5-1ubuntu0.1~esm2 |
| Ubuntu:Pro:22.04:LTS | php-twig | 0 | 3.3.8-2ubuntu4+esm2 |
| Ubuntu:Pro:24.04:LTS | php-twig | 0 | 3.8.0-2ubuntu0.1~esm1 |
| packagist | twig/twig | 3.12 | 3.14.1 |
Related vulnerabilities
- CVE-2024-51755 Twig is a template language for PHP. Also affects twig/twig
- CVE-2024-45411 Twig is a template language for PHP. Also affects twig/twig
- CVE-2026-105754 vLLM is an inference and serving engine for large language models. CWE-668
- CVE-2026-92940 vm2 versions 3.11.3 through 3.11.6 expose the host process's real https.globalAgent to… CWE-668
- CVE-2026-85053 Improper resource exposure in CacheStorage in Google Chrome prior to 152.0.7977.82… CWE-668
- CVE-2026-82652 SiYuan before v3.8.1 fails to filter invisible-tier content from SQL embed blocks… CWE-668
- CVE-2026-82650 SiYuan 3.8.0 contains a path traversal / sensitive file exposure vulnerability in the… CWE-668
- CVE-2026-79068 Improper resource exposure in StreamsAPI in Google Chrome prior to 152.0.7977.65 allowed… CWE-668