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

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). 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
    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

This page as Markdown. Free to reuse under CC BY 4.0 with a link back.