# GHSA-CCRC-GQHF-3CXC: Description The sandbox checks that a template may call toString() on an object before converting it to a string

- Database: GitHub
- Severity: CVSS 5.3 (Medium)
- Published: 2026-11-24
- Modified: 2026-11-24

## Tracked as

- [CVE-2026-133765](https://cve.now/CVE-2026-133765.md): twig/twig sandbox policy bypass via assignment expressions

## Affected versions

- twig/twig (Packagist): from 3.23.0, fixed in 3.31.1

## Description

### Description

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:

```twig
{{ (x = obj) }}
{{ ({secret: s} = obj)|join }}
```

No tag needs to be allowed.

### Resolution

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.

The patch for this issue is available [here](https://github.com/twigphp/Twig/commit/6bcdbc3d4470dde23e3e2636e7053e0512387edd) for branch 3.x.

### Credits

We would like to thank [杨延健](https://github.com/Bingoyyj), [Inanna Malick](https://github.com/inanna-malick) and [Tudor-Andrei Oprea](https://github.com/str1ng0) for independently reporting the issue, and Fabien Potencier for finding it first and providing the fix.

## References

- https://github.com/twigphp/Twig/security/advisories/GHSA-ccrc-gqhf-3cxc

Page: https://cve.now/GHSA-CCRC-GQHF-3CXC

Wrong or missing data? Send feedback: POST https://cve.now/api/v1/feedback (see https://cve.now/agents#feedback).
