CVE-2026-48806: Twig sandbox policy bypass via dynamic mapping keys

CVE-2026-48806 · Severity: medium · CVSS 5.3 · Published 2026-07-14

Twig, a popular template engine for PHP, contains a security flaw in its sandbox mode. The sandbox is designed to restrict what template authors can do, but this vulnerability allows an author to bypass these restrictions by using specific objects as keys in a list. An attacker with the ability to edit templates could exploit this to view sensitive information that should otherwise be protected.

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

Quick answers

Is CVE-2026-48806 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-48806 being exploited in the wild.
How severe is CVE-2026-48806?
Medium severity, with a CVSS score of 5.3, 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-48806?
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-48806 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2026-48806?
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 residual sandbox bypass exists in Twig's ArrayExpression component. When a dynamic key expression in a template resolves to a 'Stringable' object, PHP's engine performs a raw string cast during array construction. Because ArrayExpression failed to implement CoercesChildrenToStringInterface, the sandbox visitor did not wrap these nodes with CheckToStringNode. Consequently, SandboxExtension::ensureToStringAllowed() is never invoked, allowing a sandboxed template author to trigger __toString() on any object reachable in the render context. This results in unauthorized data disclosure. The issue is fixed in version 3.27.0 by ensuring dynamic mapping keys are treated as string-coercion sites.

Affected products

  • twigphp Twig < 3.27.0

Identifiers

  • CVE-2026-48806
  • GHSA-5v5v-ww74-355v

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.