Sandbox toString() policy bypass in Twig via assignments
Key facts
- Attack vector
- Network
- Privileges required
- Low
- User interaction
- None
- Attack complexity
- Low
- Attack requirements
- None
- 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, the PHP template engine twig/twig from 3.23.0 before 3.31.1, has a sandbox bypass. The sandbox checks that a template may call toString() on an object before converting it to a string, but it does not check the value of assignment expressions, so assignments and destructuring forms can return an object whose denied toString() method is then called. A sandboxed template author can exploit this without any tag being allowed, which is a CWE-693 protection mechanism failure.
Written with Claude Haiku 5.5 from the sources below · 2026-11-24
Description from the CNA
The sandbox checks that a template may call toString() on an object before converting it to a string. Since Twig 3.23.0, assignments like x = obj, and the destructuring forms [a] = list and {a} = obj, evaluate to the value that they assign. The sandbox didn't check that value, so a sandboxed template could call a denied toString() method: {{ (x = obj) }} {{ ({secret: s} = obj)|join }} No tag needs to be allowed. The sandbox now checks the result of assignments like the result of filters and functions. {% do x = obj %} and {% if (x = obj) %} still work, since they don't convert the value to a string.
Why it matters now
SSVC decision points
Not available: CISA has not published SSVC decision points for this record.
Affected products
Remediation
Upgrade twig/twig to version 3.31.1, which fixes the issue.
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-97277 Sandbox toString policy bypass via is true test in TwigPriority LOW 25
Timeline
- 2026-11-24 Threatist record created from CVE-2026-133765
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-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
- TI-2026-97285 Twig skips autoescaping for variables named like import aliases CVSS 4.0LOW 2.3
Sources
This product uses the NVD API but is not endorsed or certified by the NVD. Sources and licences