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

CVE-2026-47732: Twig: Sandbox: multiple `__toString()` policy bypasses via unguarded string coercion points

June 5, 2026

SandboxNodeVisitor enforces SecurityPolicy::checkMethodAllowed() for implicit __toString() calls by wrapping selected AST nodes in CheckToStringNode. The set of wrapped nodes is incomplete, and several Twig language constructs still trigger PHP string coercion on a Stringable operand without first consulting the policy. A sandboxed template author can therefore invoke __toString() on any object reachable in the render context, even when __toString on its class is not allowlisted.

Confirmed bypass vectors:

  • Conditional expressions (a ? b : c, a ?: b, a ?? b) used as the input of a string-coercing filter or as a filter/function argument.
  • The matches operator and the loose comparison operators (==, !=, <, >, <=, >=, <=>), which coerce a Stringable operand to string and can be used as an oracle to recover the value byte by byte (no tag, filter or function needs to be allowlisted).
  • Twig tests in general (which were never policy-gated), in particular is empty which casts a Stringable value via (string) $value in CoreExtension::testEmpty().
  • Null-coalesce expressions nested in concatenation, and the direct output of allowed functions or filters that return a Stringable object.
  • Arguments passed to allowed object methods, template-name expressions of template-loading tags (include, extends, use, …), dynamic attribute/property names, and spread arguments from Traversable objects.
  • The do tag and the .. range operator.

References

  • github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-47732.yaml
  • github.com/advisories/GHSA-pr2w-4gpj-cpq4
  • github.com/twigphp/Twig/releases/tag/v3.26.0
  • github.com/twigphp/Twig/security/advisories/GHSA-pr2w-4gpj-cpq4
  • nvd.nist.gov/vuln/detail/CVE-2026-47732
  • symfony.com/cve-2026-47732

Code Behaviors & Features

Detect and mitigate CVE-2026-47732 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.26.0

Fixed versions

  • 3.26.0

Solution

Upgrade to version 3.26.0 or above.

Weakness

  • CWE-20: Improper Input Validation

Source file

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

Spotted a mistake? Edit the file on GitLab.

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

Page generated Sun, 08 Nov 2026 00:16:16 +0000.