Advisory Database
  • Advisories
  • Dependency Scanning
  1. composer
  2. ›
  3. twig/twig
  4. ›
  5. CVE-2026-48806

CVE-2026-48806: Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys

June 30, 2026

This is a residual bypass of CVE-2026-47732 / GHSA-pr2w-4gpj-cpq4 left after the initial fix for unguarded __toString() calls.

In 3.26.0 the sandbox visitor was extended to wrap every child node that its parent will string-coerce at runtime with CheckToStringNode, gated by the new CoercesChildrenToStringInterface. ArrayExpression did not implement the interface for its mapping keys: when a dynamic key expression resolves to a Stringable object, ArrayExpression::compile() emits a raw (string) cast (via StringCastUnary for ContextVariable keys, and no cast at all for richer key expressions). PHP then invokes __toString() directly, without ever calling SandboxExtension::ensureToStringAllowed().

A sandboxed template author can therefore trigger __toString() on any object reachable in the render context by using it as a dynamic mapping key, for example:

{% set arr = {(obj): "value"} %}

Direct output of the same object is correctly blocked, which makes this a clear policy enforcement gap. The reliable demonstrated impact is unauthorised disclosure of data returned by __toString().

References

  • github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-48806.yaml
  • github.com/advisories/GHSA-5v5v-ww74-355v
  • github.com/twigphp/Twig/releases/tag/v3.27.0
  • github.com/twigphp/Twig/security/advisories/GHSA-5v5v-ww74-355v
  • nvd.nist.gov/vuln/detail/CVE-2026-48806
  • symfony.com/blog/cve-2026-48806-sandbox-tostring-policy-bypass-via-dynamic-mapping-keys

Code Behaviors & Features

Detect and mitigate CVE-2026-48806 with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Dependency Scanning using SBOM also detects vulnerabilities from proprietary advisories that this site does not include. Learn more about Dependency Scanning using SBOM →

Affected versions

All versions before 3.27.0

Fixed versions

  • 3.27.0

Solution

Upgrade to version 3.27.0 or above.

Weakness

  • CWE-693: Protection Mechanism Failure
  • CWE-863: Incorrect Authorization

Source file

packagist/twig/twig/CVE-2026-48806.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Mon, 09 Nov 2026 12:17:09 +0000.