Sandbox __toString() policy bypass via spread arguments in Twig
Key facts
- Attack vector
- Network
- Privileges required
- Low
- User interaction
- None
- Attack complexity
- Low
- Attack requirements
- Present
- Impact type
- Security bypass
- Confidentiality · integrity · availability
- Low · None · None
- Fix status
- Fixed
Attack profile from CVSS 4.0 · CNA. Fix status from CNA. Impact type from CWE-693.
Summary
Twig from 3.28.0 before 3.31.1 skips the __toString() sandbox check for a spread argument whose PHP parameter cannot hold a string, such as an int. A spread argument fills every parameter from its position on, but the check covered only one parameter, so a sandboxed template can call a denied toString() method. Applications are affected when they allow such a function, filter or test in the sandbox, and no built-in callable is affected. An attacker needs low privileges and the ability to write sandboxed templates.
Written with Claude Haiku 5.5 from the sources below · 2026-11-24
Description from the CNA
Since Twig 3.28.0, the sandbox skips the toString() check of an argument whose PHP parameter can't hold a string, like an int. A spread argument was mapped to a single parameter, although it fills every parameter from its position on. A sandboxed template could therefore call a denied toString() method: {{ tag(...[1, obj]) }} Here, the first parameter of tag() is an int, and a later one accepts strings. Applications are affected when they allow such a function, filter or test in the sandbox. No built-in callable is affected. A spread argument is now checked unless every parameter that it can fill has a safe type.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
Remediation
Update twig/twig to version 3.31.1. The fix checks a spread argument unless every parameter it can fill has a safe type.
Written with Claude Haiku 5.5 from the sources below · 2026-11-24
- Fix · CNA twig/twig (Twig) Fixed in 3.31.1
Fixed in the same release
Records fixed by the same vendor advisory or release, as the CNA lists them.
- Release ·
twig/twig 3.31.1
7 records Highest priority Priority LOW 7 LOW
Other records, highest priority first
- TI-2026-97282 Sandbox bypass in Twig join filter exposes object propertiesPriority LOW 25
- TI-2026-97281 Twig sandbox bypass through dynamic embed parent expressionsPriority LOW 25
- TI-2026-97279 Sandbox toString() policy bypass in Twig via assignmentsPriority LOW 25
Timeline
- 2026-11-24 Threatist record created from CVE-2026-133766
References
More Twig vulnerabilities
- TI-2026-97282 Sandbox bypass in Twig join filter exposes object properties CVSS 4.0MEDIUM 5.3
- TI-2026-97281 Twig sandbox bypass through dynamic embed parent expressions CVSS 4.0MEDIUM 5.3
- TI-2026-97279 Sandbox toString() policy bypass in Twig via assignments CVSS 4.0MEDIUM 5.3
- TI-2026-97277 Sandbox toString policy bypass via is true test in Twig CVSS 4.0MEDIUM 5.3
- TI-2026-97287 Unbounded converter cache in Twig markdown-extra exhausts memory CVSS 4.0LOW 2.3
- TI-2026-97286 Sandbox bypass in Twig guard tag lets templates use disallowed tags CVSS 4.0LOW 2.3
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences