Summary
A sanitizer bypass in sanitize-html allows content wrapped in a disallowed xmp tag to be reinterpreted as active HTML or JavaScript after sanitization.
When applications trust the library's default configuration and render sanitized output back to users, attacker-controlled payloads can become stored cross-site scripting (XSS) in ApostropheCMS and other Node.js applications.
Affected context
The vulnerability appears in Node.js applications that rely on sanitize-html (prior to 2.17.4) with the default disallowedTagsMode: 'discard' behavior to clean user-supplied HTML content.
It is most relevant to content management systems like ApostropheCMS and any other platforms that:
- Accept rich text or HTML input from users
- Sanitize this input server-side using sanitize-html
- Store and later render the sanitized content in browsers
The issue specifically involves attacker-controlled content placed within an xmp element, which can be transformed into live markup or script when output is rendered.
Exploit preconditions
- Attack surface: Web application interfaces that accept and later display user-generated HTML or rich text content (e.g., CMS fields, comments, posts).
- Required access: Ability to submit or edit content that is sanitized by sanitize-html and subsequently stored (any authenticated or anonymous contributor role with such permissions).
- Trigger point: Rendering of the sanitized content in a user's browser, where the
xmp-wrapped payload is interpreted as active HTML or JavaScript. - Why exploitation is possible: The sanitizer's default handling of disallowed tags in
disallowedTagsMode: 'discard'fails to neutralize content insidexmp, allowing the inner payload to bypass filtering and execute when the page is viewed.
Why this happens
The underlying issue is a sanitization logic flaw aligned with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting).
sanitize-html's default behavior for disallowed elements assumes that discarding the tag itself is sufficient to neutralize unsafe content. However, the xmp tag behaves differently from typical elements: its contents can be treated as raw text and later reinterpreted as markup when the tag is removed or mishandled.
Because the sanitizer does not fully account for these semantics, attacker-controlled data inside xmp can survive the sanitization step and become active HTML or script on output, undermining the trust boundary between untrusted input and rendered content.
Potential impact
- Execution of arbitrary JavaScript in victims' browsers when they view affected pages
- Theft of session tokens or other sensitive data accessible via the DOM
- Performance of actions on behalf of logged-in users (e.g., content changes, administrative actions, or configuration updates)
- Defacement of site content or injection of malicious UI elements and phishing flows
- Use of compromised pages as a launchpad for further client-side attacks within the same origin
General mitigation guidance
Mitigation focuses on strengthening HTML sanitization boundaries and reducing trust in library defaults:
- Treat all user-supplied HTML as untrusted and ensure sanitization logic explicitly handles edge-case tags like
xmp,template, and similar raw-text elements. - Prefer an allowlist-based sanitization model with minimal permitted tags and attributes, adding new ones only when strictly required.
- Enforce contextual output encoding on top of sanitization, especially for dynamic content inserted into HTML, attributes, or script-related contexts.
- Limit where rich HTML is allowed; use plain text fields with escaping for most user input and reserve HTML only for tightly controlled roles.
- Apply strict privilege separation so that untrusted or semi-trusted users cannot introduce complex markup that relies solely on sanitizer behavior for safety.
How teams detect issues like this
Detection strategies generally combine code-level inspection and behavioral testing:
- Review server-side and middleware code for usage of sanitize-html, noting the configured
disallowedTagsModeand any reliance on default options. - Use static analysis or grep-based checks to inventory all sanitization points, then verify they do not assume that discarding disallowed tags is sufficient for safety.
- Develop security test cases that submit payloads within
xmp(and other special tags) to see whether stored content reappears as executable HTML or JavaScript when rendered. - Incorporate automated security testing (e.g., SAST/DAST tools) into CI pipelines to flag suspicious sanitization patterns and unencoded dynamic content.
- During manual code review, treat trust in third-party sanitization libraries as a red flag and verify that layered defenses (sanitization plus encoding) are in place.

