Skip to main content

Twig Extras CVE-2026-46637

MEDIUM
Improper Encoding or Escaping of Output (CWE-116)
2026-05-21 https://github.com/twigphp/Twig GHSA-jv8m-2544-3pg3
5.1
CVSS 4.0 · Vendor: https://github.com/twigphp/Twig
View

Attack ChainAIDerived

Hypothetical attack flow derived from CVE metadata – not a confirmed exploit chain

  1. Access
    Supply HTML entity-encoded payload in user input
  2. Delivery
    Content stored and later passed to html_to_markdown or markdown_to_html filter
  3. Exploit
    league/html-to-markdown decodes entities or filter emits raw HTML
  4. Execution
    Twig autoescaper suppresses re-encoding due to is_safe=['all']
  5. Persist
    Unescaped output rendered in browser JS/CSS/HTML context
  6. Impact
    XSS payload executes

Vulnerability Assessment

Weakness
CWE
OWASP Top 10:2025
A05:2025 - Injection
ASVS 5.0
V1 - Encoding and Sanitization Output encoding for downstream
Exploitation Conditions

Exploitation requires three concurrent conditions: (1) attacker-controlled input must reach one of the three affected filters - html_to_markdown, markdown_to_html, or inline_css - in a Twig template; (2) the filter's output must be interpolated into a non-HTML escaping context (a JS string literal, a CSS value, or a URL parameter) for markdown_to_html and inline_css, or any HTML-rendering context for html_to_markdown given the entity-decoding gadget; and (3) the application must be running twig/markdown-extra or twig/cssinliner-extra below version 3.26.0. Exploitation is limited by the fact that many deployments using these filters operate only in HTML body contexts, where markdown_to_html and inline_css are genuinely safe; only the html_to_markdown vector is exploitable in a pure HTML body context via the entity-decoding path. Authentication requirements are not confirmed from available data, as no CVSS vector is provided - exploitability depends entirely on whether the attacker can supply input to the affected filter pipeline, which varies by application design.

Impact

No CVSS vector or score is available for this CVE, so quantitative risk scoring cannot be applied. No EPSS probability is available. The vulnerability is not listed in the CISA KEV catalog and no public exploit code has been identified at time of analysis. Despite the absence of CVSS data, the qualitative risk profile is meaningful: exploitability requires attacker-controlled content to pass through an affected filter and then be interpolated into a JS, CSS, or URL context in a Twig template - a combination that is plausible in content-management and email-rendering applications built on Symfony/Twig. The html_to_markdown vector is especially noteworthy because it creates a persistent XSS path that bypasses developer intent (no |raw was written), making it harder to audit by code review alone. The fix is available as version 3.26.0 with no known workaround complexity, which lowers the remediation cost and argues for prompt patching over detective controls. Overall: moderate-to-high priority for applications that render user-supplied content through these filters; low priority for applications where filter inputs are fully trusted.

Exploit ScenarioDerived

An attacker submits content containing a crafted HTML code element such as '<code>&lt;img src=x onerror=alert(document.cookie)&gt;</code>' to a web application that stores and later renders user content through Twig's html_to_markdown filter. When the template interpolates the filter output into a page - even inside what appears to be an HTML body context - the league/html-to-markdown library decodes the entities into a live backtick-wrapped image tag, which the misconfigured autoescaper emits verbatim, executing the payload in the victim's browser. A second path exists for markdown_to_html or inline_css if a developer embeds their output inside an inline script block, where the unescaped HTML characters break out of the JavaScript string context.

This Month Plan within 30 days. Why: MEDIUM severity (CVSS 4.0-6.9).
Patch available 0.1% exploitation probability (EPSS)

Get an e-mail when this CVE is exploited, patched or re-scored. Free account.

Alert me

AnalysisAIv1 – May 21, 2026

Cross-site scripting in twig/markdown-extra and twig/cssinliner-extra arises from three filters - html_to_markdown, markdown_to_html, and inline_css - being incorrectly registered with is_safe => ['all'], which instructs Twig's autoescaper to suppress output encoding in every context including JS, CSS, and URL. When attacker-controlled content flows through these filters and the result is interpolated into a non-HTML context such as an inline script block, the autoescaper emits the raw output verbatim, enabling XSS without the developer ever using the explicit |raw bypass. Notably, html_to_markdown has an additional entity-decoding gadget via league/html-to-markdown that converts encoded HTML entities back to live markup during code span generation, creating a secondary injection path even in HTML contexts. No public exploit identified at time of analysis and no CISA KEV listing.

RemediationAI

Vendor-released patch: 3.26.0 for both twig/markdown-extra and twig/cssinliner-extra. Upgrade both packages using Composer: run 'composer update twig/markdown-extra twig/cssinliner-extra' and verify the installed version reaches 3.26.0 or higher. The fix retracts the is_safe => ['all'] claim: html_to_markdown now declares no safe context (its output is re-escaped for the surrounding context), and markdown_to_html and inline_css are narrowed to is_safe => ['html']. If an immediate upgrade is not feasible, the most targeted compensating control is to audit every Twig template that uses these three filters and confirm the filter output is only ever interpolated inside an HTML body context, never inside a script block, style attribute, or URL parameter - manually adding |escape('js'), |escape('css'), or |url_encode as appropriate for non-HTML contexts. Note that this manual audit is error-prone and does not address the html_to_markdown entity-decoding vector; upgrading to 3.26.0 is strongly preferred. The full advisory is at https://github.com/twigphp/Twig/security/advisories/GHSA-jv8m-2544-3pg3.

