CVE-2026-48806

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

Published Jul 14, 2026 CVSS 4.0 · 7.1 High EPSS < 1% KEV · Not listed
Description
Twig is a template language for PHP. Prior to 3.27.0, ArrayExpression does not guard dynamic mapping keys that are coerced to strings, allowing PHP to invoke __toString() on a Stringable object used as a mapping key without calling SandboxExtension::ensureToStringAllowed(). This issue is fixed in version 3.27.0.

Analysis

AI-generated

Technical impact

Twig is a PHP template language. The vulnerability is in ArrayExpression before version 3.27.0; dynamic mapping keys that are coerced to strings are not guarded. When a mapping key is a Stringable object, PHP calls its __toString() method without first invoking SandboxExtension::ensureToStringAllowed(), bypassing the sandbox's to-string restrictions. This failure to enforce a security policy (CWE-693) and improper handling of untrusted input during string coercion (CWE-863) can allow an attacker who can supply a template to trigger code execution or elevate privileges within the process.

Affected Systems

The affected product is the Twig template engine, version 3.x from twigphp:Twig. Any installation running a Twig version older than 3.27.0 is susceptible. The issue is fixed in Twig 3.27.0 and later, which guards dynamic mapping keys before invoking __toString().

Risk and Exploitability

The CVSS score of 7.1 indicates a high risk to confidentiality, integrity, and availability. With an EPSS of less than 1%, exploitation is currently considered unlikely. The vulnerability is not listed in the CISA KEV catalog. The likely attack vector involves an attacker-controllable template that supplies a Stringable object as a mapping key, which triggers __toString() without sandbox enforcement, leading to local privilege escalation or code execution on the host where Twig runs.

Remediation

No solution or workaround provided in the CVE record.

OpenCVE Recommended Actions

  • Apply the official Twig 3.27.0 or newer patch that preserves sandbox enforcement for dynamic mapping keys.
  • If an upgrade cannot be performed immediately, ensure that template engines do not use Stringable objects as mapping keys, and validate any keys before processing to prevent unintended __toString() invocation.
  • Implement logging or monitoring for unexpected __toString() calls or template execution errors, which can serve as early indicators of an attempted bypass.

Generated by OpenCVE AI on July 31, 2026 at 04:32 UTC.

Tracking

Sign in to view the affected projects.

Advisories

Source ID Title
Github GHSA Github GHSA GHSA-5v5v-ww74-355v Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
History
Type Values Removed Values Added
First Time appeared Twigphp
Twigphp twig
Vendors & Products Twigphp
Twigphp twig
Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'none', 'Technical Impact': 'partial'}, 'version': '2.0.3'}

Type Values Removed Values Added
Description Twig is a template language for PHP. Prior to 3.27.0, ArrayExpression does not guard dynamic mapping keys that are coerced to strings, allowing PHP to invoke __toString() on a Stringable object used as a mapping key without calling SandboxExtension::ensureToStringAllowed(). This issue is fixed in version 3.27.0.
Title Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
Weaknesses CWE-693
CWE-863
References
Metrics cvssV4_0

{'score': 7.1, 'vector': 'CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:H/VI:L/VA:N/SC:N/SI:N/SA:N'}

Weaknesses
  • CWE-693

    Protection Mechanism Failure

  • CWE-863

    Incorrect Authorization

Sources

Status
PUBLISHED
Assigner
GitHub_M
Published
Updated
Jul 15, 2026, 12:47 PM
Reserved
May 22, 2026, 8:57 PM
Status
Analyzed
Published
Jul 14, 2026, 10:17 PM
Modified
Oct 24, 2026, 10:10 PM