Twig CVE-2026-48805
MEDIUMSeverity by source
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:L/VA:N/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
AC:H reflects three simultaneous prerequisites (sandbox mode, deprecated wrappers, version 3.26.x); PR:L because template submission typically requires authenticated access; S:C for sandbox escape into the broader PHP process.
Primary rating from Vendor (https://github.com/twigphp/Twig).
CVSS VectorVendor: https://github.com/twigphp/Twig
Lifecycle Timeline
2DescriptionCVE.org
Description
The 3.26.0 source-policy hardening changed the signature of CoreExtension::checkArrow() to take a boolean $isSandboxed instead of an Environment, and added the same $isSandboxed argument to CoreExtension::arraySome() and CoreExtension::arrayEvery(). Compiled templates were updated to pass the per-source sandbox state computed at the call site.
The deprecated internal wrappers exposed in src/Resources/core.php for legacy third-party code (twig_check_arrow_in_sandbox(), twig_array_some(), twig_array_every()) were not updated:
twig_array_some()andtwig_array_every()callCoreExtension::arraySome()/arrayEvery()without forwarding the sandbox state. The underlying methods default$isSandboxedtofalse, so the callable-must-be-a-Closurerestriction is silently bypassed in sandbox mode and a string callable such as'strcmp'is accepted.twig_check_arrow_in_sandbox()passes theEnvironmentobject whereCoreExtension::checkArrow()now expects abool, which throws aTypeErroron PHP 8+.
Compiled Twig templates are not affected: they call CoreExtension::* directly with the correct arguments. Applications are only impacted if they still call the deprecated twig_* helpers on top of a sandboxed Environment.
Resolution
The three wrappers now resolve the current sandbox state via twig_resolve_is_sandboxed() (the same helper compiled templates use), and forward it to the corresponding CoreExtension::* method. twig_check_arrow_in_sandbox() no longer triggers a TypeError, and twig_array_some() / twig_array_every() now enforce the same sandbox restriction as compiled templates.
Credits
We would like to thank El Kharoubi Iosif for reporting the issue and Fabien Potencier for providing the fix.
AnalysisAI
Sandbox bypass in Twig 3.26.x allows string callables to circumvent the Closure-only restriction when applications use the deprecated twig_array_some() and twig_array_every() wrapper functions over a sandboxed Environment. The 3.26.0 source-policy hardening changed CoreExtension::checkArrow() to accept a boolean sandbox state, but the legacy wrappers in src/Resources/core.php were not updated, causing them to silently pass false for $isSandboxed and accept arbitrary string callables such as 'exec' or 'system' that the sandbox was designed to block. No public exploit has been identified at time of analysis, and impact is limited to the narrow subset of applications calling the deprecated wrappers with sandbox mode active.
Technical ContextAI
Twig (pkg:composer/twig_twig) is a PHP template engine with a sandbox mode that restricts callable types - arrow functions must be proper PHP Closure objects, not arbitrary string callables, to prevent template authors from invoking unrestricted PHP functions. The 3.26.0 release introduced a source-policy hardening that refactored CoreExtension::checkArrow() to accept a bool $isSandboxed parameter instead of an Environment object, and added the same parameter to CoreExtension::arraySome() and CoreExtension::arrayEvery(). Compiled templates were updated to call these methods with the correct boolean derived at the call site. However, the three deprecated wrapper functions in src/Resources/core.php - maintained for legacy third-party compatibility - were not updated: twig_array_some() and twig_array_every() call the underlying methods without forwarding sandbox state (defaulting to false), and twig_check_arrow_in_sandbox() passes an Environment object where a bool is now required, triggering a TypeError on PHP 8+. CWE-693 (Protection Mechanism Failure) accurately describes this: the Closure enforcement mechanism exists but fails to engage due to a regression in parameter forwarding through the deprecated code path.
RemediationAI
Upgrade Twig to version 3.27.0 or later, where all three deprecated wrappers have been corrected to resolve sandbox state via twig_resolve_is_sandboxed() and forward it to the corresponding CoreExtension::* methods. The patch is available at https://github.com/twigphp/Twig/releases/tag/v3.27.0; run composer require twig/twig:^3.27.0 to apply the fix. If an immediate upgrade is not possible, audit the codebase and all third-party dependencies for direct calls to twig_check_arrow_in_sandbox(), twig_array_some(), or twig_array_every(), and replace them with their CoreExtension::* equivalents passing the correct boolean sandbox state obtained via twig_resolve_is_sandboxed() - this eliminates the flawed code paths without requiring a package upgrade, though it introduces a maintenance burden and may break third-party packages that cannot be easily patched. As an additional compensating control, if your application does not strictly require Twig sandbox mode with arrow functions or array callbacks, consider auditing whether sandbox mode is actively protecting a real threat model, since disabling sandbox mode entirely removes the bypass but also removes the intended security boundary. Do not rely on disabling sandbox mode as a long-term substitute for patching.
In PHP versions 7.1.x below 7.1.33, 7.2.x below 7.2.24 and 7.3.x below 7.3.11 in certain configurations of FPM setup it
sapi/cgi/cgi_main.c in PHP before 5.3.12 and 5.4.x before 5.4.2, when configured as a CGI script (aka php-cgi), does not
(1) boardData102.php, (2) boardData103.php, (3) boardDataJP.php, (4) boardDataNA.php, and (5) boardDataWW.php in Netgear
The '/common/download_agent_installer.php' script in the Quest KACE System Management Appliance 8.0.318 is accessible by
ProjectSend versions prior to r1720 are affected by an improper authentication vulnerability. Rated critical severity (C
Roundcube Webmail contains a critical PHP object deserialization vulnerability (CVE-2025-49113, CVSS 9.9) that allows au
Util/PHP/eval-stdin.php in PHPUnit before 4.8.28 and 5.x before 5.6.3 allows remote attackers to execute arbitrary PHP c
Palo Alto Networks PAN-OS management web interface contains an authentication bypass allowing unauthenticated attackers
Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re
Nagios XI version xi-5.7.5 is affected by OS command injection. Rated high severity (CVSS 8.8), this vulnerability is re
The get_referers function in /opt/ws/bin/sblistpack in Sophos Web Appliance before 3.7.9.1 and 3.8 before 3.8.1.1 allows
The Backup Migration plugin for WordPress is vulnerable to Remote Code Execution in all versions up to, and including, 1
Same weakness CWE-693 – Protection Mechanism Failure
View allSame technique Authentication Bypass
View allShare
External POC / Exploit Code
Leaving vuln.today
GHSA-p42q-9prx-q5wq