CVE-2026-48807: Twig sandbox policy bypass via Traversable objects in filters and operators

CVE-2026-48807 · Severity: medium · CVSS 0 · Published 2026-07-14

Twig is a popular template engine for PHP used to generate HTML and other web content. A security flaw in its "sandbox" mode—a feature designed to safely run untrusted code—allows users to bypass security restrictions and execute unauthorized internal functions. This could allow an attacker with template editing permissions to access sensitive data or trigger unintended actions on the server.

Technologies: twig/twig (Packagist). Vendors: Packagist.

Quick answers

Is CVE-2026-48807 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-48807 being exploited in the wild.
How severe is CVE-2026-48807?
Medium severity, with a CVSS score of 0, published 14 July 2026.
Which products and versions are affected?
twig/twig (Packagist) <= 3.26.0, ECOSYSTEM:introduced=0,fixed=3.27.0.
Is there a fix for CVE-2026-48807?
Yes. twig/twig (Packagist): upgrade to 3.27.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-48807 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2026-48807?
Check whether you run twig/twig (Packagist) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • twig/twig (Packagist): upgrade to 3.27.0 or later
    composer require twig/twig:^3.27.0

Technical details

A vulnerability in Twig's sandbox mode allows for a policy bypass when handling Traversable objects. The sandbox's __toString() checks failed to recurse into Traversable values passed to the 'join' and 'replace' filters, or operands used with 'in' and 'not in' operators. This allows Stringable objects contained within these structures to be coerced into strings without the SecurityPolicy consulting the allowed methods list. An attacker with the ability to author sandboxed templates can exploit this to call disallowed __toString() methods on objects within the render context, potentially leading to information disclosure or side-channel attacks. The issue is resolved in version 3.27.0 by ensuring the sandbox recurses into Traversable operands to validate them against the security policy.

Affected products

  • twigphp Twig < 3.27.0

Identifiers

  • CVE-2026-48807
  • GHSA-8x9c-rmqh-456c

Timeline

  • 2026-05-27: patched: Version 3.27.0 released
  • 2026-05-27: advisory: GitHub Security Advisory published
  • 2026-07-14: disclosed: CVE published to NVD

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.