# GHSA-RC9G-XWX4-RMFH: Description The sandbox checks that a template may call toString() on an object before converting it to a string

- Database: GitHub
- Severity: CVSS 2.3 (Low)
- Published: 2026-11-24
- Modified: 2026-11-24

## Tracked as

- [CVE-2026-133764](https://cve.now/CVE-2026-133764.md): twig/twig sandbox policy bypass via custom test input

## Affected versions

- twig/twig (Packagist): 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. It didn't check the input of tests. The PHP callable of a test may convert this input to a string, for example when its parameter is typed as `string`. PHP then calls `__toString()` on an object without the sandbox checking it first:

```twig
{{ obj is upperish }}
```

Applications are affected when they register such a test and allow it in the sandbox. No built-in test is affected.

### Resolution

The sandbox now checks the input of tests like the input of filters. The built-in tests that never convert their input to a string still skip the check.

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

### Credits

We would like to thank [Arpit Jain](https://github.com/arpitjain099) for reporting the issue, and Fabien Potencier for providing the fix.

## References

- https://github.com/twigphp/Twig/security/advisories/GHSA-rc9g-xwx4-rmfh

Page: https://cve.now/GHSA-RC9G-XWX4-RMFH

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