Description
Twig is a template language for PHP. From version 1.0.0 to before version 3.27.0, SecurityPolicy::checkMethodAllowed() unconditionally whitelists all method calls on instances of Twig\Markup. Twig\Markup is not final, so subclasses inherit the bypass. An application that passes an object of a Markup-derived class into a sandboxed template (typically to mark a chunk of HTML as safe) inadvertently exposes every public method of that subclass to template authors, regardless of the configured allowedMethods list. This issue has been patched in version 3.27.0.
Published: 2026-09-04
Score: 8.7 High
EPSS: n/a
KEV: No
Impact: n/a
Action: n/a
AI Analysis

Impact

Twig's sandbox feature is designed to limit which methods can be called on objects within templates. Prior to version 3.27.0 the checkMethodAllowed routine automatically permitted all public methods of Twig\\Markup instances, regardless of the allowedMethods whitelist. Because Twig\\Markup is not a final class, any subclass inherits this behavior. If an application passes a Markup-derived object into a sandboxed template, the template author can invoke any public method defined by that subclass. This bypass allows arbitrary code execution through the sandbox, elevating the impact from a limited template interference to full execution of methods on the subclass, potentially revealing sensitive data or executing privileged operations.

Affected Systems

Twig versions 1.0.0 through 3.26.x, distributed by the twigphp project, are affected. The vulnerability is present in all releases prior to 3.27.0. Upgrading to Twig 3.27.0 or newer resolves the issue.

Risk and Exploitability

The CVSS score of 8.7 marks this as a high‑severity flaw. No EPSS data is available, so the likelihood of exploitation is unclear, and it is not yet listed in the CISA KEV catalog. The likely attack vector is a sandboxed template that an attacker can influence – for example, through a content management system that renders user‑supplied templates. If such a template is rendered while a Markup‑derived object is in scope, the attacker can trigger any public method on that object, which can lead to data exposure or remote code execution. The flaw requires an application to supply a Markup subclass to the template; therefore, detecting and limiting such objects mitigates the risk.

Generated by OpenCVE AI on September 4, 2026 at 23:20 UTC.

Remediation

No vendor fix or workaround currently provided.

OpenCVE Recommended Actions

  • Upgrade to Twig 3.27.0 or later.
  • Audit the application code to ensure no Markup‑derived objects are passed into sandboxed templates; replace them with plain string data where possible.
  • Where sandboxed template use is unavoidable, configure the allowedMethods list to include only the necessary methods and explicitly deny subclass methods, and avoid subclassing Twig\\Markup.

Generated by OpenCVE AI on September 4, 2026 at 23:20 UTC.

Tracking

Sign in to view the affected projects.

Advisories
Source ID Title
Debian DSA Debian DSA DSA-6311-1 php-twig security update
History

Sat, 05 Sep 2026 02:00:00 +0000

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

Fri, 04 Sep 2026 22:15:00 +0000

Type Values Removed Values Added
Description Twig is a template language for PHP. From version 1.0.0 to before version 3.27.0, SecurityPolicy::checkMethodAllowed() unconditionally whitelists all method calls on instances of Twig\Markup. Twig\Markup is not final, so subclasses inherit the bypass. An application that passes an object of a Markup-derived class into a sandboxed template (typically to mark a chunk of HTML as safe) inadvertently exposes every public method of that subclass to template authors, regardless of the configured allowedMethods list. This issue has been patched in version 3.27.0.
Title Twig: Sandbox method allowlist bypass via `Markup` subclass
Weaknesses CWE-1336
References
Metrics cvssV4_0

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


cve-icon MITRE

Status: PUBLISHED

Assigner: GitHub_M

Published:

Updated: 2026-09-04T22:07:35.122Z

Reserved: 2026-05-15T20:11:54.584Z

Link: CVE-2026-46636

cve-icon Vulnrichment

No data.

cve-icon NVD

Status : Received

Published: 2026-09-04T22:17:17.360

Modified: 2026-09-04T22:17:17.360

Link: CVE-2026-46636

cve-icon Redhat

No data.

cve-icon OpenCVE Enrichment

Updated: 2026-09-05T01:45:17Z

Weaknesses
  • CWE-1336

    Improper Neutralization of Special Elements Used in a Template Engine