CVE-2026-46633: Twig PHP code injection via use tag template name

CVE-2026-46633 · Severity: critical · CVSS 4 · Published 2026-07-14

Twig is a popular template engine for PHP used to generate dynamic web content. A vulnerability in how it handles template names allows an attacker to inject and execute malicious PHP code on the server. This bypasses security restrictions (sandboxing) and could lead to full system compromise or unauthorized data access.

Technologies: twig/twig (Packagist), Twig PHP Twig. Vendors: Packagist, Twig PHP.

Quick answers

Is CVE-2026-46633 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-46633 being exploited in the wild.
How severe is CVE-2026-46633?
Critical severity, with a CVSS score of 4, published 14 July 2026.
Which products and versions are affected?
twig/twig (Packagist) < 3.26.0, ECOSYSTEM:introduced=0,fixed=3.26.0; Twig PHP Twig < 3.26.0.
Is there a fix for CVE-2026-46633?
Yes. twig/twig (Packagist): upgrade to 3.26.0 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-46633 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2026-46633?
Check whether you run twig/twig (Packagist) or Twig PHP Twig at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

How to fix

  • twig/twig (Packagist): upgrade to 3.26.0 or later
    composer require twig/twig:^3.26.0

Technical details

A code injection vulnerability exists in Twig's Compiler::string() method, which fails to escape single quotes when generating PHP code. When a template name from a '{% use %}' tag is processed in ModuleNode::compileConstructor(), it is placed inside a single-quoted PHP string literal in the compiled cache file. An attacker can provide a template name containing a single quote to terminate the string literal and inject arbitrary PHP expressions. Because the SecurityPolicy unconditionally allows the '{% use %}' tag, this vulnerability can be exploited even from within a sandboxed environment to achieve remote code execution (RCE). The issue is resolved in version 3.26.0 by ensuring single quotes are escaped as hex sequences.

Affected products

  • twigphp Twig < 3.26.0

Identifiers

  • CVE-2026-46633
  • GHSA-7p85-w9px-jpjp

Timeline

  • 2026-05-20: patched: Version 3.26.0 released
  • 2026-05-20: advisory: GitHub Security Advisory GHSA-7p85-w9px-jpjp published
  • 2026-07-14: disclosed: CVE-2026-46633 published to NVD

References

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.