Junglewise Threat Intelligence

CVE-2026-46628: Twig XSS via incorrect autoescaping in spaceless filter

CVE-2026-46628 · Severity: medium · CVSS 4 · Published 2026-07-14

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

Executive brief

Twig, a popular template engine for PHP applications, contains a vulnerability in its 'spaceless' filter. This filter, used to remove whitespace between HTML tags, incorrectly tells the system that its content is safe and does not need to be cleaned. An attacker could use this to inject malicious scripts into a website, potentially leading to unauthorized actions or the theft of user data.

Technical details

The 'spaceless' filter in Twig was registered with the 'is_safe => ["html"]' attribute, which instructs Twig's autoescaper to skip output encoding when the filter is applied. If a developer applies this filter to untrusted user input, any malicious HTML or JavaScript within that input is rendered raw in the browser. This results in a Cross-Site Scripting (XSS) vulnerability even when global autoescaping is enabled. The issue is classified as CWE-116 (Improper Encoding or Escaping of Output) and has been resolved in version 3.26.0 by removing the implicit safe flag and pre-escaping input.

Affected products

  • twigphp Twig < 3.26.0

Timeline

  • 2026-05-20: patched: Version 3.26.0 released
  • 2026-05-20: advisory: GitHub Security Advisory GHSA-4j38-f5cw-54h7 published
  • 2026-07-14: disclosed: CVE-2026-46628 published to NVD

References

Related threats