Advisory Database
  • Advisories
  • Dependency Scanning
  1. composer
  2. ›
  3. twig/twig
  4. ›
  5. CVE-2026-46628

CVE-2026-46628: Twig: The `spaceless` filter implicitly marks its output as safe

May 21, 2026

The spaceless filter is registered with is_safe => ['html'], which means Twig’s autoescaper does not escape its output in an HTML context. As a result, applying spaceless to attacker-controlled input that contains markup emits the markup unescaped even when the developer never wrote |raw and autoescape is enabled.

Example:

{% set payload = '<script>alert()</script>' %}
{{ payload }}          {# escaped #}
{{ payload|spaceless }} {# not escaped #}

The filter is deprecated but still functional. With the deprecation, some downstream projects (e.g. Drupal modules) have duplicated the filter and inherited the same is_safe flag.

References

  • github.com/FriendsOfPHP/security-advisories/blob/master/twig/twig/CVE-2026-46628.yaml
  • github.com/advisories/GHSA-4j38-f5cw-54h7
  • github.com/twigphp/Twig/security/advisories/GHSA-4j38-f5cw-54h7
  • nvd.nist.gov/vuln/detail/CVE-2026-46628
  • symfony.com/cve-2026-46628

Code Behaviors & Features

Detect and mitigate CVE-2026-46628 with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Learn more about Dependency Scanning →

Affected versions

All versions before 3.26.0

Fixed versions

  • 3.26.0

Solution

Upgrade to version 3.26.0 or above.

Impact 5.4 MEDIUM

CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N

Learn more about CVSS

Weakness

  • CWE-116: Improper Encoding or Escaping of Output

Source file

packagist/twig/twig/CVE-2026-46628.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Wed, 10 Jun 2026 12:19:55 +0000.