Executive brief
Twig, a popular template engine for PHP, contains a security flaw in its sandbox mode. The sandbox is designed to safely run untrusted code, but certain outdated internal functions fail to check if they are running in this restricted environment. This could allow an attacker with the ability to provide templates to bypass security restrictions and execute unauthorized functions, potentially compromising the application's integrity.
Technical details
A vulnerability exists in Twig's deprecated internal wrappers within src/Resources/core.php. Following hardening changes in version 3.26.0, the signatures for CoreExtension::checkArrow(), arraySome(), and arrayEvery() were updated to require a boolean $isSandboxed flag. However, the legacy wrapper functions (twig_array_some, twig_array_every, and twig_check_arrow_in_sandbox) were not updated to forward this state. Consequently, these functions default to a non-sandboxed state, allowing attackers to bypass callable restrictions (such as the requirement that callables be Closures) and execute string-based callables like 'strcmp'. Additionally, twig_check_arrow_in_sandbox triggers a TypeError on PHP 8+ due to type mismatch. The issue is resolved in version 3.27.0 by ensuring these wrappers correctly resolve and forward the sandbox state.
Affected products
- twigphp Twig < 3.27.0
Timeline
- 2026-05-27: patched: Version 3.27.0 released
- 2026-05-27: advisory: GitHub Security Advisory published
- 2026-07-14: disclosed: CVE published to NVD