Affected Packages

composer twig/cssinliner-extra fix: 3.26.0
composer twig/markdown-extra fix: 3.26.0

Source: OSV (Open Source Vulnerabilities)

Affects your stack

Affects 2 packages in composer

Checking this CVE against your own stacks and servers is part of the Basic plan and up.

Technical ContextAI · show details

Twig's autoescaper assigns each registered filter a set of safe output contexts via the is_safe metadata flag, allowing it to skip re-encoding filter output in those contexts. CWE-116 (Improper Encoding or Escaping of Output) is the root cause: the three affected filters overclaim their safety guarantee by declaring is_safe => ['all'] rather than the narrower is_safe => ['html'] that their actual output (HTML markup or Markdown text) warrants. The affected Composer packages are pkg:composer/twig/markdown-extra and pkg:composer/twig/cssinliner-extra, both below version 3.26.0. The html_to_markdown filter introduces a compounding issue through its dependency league/html-to-markdown, which decodes HTML entities when generating code spans and fenced code blocks - meaning HTML entity-encoded payloads survive the HTML-to-Markdown conversion as live markup rather than inert text. The markdown_to_html and inline_css filters emit HTML, which is safe within an HTML escaping context but becomes unescaped content when Twig interpolates it into a JavaScript string literal, CSS property value, or URL parameter.

Know when the next one hits your stack

  • Watch products and get an email when something new is published
  • Check this CVE against your own stack and servers
  • Exploit and PoC references, threat intelligence from 22 sources

No credit card · 7-day full trial

Severity by source

Vendor (https://github.com/twigphp/Twig) PRIMARY 5.1 MEDIUM
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N

Primary rating from Vendor (https://github.com/twigphp/Twig) · only source for this CVE.

CVSS VectorVendor: https://github.com/twigphp/Twig

Attack Vector
Network
Attack Complexity
Low
Attack Requirements
None
Privileges Required
Low
User Interaction
Passive
Vulnerable system: Confidentiality
None
Vulnerable system: Integrity
None
Vulnerable system: Availability
None
Subsequent system: Confidentiality
Low
Subsequent system: Integrity
Low
Subsequent system: Availability
None

Lifecycle Timeline

1
CVSS changed
Jul 14, 2026 - 22:22 NVD
5.1 (MEDIUM)

DescriptionCVE.org

Description

Several filters in the twig/* extras packages are registered with is_safe => ['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:

  • html_to_markdown (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>&lt;img src=x onerror=alert(1)&gt;</code> becomes ` <img src=x onerror=alert(1)> `, which renders live when interpolated into an HTML page.
  • markdown_to_html (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).
  • inline_css (twig/cssinliner-extra) emits HTML with inlined styles. Same constraint as markdown_to_html.

In all three cases, is_safe => ['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

  • html_to_markdown no longer claims to be safe in any escaping context; its plain-text output is now autoescaped for the surrounding context.
  • markdown_to_html and inline_css are now declared is_safe => ['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 html_to_markdown and markdown_to_html in twig/markdown-extra, and Christophe Coevoet for extending the audit to inline_css in twig/cssinliner-extra.

Threat Intelligence Overview

EPSS Score
0.1%
Top 81% exploitable
Threat Intel
1
1 source
Data Quality
4 sources
Confidence: Medium

How this decision was reached

The engine reads each signal below and applies a fixed list of rules from top to bottom. The first rule that matches sets the recommended action – like a statement, every line is shown.

SignalValue
Severity MEDIUM
CISA KEV No
Public POC No
EPSS 0.1%
Patch available Yes
Active threat No
Deciding rule
MEDIUM severity (CVSS 4.0-6.9)
What every action level means
Emergency Immediate action required. Criteria: CRITICAL + in CISA KEV (actively exploited) without patch, OR CRITICAL + EPSS > 30% without patch, OR CRITICAL + active threat signals without patch.
Act Now Prioritize within 24-48h. Criteria: in KEV with patch available, OR CRITICAL + public POC, OR HIGH + EPSS > 10%, OR CRITICAL + active threat, OR any CRITICAL severity.
This Week Schedule remediation this week. Criteria: HIGH severity (CVSS 7.0-8.9). Patch within normal change window.
This Month Plan within 30 days. Criteria: MEDIUM severity (CVSS 4.0-6.9), lower exploitation probability. Include in regular patch cycle.
Monitor Track and reassess. Criteria: LOW severity (CVSS 0.1-3.9), minimal exploitation risk. No immediate action needed.

SSVC AssessmentENISA

SSVC Decision· derived
Scheduled
Exploitation· derived
None
System Exposure· derived
Open
Automatable· derived
No
Human Impact· derived
Medium

Priority Score

26
Low Medium High Critical
KEV: 0
EPSS: 0
CVSS: +26
PoC: 0
Weaponized: 0
Threat intel: 0
Gov advisory: 0

Attack Technique

Cross-Site Scripting occurs when an application accepts untrusted data and sends it to a web browser without proper validation or encoding.

Affected Products (CPE)CVE.org

pkg:composer/twig_markdown-extra
pkg:composer/twig_cssinliner-extra

This site uses cookies essential for authentication and security. No tracking or analytics cookies are used. Privacy Policy