Skip to main content

CVE-2024-51754 — Vulnerability in twig/twig — CVE Details

LOW

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

Published November 6, 2024Updated May 29, 2025Source: OSV

What Should I Do?

Address in Next Maintenance Window

Low exploitation probability (0.71%). Schedule for your next planned update.

Does your project use an affected twig/twig version?

Paste your composer.lock to check it for CVE-2024-51754 and every other known vulnerability, with CISA KEV and EPSS on each finding. Free with no signup for up to 10 packages, or up to 500 per scan with a free account, which also keeps up to 200 packages in saved projects.

Check my composer.lock

Summary

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.

Advisory Timeline

  • First published November 6, 2024 (750 days ago).
  • Last revised May 29, 2025 — 204 days after initial publication.

Remediation

Upgrade to the fixed version using your package manager.

Composer
Update twig/twig to 3.14.1 or later
composer require "twig/twig:^3.14.1"
Composer
Update twig/twig to 3.11.2 or later
composer require "twig/twig:^3.11.2"

After upgrading, scan your dependencies again to confirm the vulnerability is resolved.

Affected Packages (2)

Affects 1 ecosystem: Packagist (1).

PackageFixed In
twig/twig Packagist · Affected: v3.12.0, v3.13.0, v3.14.03.14.1
twig/twig Packagist · Affected: 1.3.0, 1.4.0, 1.5.0, 1.5.1 (+216 more)3.11.2

Vulnerability Classification

Common Weakness Enumeration (CWE) identifiers for this vulnerability type.

CVSS Score Breakdown

What the CVSS (Common Vulnerability Scoring System) 2.2 score means for each attack dimension.

Attack Vector
Network
Attack Complexity
High
Privileges Required
High
User Interaction
None
Scope
Unchanged
Confidentiality
Low
Integrity
None
Availability
None

CVSS:3.1/AV:N/AC:H/PR:H/UI:N/S:U/C:L/I:N/A:N

Frequently Asked Questions

What is CVE-2024-51754?
Twig has unguarded calls to `__toString()` when nesting an object into an array. This vulnerability has been assigned a severity rating of LOW (CVSS score: 2.2/10).
How do I check if my project is affected by CVE-2024-51754?
CVE-2024-51754 affects twig/twig. It has a 0.7% probability of exploitation within 30 days (EPSS score). Use GeekWala's free vulnerability scanner to check your dependencies against CVE-2024-51754 and 200,000+ other known vulnerabilities.

Severity & Exploitability

CVSS Score
2.2

Exploitation is difficult, or the impact is minor.

EPSS Score (30-day exploit probability)
0.71%
EPSS percentile: 49.2

This is a below-median EPSS score — only 49.2% of tracked vulnerabilities score at or below it, so most tracked vulnerabilities are considered more likely to be exploited than this one.

Also Known As

GHSA-6377-hfv9-hqf6

Related CVEs

  • CVE-2026-24425
    HIGH

    Twig: Possible sandbox bypass when using a source policy

  • CVE-2026-46640
    HIGH

    Twig: Arbitrary PHP code execution via `_self.(<string>)` macro-reference compilation

  • CVE-2026-49981
    HIGH

    Twig: Sandbox filter, tag and function allow-list bypass when sandbox state changes between renders for a cached `Template`

  • CVE-2026-46634
    MEDIUM

    Twig: `template_from_string()` escapes a SourcePolicy-driven sandbox via synthesized template name

  • CVE-2026-48806
    MEDIUM

    Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys

  • CVE-2024-45411
    MEDIUM

    Twig has a possible sandbox bypass

  • CVE-2026-47730
    LOW

    Twig: XSS in profiler HtmlDumper via unescaped template and profile names

  • CVE-2026-46628
    LOW

    Twig: The `spaceless` filter implicitly marks its output as safe

Check your own dependencies

Free, with no signup for up to 10 packages.

Check my composer.lock