CVE-2026-40186: sanitize-html Package Allows Bypass of allowedTags via Entity-Decoded Text

sanitize-html Updated 16 Apr 2026

Summary

16/04/2026
Yes i
Moderate
6.1

CVE-2026-40186: sanitize-html allowedTags Bypass via Entity-Decoded Text in nonTextTags Elements. Affects sanitize-html versions >= 2.17.2, < 2.17.3. Fixed in 2.17.3. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

sanitize-html is an npm package that sanitizes HTML input to prevent XSS attacks by allowing only specified tags and attributes. It is commonly used in web applications to ensure that user-generated content is safe for rendering. The package provides a configuration option called allowedTags, which defines which HTML tags are permitted. However, a recent vulnerability has been identified that allows attackers to bypass this restriction under certain conditions.

Vulnerability Detail

The vulnerability arises from a regression introduced in commit 49d0bb7, which incorrectly handles entity-encoded HTML within nonTextTagsArray elements, specifically <textarea> and <option>. When entity-encoded HTML is processed, it is decoded before being passed to the sanitizer, allowing arbitrary HTML tags to be injected, including potentially harmful scripts. This leads to a complete bypass of the allowedTags filter, posing a significant risk of stored XSS attacks, where an attacker can inject malicious scripts that execute in the context of the user's session.

How To Fix

Latest published version: 2.18.1 as of 23 Oct 2026

npm install sanitize-html@2.18.1

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

2.17.3

This is the first release that contains the fix.

npm install sanitize-html@2.17.3

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If you cannot immediately update the package, you can implement a temporary workaround by avoiding the use of <option> and <textarea> tags in your allowedTags configuration. This will prevent the vulnerability from being exploited until you can apply the patch.

Conclusion

The CVE-2026-40186 vulnerability in the sanitize-html package poses a significant risk by allowing the injection of arbitrary HTML tags through entity-decoded text in <textarea> and <option> elements. It is crucial to update to the patched version to protect your application from potential XSS attacks.

See every vulnerability recorded for sanitize-html →

Share this vulnerability

FAQ

CVE-2026-40186 is a vulnerability in the sanitize-html package that allows attackers to bypass allowedTags restrictions through entity-decoded text in <textarea> and <option> elements.

If your application uses sanitize-html with <option> or <textarea> in its allowedTags configuration, it may be vulnerable to XSS attacks, allowing attackers to inject malicious scripts.

You should update sanitize-html to version 2.17.3 or later to mitigate the vulnerability. Use the command 'npm install sanitize-html@2.17.3' to update.

Yes, you can use Vulert, which monitors and alerts for open-source vulnerabilities in your software using just package-lock.json. You can check your application at Vulert Scanner without signing up.

The CVSS score of this vulnerability is 6.1, indicating a moderate severity level.

Related vulnerabilities

Recent vulnerabilities recorded for sanitize-html.

How To Fix

Latest published version: 2.18.1 as of 23 Oct 2026

npm install sanitize-html@2.18.1

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

2.17.3

This is the first release that contains the fix.

npm install sanitize-html@2.17.3

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback