CVE-2026-133765: Sandbox `__toString()` policy bypass via assignment and destructuring expressions

Published Nov 24, 2026
·
Updated

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.

Affected Software

1 affected component
composer/twig/twig>=3.23.0

Event History

Nov 24, 2026
CVE Published
via MITRE·01:07 PM
Data Sourced
via MITRE·01:07 PM
DescriptionWeakness
Data Sourced
via OSV·01:07 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·01:17 PM
DescriptionSeverityWeakness

Frequently Asked Questions

1

Who can exploit this issue?

An attacker needs the ability to render a sandboxed Twig template and access to an object whose toString() method is denied by the sandbox policy. The bypass occurs when an assignment or destructuring expression evaluates to that object and its result is converted to a string.

2

Does an attacker need any Twig tags to be allowed?

No. The issue can be exploited without any tag being allowed.

3

Which template patterns are relevant when assessing exposure?

Review rendered assignment expressions such as {{ (x = obj) }} and destructuring expressions whose result is passed through a string-converting operation, such as {{ ({secret: s} = obj)|join }}. Twig versions since 3.23.0 are described as evaluating these expressions to their assigned value.

4

Are assignments safe when they are not rendered as strings?

{% do x = obj %} and {% if (x = obj) %} still work because those contexts do not convert the assigned value to a string. The vulnerable behavior concerns assignment or destructuring results that are converted to strings.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203