CVE-2026-40186: Apostrophe sanitize-html allowedTags bypass in textarea and option tags

CVE-2026-40186 · Severity: medium · CVSS 6.1 · Published 2026-04-15

A vulnerability in the sanitize-html library allows attackers to bypass security filters and inject malicious scripts into web applications. This occurs when the library is configured to allow certain form-related tags like text areas or dropdown options. An exploit could lead to cross-site scripting (XSS), allowing attackers to steal user session data or perform unauthorized actions on behalf of users.

Technologies: ApostropheCMS, sanitize-html (npm). Vendors: ApostropheCMS, npm.

Quick answers

Is CVE-2026-40186 exploited in the wild?
No. Junglewise Threat Intelligence has no report of CVE-2026-40186 being exploited in the wild.
How severe is CVE-2026-40186?
Medium severity, with a CVSS score of 6.1, published 15 April 2026.
Which products and versions are affected?
sanitize-html (npm) >= 2.17.2, < 2.17.3, SEMVER:introduced=2.17.2,fixed=2.17.3.
Is there a fix for CVE-2026-40186?
Yes. sanitize-html (npm): upgrade to 2.17.3 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.
How is CVE-2026-40186 attacked?
It is attacked over the network, in a software library.
Am I affected by CVE-2026-40186?
Check whether you run ApostropheCMS, ApostropheCMS Sanitize-Html or 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.17.3 or later
    npm install sanitize-html@2.17.3

Technical details

A regression introduced in commit 49d0bb7 causes sanitize-html to skip HTML escaping for text content within elements defined in nonTextTagsArray (specifically <textarea> and <option>). The library incorrectly assumes that the underlying parser (htmlparser2) does not decode entities in these contexts; however, htmlparser2 10.x does decode them. Consequently, an attacker can provide entity-encoded payloads (e.g., &lt;script&gt;) which are decoded by the parser and then written directly to the output without being re-escaped. This allows for complete bypass of the allowedTags enforcement and enables stored XSS. The vulnerability is present in version 2.17.2 and is fixed in version 2.17.3.

Affected products

  • apostrophecms sanitize-html >= 2.17.2, < 2.17.3

Identifiers

  • CVE-2026-40186
  • GHSA-9mrh-v2v3-xpfm

Timeline

  • 2026-04-15: disclosed
  • 2026-04-15: patched
  • 2026-04-16: advisory

References

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