HtmlSanitizer has a bypass via template tag
Impact
If the template tag is allowed, its contents are not sanitized. The template tag is a special tag that does not usually render its contents, unless the shadowrootmode attribute is set to open or closed.
The lack of sanitization of the template tag brings up two bypasses:
- it is still possible to forcibly render the contents of a
<template>tag through mutation XSS. The DOM parsers in browsers such as Chromium have a node depth limit of 512 and tags which are beyond that depth are flattened. This in turn allows elements within<template>(which are not sanitized) to be effectively 'popped out'. An example would look like this:<div>[...]<template><script>alert('xss')</script>where[...]denotes at least another 509 opening<div>tags. - If in addition to the template tag, the
shadowrootmodeattribute is allowed throughsanitizer.AllowedAttributes.Add("shadowrootmode");, the simple payload of<div><template shadowrootmode="open"><script>alert('xss')</script>would bypass the sanitizer. This is because such usage of<template>attaches a shadow root to its parent:<div>, and its contents will be rendered.
Note that the default configuration is not affected because the template tag is disallowed by default.
Patches
The problem has been patched in versions 9.0.892 and 9.1.893-beta.
Workarounds
Disallow the template tag. It is disallowed by default.
Resources
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template
Affected software
Click a technology to see all vulnerabilities affecting it.
| Platform | Package | Vulnerable versions | Fixed in |
|---|---|---|---|
| .NET (NuGet) | HtmlSanitizer | < 9.0.892, >= 9.1.878-beta, < 9.1.893-beta | 9.0.892, 9.1.893-beta |
References
- https://github.com/mganss/HtmlSanitizer/security/advisories/GHSA-j92c-7v7g-gj3f
- https://nvd.nist.gov/vuln/detail/CVE-2026-25543
- https://github.com/mganss/HtmlSanitizer/commit/0ac53dca30ddad963f2b243669a5066933d82b81
- https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template
- https://github.com/mganss/HtmlSanitizer
- https://github.com/mganss/HtmlSanitizer/releases/tag/v9.0.892
- https://www.nuget.org/packages/HtmlSanitizer/9.0.892
- https://www.nuget.org/packages/HtmlSanitizer/9.1.893-beta
- CVSS vector
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N- Weakness (CWE)
CWE-116, CWE-79- Platform
- .NET (NuGet)
- Package
HtmlSanitizer- Disclosed
- 03.02.2026
- Updated
- 11.10.2026 11:23
Sources and licenses
OSV / GitHub Advisory Database - GHSA-j92c-7v7g-gj3f - CC BY 4.0
Vulnerability history: HtmlSanitizer
All published vulnerabilities of this package (.NET (NuGet)), newest first. Shows whether this is a one-off slip or a package that needs watching.
- Total entries
- 3
- First → latest
- 01.2021 02.2026
- Without a fix
- 0
- Exploited in attacks
- 0
Severity breakdown
- Medium 2
- Low 1
Disclosures per year
- 2021: 1
- 2022: 0
- 2023: 1
- 2024: 0
- 2025: 0
- 2026: 1
-
HtmlSanitizer has a bypass via template tag this entry
Know which vulnerabilities affect your application
With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.