# CVE-2021-26540: Apostrophe sanitize-html hostname whitelist bypass in iframe validation

Source: https://junglewise.ai/threats/cve-2021-26540-apostrophe-sanitize-html-hostname-whitelist-bypass-in-iframe  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2021-05-06. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

CVE-2021-26540 · Severity: low · CVSS 3.1 · Published 2021-05-06

sanitize-html is a Node.js library used to strip potentially malicious HTML from user input. A flaw in its iframe hostname validation allows attackers to bypass the whitelist of allowed iframe sources when relative URLs are enabled, potentially enabling injection of iframes pointing to attacker-controlled or unintended domains. This could lead to cross-site scripting or credential theft if untrusted HTML is processed and displayed to users.

Technologies: [sanitize-html (npm)](https://junglewise.ai/threats/technologies/sanitize-html). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is CVE-2021-26540 exploited in the wild?** No. Junglewise Threat Intelligence has no report of CVE-2021-26540 being exploited in the wild.

**How severe is CVE-2021-26540?** Low severity, with a CVSS score of 3.1, published 6 May 2021.

**Which products and versions are affected?** sanitize-html (npm) SEMVER:introduced=0,fixed=2.3.2.

**Is there a fix for CVE-2021-26540?** Yes. sanitize-html (npm): upgrade to 2.3.2 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is CVE-2021-26540 attacked?** It is attacked over the network, in a software library.

**Am I affected by CVE-2021-26540?** Check whether you run sanitize-html (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- sanitize-html (npm): upgrade to 2.3.2 or later

  ```sh
  npm install sanitize-html@2.3.2
  ```


## Technical details

The vulnerability is an improper input validation flaw (CWE-20) in sanitize-html versions before 2.3.2. When the allowIframeRelativeUrls option is enabled, the library fails to properly validate hostnames specified in the allowedIframeHostnames whitelist. An attacker can bypass this whitelist using a specially crafted src value beginning with a forward slash followed by a backslash and a domain name (e.g., "/\example.com"), exploiting differences in how the WHATWG URL parser and browsers interpret URL components. The fix, merged in PR #460, implements proper protocol cleaning before URL parsing to address the inconsistency. No authentication or special preconditions are required; any application processing untrusted HTML with this option enabled is vulnerable.

## Affected products

- Apostrophe Technologies sanitize-html before 2.3.2

## Identifiers

- CVE-2021-26540
- GHSA-mjxr-4v3x-q3m4

## Timeline

- 2021-02-08: disclosed: Published on NVD
- 2021-01-26: patched: Fixed in version 2.3.2

## References

- [https://github.com/apostrophecms/sanitize-html/pull/460](https://github.com/apostrophecms/sanitize-html/pull/460)

## Related threats

- [sanitize-html incomplete : meta refresh URL scheme bypass](https://junglewise.ai/threats/cve-2026-113661-apostrophecms-incomplete-meta-http-equiv-refresh-content-still)
- [ApostropheCMS sanitize-html: SMIL animation namespace-prefix bypass allows javascript: URI injection (XSS)](https://junglewise.ai/threats/cve-2026-113657-apostrophecms-is-an-open-source-node-js-content-management)
- [sanitize-html noscript XSS bypass](https://junglewise.ai/threats/cve-2026-113654-apostrophecms-is-an-open-source-node-js-content-management)
- [sanitize-html unbounded recursion denial of service](https://junglewise.ai/threats/cve-2026-113650-apostrophecms-is-an-open-source-node-js-content-management)
- [sanitize-html stored XSS via SVG SMIL URI-list scheme bypass](https://junglewise.ai/threats/cve-2026-84371-sanitize-html-stored-xss-via-svg-smil-uri-list-scheme-bypass)
