CVE-2026-25543
C# vulnerability analysis and mitigation

Overview

CVE-2026-25543 is a Cross-Site Scripting (XSS) bypass vulnerability in HtmlSanitizer, a .NET library used to clean HTML fragments and documents to prevent XSS attacks. When the <template> tag is explicitly allowed by the application configuration, its contents are not sanitized, enabling attackers to inject malicious scripts. Affected versions are all releases prior to 9.0.892 (stable) and prior to 9.1.893-beta (beta channel, starting from 9.1.878). The vulnerability was published on February 4, 2026, and carries a CVSS v3.1 base score of 6.1 (Medium) and a CVSS v4.0 base score of 6.3 (Medium) (GitHub Advisory, Red Hat CVE).

Technical details

The root cause is improper sanitization of the <template> HTML element's content (CWE-79: Cross-site Scripting; CWE-116: Improper Encoding or Escaping of Output). The <template> tag is special in that browsers do not normally render its contents — however, two bypass paths exist. First, a mutation XSS technique exploits Chromium-based browsers' DOM node depth limit of 512: nesting at least 509 opening tags before a <template> causes the browser to flatten the DOM, effectively "popping out" unsanitized content from within the template and rendering it. Second, if the application also allows the shadowrootmode attribute (via sanitizer.AllowedAttributes.Add("shadowrootmode")), a simple payload like <template shadowrootmode="open"><script>alert('xss')</script></template> bypasses the sanitizer entirely, as the shadow root causes the template contents to be rendered. The fix modifies DoSanitize() to recursively sanitize the IDocumentFragment content of any IHtmlTemplateElement encountered (GitHub Advisory, Patch Commit).

Impact

Successful exploitation allows an attacker to execute arbitrary JavaScript in the context of a victim's browser session on any application that relies on HtmlSanitizer for HTML safety and has explicitly allowed the <template> tag. This can lead to session hijacking, credential theft, unauthorized actions performed on behalf of the user, and defacement of web content. The confidentiality and integrity of user data are at risk, though availability is not directly impacted. The scope is changed (cross-origin), meaning the injected script can affect resources beyond the vulnerable application's immediate context (GitHub Advisory).

Exploitation steps

  1. Reconnaissance: Identify web applications built on .NET that use HtmlSanitizer versions prior to 9.0.892 or 9.1.893-beta and that accept user-supplied HTML input (e.g., rich text editors, comment fields, profile pages).
  2. Confirm template tag allowance: Test whether the application passes <template> tags through the sanitizer by submitting a benign <template> payload and observing whether it is preserved in the output HTML.
  3. Mutation XSS via depth limit (no shadowrootmode required): Craft a payload consisting of at least 509 nested opening tags followed by <template><script>alert('xss')</script></template>. When the browser's DOM parser hits the 512-node depth limit, it flattens the structure, causing the unsanitized <script> inside the template to be rendered.
  4. Shadow DOM bypass (if shadowrootmode is allowed): If the application also permits the shadowrootmode attribute, submit the simpler payload: <div><template shadowrootmode="open"><script>alert('xss')</script></template></div>. The shadow root causes the template contents to render immediately.
  5. Deliver payload to victim: Embed the crafted payload in any user-controlled field that is stored or reflected and later rendered in another user's browser (stored XSS) or via a crafted link (reflected XSS).
  6. Achieve objective: The injected script executes in the victim's browser, enabling session token theft, credential harvesting, keylogging, or further attacks (GitHub Advisory).

Indicators of compromise

  • Logs: Web server or application logs showing requests containing deeply nested HTML tags (500+ opening tags) or <template> elements with shadowrootmode attributes in user-submitted fields; unusual JavaScript payloads (e.g., alert, fetch, document.cookie) embedded within <template> tags in stored content.
  • File System / Database: Stored HTML content in the database containing <template> tags with nested <script> blocks or event handlers, particularly with shadowrootmode="open" or shadowrootmode="closed" attributes.
  • Network: Outbound requests from victim browsers to attacker-controlled domains (e.g., for cookie exfiltration) originating from pages that render user-supplied HTML; unexpected POST requests carrying session tokens or credentials to external endpoints.
  • Application Behavior: Reports from users of unexpected JavaScript dialogs, redirects, or unauthorized actions occurring on pages that display user-generated content.

Mitigation and workarounds

Upgrade HtmlSanitizer to version 9.0.892 (stable) or 9.1.893-beta (beta), which patch the vulnerability by recursively sanitizing the content of <template> elements (GitHub Advisory, NuGet 9.0.892). As a workaround for those unable to upgrade immediately, ensure the <template> tag is not added to the allowed tags list — it is disallowed by default, so only custom configurations that explicitly call sanitizer.AllowedTags.Add("template") are affected. Additionally, avoid allowing the shadowrootmode attribute in sanitizer configurations. Prioritize patching any application that accepts and renders user-supplied HTML with a non-default HtmlSanitizer configuration.

Community reactions

The vulnerability was discovered and reported by security researcher nsysean, who is credited in the official GitHub Security Advisory (GitHub Advisory). The maintainer (mganss) responded promptly, publishing the advisory and patch on February 3–4, 2026. No significant broader media coverage or notable social media discussion has been identified beyond standard vulnerability database aggregation.

Additional resources


SourceThis report was generated using AI

Related C# vulnerabilities:

CVE ID

Severity

Score

Technologies

Component name

CISA KEV exploit

Has fix

Published date

GHSA-p5rm-jg5c-8c77MEDIUM6.1
  • C# logoC#
  • Microsoft.OpenApi.Kiota
NoYesJul 24, 2026
CVE-2026-62946MEDIUM5.1
  • C# logoC#
  • Magick.NET-Q8-x86
NoYesJul 24, 2026
CVE-2026-62363MEDIUM5
  • C# logoC#
  • Magick.NET-Q8-AnyCPU
NoYesJul 24, 2026
CVE-2026-62343MEDIUM4.7
  • C# logoC#
  • Magick.NET-Q8-x86
NoYesJul 24, 2026
GHSA-464c-974j-9xm6LOW3.3
  • JavaScript logoJavaScript
  • @aws-cdk/aws-codebuild
NoYesJul 24, 2026

Free Vulnerability Assessment

Benchmark your Cloud Security Posture

Evaluate your cloud security practices across 9 security domains to benchmark your risk level and identify gaps in your defenses.

Request assessment

Get a personalized demo

Ready to see Wiz in action?

"Best User Experience I have ever seen, provides full visibility to cloud workloads."
David EstlickCISO
"Wiz provides a single pane of glass to see what is going on in our cloud environments."
Adam FletcherChief Security Officer
"We know that if Wiz identifies something as critical, it actually is."
Greg PoniatowskiHead of Threat and Vulnerability Management