CVE-2026-46628: Twig: The `spaceless` filter implicitly marks its output as safe
Description The spaceless filter is registered with issafe = ['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: The filter is deprecated but still functional.
Published May 21, 2026
Affected packages
twig/twig
- Ecosystem
- Composer (PHP)
- Affected
- < 3.26.0
- Fixed in
- 3.26.0
- Check
composer show twig/twig
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Description
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.
Resolution
The spaceless filter no longer marks its output as safe. Documentation has been updated to warn that spaceless should not be applied to unsanitised user input.
Credits
Twig would like to thank Pierre Rudloff for reporting the issue.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More Composer (PHP) vulnerabilities
All Composer (PHP) entriesCVE-2026-49981
Twig: Sandbox filter, tag and function allow-list bypass when sandbox state changes between renders for a cached `Template`
high8.7Jul 1, 2026CVE-2026-48805
Twig: Sandbox state regression in deprecated internal wrappers in `src/Resources/core.php`
lowJun 30, 2026CVE-2026-48806
Twig: Sandbox `__toString()` policy bypass via dynamic mapping keys
mediumJun 30, 2026CVE-2026-48807
Twig: Sandbox `__toString()` policy bypass via `Traversable` in `join` and `replace` filters
mediumJun 30, 2026CVE-2026-48808
Twig: Sandbox property allowlist bypass via the `column` filter under `SourcePolicyInterface`
mediumJun 30, 2026CVE-2026-24425
Twig: Possible sandbox bypass when using a source policy
high8.8No fixJun 5, 2026
