Description
Twig is a template language for PHP. Prior to 3.27.0, the per-template filter, tag, and function allow-list verdict is computed when a Template instance is constructed and can remain cached after sandbox state changes between renders, allowing a later sandboxed render to reuse a template that was originally checked with a different or empty policy. This issue is fixed in version 3.27.0.
Published: 2026-07-14
Score: 6 Medium
EPSS: < 1% Very Low
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

Twig is a PHP template engine that includes a sandbox mode to restrict which filters, tags, and functions templates may use. The issue arises because the list of approved components is calculated only when a Template instance is constructed and then kept in cache. When an application changes the sandbox policy between renders, the cached Template still references the stale allow‑list, potentially enabling disallowed operations. The vulnerability is classified as CWE‑693 (System Will Not Perform as Intended) and CWE‑863 (Improper Handling of Policy Changes). The primary impact is that code that should be rejected by the sandbox can be executed, allowing an attacker to read or manipulate data outside the sandbox’s intended boundaries.

Affected Systems

All installations of twigphp:Twig older than version 3.27.0 are affected. Any PHP application that caches Template objects and subsequently modifies its sandbox policy between renders is vulnerable. This includes applications that build and cache templates for later use, regardless of how Twig was installed or distributed.

Risk and Exploitability

The CVSS base score of 6 marks the flaw as medium severity. The EPSS score of less than 1 % indicates that exploitation attempts are currently uncommon, and the vulnerability is not listed in the CISA KEV catalog. However, the logic flaw permits a sandbox bypass that could lead to arbitrary code execution. Based on the description, it is inferred that the most likely attack vector involves an application that re‑renders cached templates after changing its sandbox policy without clearing the cache. Such a scenario provides the conditions necessary for the bypass, making timely mitigation important.

Generated by OpenCVE AI on July 31, 2026 at 04:33 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade twigphp:Twig to version 3.27.0 or later, where the allow‑list is re‑evaluated on each render or when the sandbox policy changes.
  • If an upgrade is not immediately possible, clear any cached Template objects before changing the sandbox policy and recompile templates thereafter to enforce the new allow‑list.
  • Disable template caching in sandboxed environments until the patch is applied, or ensure templates are reloaded whenever the sandbox policy changes.

Generated by OpenCVE AI on July 31, 2026 at 04:33 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Github GHSA Github GHSA GHSA-529h-vh3j-85hq Twig: Sandbox filter, tag and function allow-list bypass when sandbox state changes between renders for a cached `Template`
History

Tue, 21 Jul 2026 16:30:00 +0000

Type Values Removed Values Added
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'none', 'Technical Impact': 'partial'}, 'version': '2.0.3'}


Wed, 15 Jul 2026 15:15:00 +0000

Type Values Removed Values Added
First Time appeared Twigphp
Twigphp twig
Vendors & Products Twigphp
Twigphp twig

Tue, 14 Jul 2026 21:45:00 +0000

Type Values Removed Values Added
Description Twig is a template language for PHP. Prior to 3.27.0, the per-template filter, tag, and function allow-list verdict is computed when a Template instance is constructed and can remain cached after sandbox state changes between renders, allowing a later sandboxed render to reuse a template that was originally checked with a different or empty policy. This issue is fixed in version 3.27.0.
Title Twig: Sandbox filter, tag and function allow-list bypass when sandbox state changes between renders for a cached `Template`
Weaknesses CWE-693
CWE-863
References
Metrics cvssV4_0

{'score': 6, 'vector': 'CVSS:4.0/AV:N/AC:L/AT:P/PR:L/UI:N/VC:H/VI:L/VA:N/SC:N/SI:N/SA:N'}


cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-07-21T14:57:52.032Z

Reserved: 2026-06-02T18:30:51.282Z

Link: CVE-2026-49981

cve-icon Vulnrichment

Updated: 2026-07-21T14:57:47.497Z

cve-icon NVD

No data.

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-07-31T04:45:17Z

Weaknesses
  • CWE-693

    Protection Mechanism Failure

  • CWE-863

    Incorrect Authorization