CVE-2026-46637: Twig: HTML-output filters in twig/* extras incorrectly declared `is_safe => ['all']`
Description
Several filters in the twig/ extras packages are registered with issafe => ['all'], which tells Twig's autoescaper to treat their output as safe in every context (html, js, css, url, ...). The output of these filters is plain text or HTML markup, neither of which is safe in every escaping context.
Affected filters:
- htmltomarkdown (twig/markdown-extra) emits plain Markdown text. league/html-to-markdown decodes HTML entities when producing code spans and fenced blocks, so an attacker-controlled <code><img src=x onerror=alert(1)></code> becomes <img src=x onerror=alert(1)> , which renders live when interpolated into an HTML page. - markdowntohtml (twig/markdown-extra) emits HTML. Safe in an HTML context but not in JS, CSS or URL contexts (e.g. when interpolated into an inline <script> block). - inlinecss (twig/cssinliner-extra) emits HTML with inlined styles. Same constraint as markdowntohtml.
In all three cases, issafe => ['all'] causes the autoescaper to emit the output verbatim in any context, even when the developer never wrote |raw. In a context such as a JS string or a URL parameter, this produces unescaped HTML and is exploitable as XSS.
Resolution
- htmltomarkdown no longer claims to be safe in any escaping context; its plain-text output is now autoescaped for the surrounding context. - markdowntohtml and inlinecss are now declared issafe => ['html'], asserting only what they actually guarantee.
Credits
Twig would like to thank Claude Mythos Preview (via Project Glasswing) for reporting the issue and providing the fix for htmltomarkdown and markdowntohtml in twig/markdown-extra, and Christophe Coevoet for extending the audit to inlinecss in twig/cssinliner-extra.
Other sources
Twig is a template language for PHP. Prior to 3.26.0, several filters in twig/markdown-extra and twig/cssinliner-extra are registered with issafe => [all], causing Twig to treat plain text or HTML output as safe in HTML, JavaScript, CSS, URL, and other contexts where the output is not properly escaped. This issue is fixed in version 3.26.0.
— MITRE
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
composer/twig/cssinliner-extrato a version that resolves this vulnerability.Fixed in 3.26.0 - Upgrade
Upgrade
composer/twig/markdown-extrato a version that resolves this vulnerability.Fixed in 3.26.0 - Upgrade
Upgrade
twig/markdown-extrato a version that resolves this vulnerability.Fixed in 3.26.0 - Upgrade
Upgrade
twig/cssinliner-extrato a version that resolves this vulnerability.Fixed in 3.26.0 - Configuration
Remove/adjust the filter’s is_safe declaration so Twig autoescapes html_to_markdown plain-text output in the surrounding context (issue: plain-text output was emitted verbatim due to is_safe => ['all']).
twig/markdown-extra (html_to_markdown filter) is_safe = no longer claims to be safe in any escaping context; plain-text output is autoescaped for the surrounding context - Configuration
Change markdown_to_html is_safe from ['all'] to ['html'] so its HTML output is only treated as safe for HTML context, not for JS/CSS/URL contexts.
twig/markdown-extra (markdown_to_html filter) is_safe = ['html'] - Configuration
Change inline_css is_safe from ['all'] to ['html'] so its inlined-HTML output is only treated as safe for HTML context, not for JS/CSS/URL contexts.
twig/cssinliner-extra (inline_css filter) is_safe = ['html']
Event History
Frequently Asked Questions
What is the severity of CVE-2026-46637?
CVE-2026-46637 has a risk rating of 52, indicating a moderate severity level.
What type of vulnerability is CVE-2026-46637?
CVE-2026-46637 is an XSS (Cross-Site Scripting) vulnerability due to improper handling of filters in Twig's extras packages.
How do I fix CVE-2026-46637?
To mitigate CVE-2026-46637, review and update the Twig extras packages to secure versions that do not register filters with 'is_safe' set to ['all'].
Which packages are affected by CVE-2026-46637?
CVE-2026-46637 affects the composer/twig/cssinliner-extra and composer/twig/markdown-extra packages.
When was CVE-2026-46637 published?
CVE-2026-46637 was published on May 21, 2026.