Elestia Open Source Ratings
6.8

sanitize-html

Reasonable, with limits. 7th of 10 web security libraries.

sanitize-html is ApostropheCMS's allowlist-based HTML sanitizer for Node. It parses strings with htmlparser2 and needs no DOM. It is a reasonable server-side choice with good configuration. But 2026 brought a run of bypass advisories, one of them critical in the default setup, and DOMPurify is generally the more robust sanitizer.

Best for: Node back ends that must clean user HTML on the server without jsdom, and that need fine control over the tags and attributes they allow and how they are rewritten.

WebsiteGitHubnpm

Scores

Overall6.8

How strongly do we recommend it for a new project today?

Claude Opus 5.5: 6.0, likely 5.0 to 7.0

It is a capable, maintained server-side sanitizer that needs no DOM, and that is enough for many Node apps. But many 2026 bypasses, including one in the default setup, and a parser that can disagree with browsers make DOMPurify the stronger pick for most new projects. On the server, run DOMPurify with jsdom or use isomorphic-dompurify. Choose sanitize-html when its rewrite hooks or the lack of a DOM matter, and keep it updated.

  • advisories.last24Months: 10 recent advisories.
  • peers DOMPurify: Larger, faster growing, and more commits in the last year.
  • npm-compare.com/dompurify,sanitize-html: Positions it for the server and DOMPurify for DOM-based filtering.

GPT-6.2 Sol: 7.5, likely 6.4 to 8.5

For a new Node.js app that needs a precise policy for user-submitted rich text, sanitize-html is a strong pick because it handles HTML fragments directly and ships security fixes regularly. DOMPurify is the stronger browser-first choice, with a smaller bundle and an OWASP recommendation. The recent runtime break and recurring parser fixes temper the recommendation, particularly for teams with older deployment targets or unusually permissive markup policies.

Needed by many4.4

How many developers need a tool for this job?

Claude Opus 5.5: 4.5, likely 3.5 to 5.5

Cleaning user HTML is needed only by apps that accept rich text, comments or user markdown output. That is a clear but limited share of web projects. sanitize-html also targets the server side mainly, which narrows it further than a sanitizer that runs everywhere.

GPT-6.2 Sol: 4.2, likely 3.2 to 5.3

Many web developers work on sites that display user content, but an HTML sanitizer is mainly needed when that content must retain markup. sanitize-html can work across Node.js frameworks and covers HTML cleanup within the wider web security category. The developer survey measures web work broadly, so it gives only an indirect estimate of demand.

Helps a lot6.9

How well does it do the job for those who need it?

Claude Opus 5.5: 6.0, likely 5.0 to 7.0

Its configuration is rich: allowed tags, attributes, schemes, styles and transformTags. It also needs no DOM on the server. But it parses with htmlparser2 instead of a browser-grade DOM, and 2026 exposed many bypasses, including mutation XSS, nonTextTags handling and an xmp passthrough in the default mode. Types live in a separate community package. DOMPurify does the core job more robustly.

GPT-6.2 Sol: 7.8, likely 6.7 to 8.8

The string-in, string-out API makes basic use easy, and detailed allowlists and transforms cover demanding rich-text policies without a server-side DOM. The examples make basic calls easy for coding agents to draft, though custom policies still need review and the types ship separately. An independent benchmark found good Node.js performance on one article, but its results varied by sanitizer policy and its browser bundle comparison favored DOMPurify.

Holds up over time7.1

Will it still be a good choice in two years?

Claude Opus 5.5: 7.0, likely 6.0 to 8.0

A company that sells a CMS on top of it maintains it. There were 10 npm versions last year, and the latest came ten days before the read date. Folding it into the Apostrophe monorepo ties it to an active, funded codebase. The repository shows no GitHub releases, and the recent Node 22.12+ requirement may break older deployments.

  • npm versionsLastYear: 10 versions; latest published 2026-11-11.
  • github commitsLastYear: 377 commits in the monorepo, which covers all of ApostropheCMS.
  • bluesky top: Apostrophe releases ship batches of security fixes.
  • npm-compare.com/dompurify,sanitize-html: The current runtime requires Node 22.12+.

GPT-6.2 Sol: 7.2, likely 6.0 to 8.4

ApostropheCMS still maintains the package in its monorepo, with ten npm versions in the past year and a November patch. The Node.js minimum rose in the 2.17.6 patch, and downstream projects reported startup failures or had to raise their own runtime minimums. Repository-wide activity gives limited insight into package-level response times and how many people can publish.

Used widely6.7

How many use it, and is that growing?

Claude Opus 5.5: 7.0, likely 6.0 to 8.0

73M downloads in 4 weeks and about 90k dependent repos make it very widely used, though much of that is transitive. Its download ratio of 4.7 is slightly above the 4.1 median, so it holds its ground. DOMPurify is far bigger at about 402M, and it grew faster with a ratio of 6.9.

  • npm downloadsLast4Weeks: 73.0M, against 15.5M a year before (ratio 4.7).
  • dependents: 89,985 repos and 1,495 packages; DOMPurify has 56,633 repos.
  • peers DOMPurify: 401.8M downloads, ratio about 6.9.

GPT-6.2 Sol: 6.3, likely 5.3 to 7.4

ecosyste.ms found about 90,000 dependent repositories and 1,495 dependent npm packages, ahead of DOMPurify on the sampled repository count and behind js-xss. Four-week installs grew 4.72 times year over year, modestly ahead of the 4.1 catalog baseline and behind DOMPurify’s 6.89 times. Automated and transitive installs blur that trend, and the current repository’s stars and Bluesky links mainly reflect the broader CMS.

  • dependents repos and packages: 89,985 repositories and 1,495 npm packages in the collector’s sample.
  • npm downloadsLast4Weeks and downloadsSame4WeeksYearAgo, medianDownloadsRatio: 73.0 million versus 15.5 million installs, against a 4.1 growth baseline.
  • peers DOMPurify and js-xss: DOMPurify installs grew faster, while js-xss had more sampled dependent repositories.
  • github stars and bluesky top: The repository stars cover the CMS, and the sampled social posts offer little package-specific evidence.
Vouched for6.2

Who stands behind it being good?

Claude Opus 5.5: 5.0, likely 4.0 to 6.5

Many projects use it in production, and ApostropheCMS relies on it. Comparison sites name it as the standard server-side choice. But I found no recent independent benchmark or survey praise. Outside researchers' attention showed up as advisories rather than endorsements.

GPT-6.2 Sol: 7.4, likely 6.2 to 8.5

Ghost and NodeBB list sanitize-html as a runtime dependency, and Cronicle describes using it to protect HTML job reports. Independent timing data adds evidence for Node.js performance, though it covers one fixture. Current evidence on developer satisfaction and comparative security across real applications is thinner.

Safe5.6

How safe is it to depend on?

Claude Opus 5.5: 5.0, likely 4.0 to 6.5

Ten advisories in 24 months, including a critical one in the default configuration, show a real and continuing bypass risk for a security tool. Fixes ship quickly, and the project has a security policy. The Scorecard is 6.4, with unpinned dependencies and no fuzzing. It has six dependencies and an MIT licence.

  • advisories: 17 total, 10 in the last 24 months, the latest from October 2026.
  • advisories.gitlab.com/npm/sanitize-html/CVE-2026-44990: Critical (CVSS 9.3) default-config XSS.
  • scorecard: 6.4: Pinned-Dependencies 0, Fuzzing 0, Token-Permissions 0.
  • npm dependencies: 6 dependencies; MIT licence.

GPT-6.2 Sol: 6.2, likely 5.1 to 7.4

The npm package uses the MIT license and has six direct dependencies. The iframe regression was fixed in 2.18.1 before public disclosure, and 2.18.2 fixed several more parser-related issues. The monorepo scored 6.4 on OpenSSF Scorecard, with full marks for code review and zeroes for token permissions, dependency pinning, and fuzzing. The monorepo documents Changesets publishing, but package-specific publisher access and provenance remain unverified.

Good

  • Runs in plain Node with no DOM or jsdom, and returns a cleaned string.
  • Detailed allowlists for tags, attributes, schemes and CSS styles, plus a transformTags hook to rewrite elements.
  • Maintained by a company (ApostropheCMS), with frequent patch releases and fast fixes for reported bypasses.
  • MIT licence and a small package (about 87 kB) with six dependencies.

Bad

  • Ten advisories in 24 months, including a critical XSS (CVE-2026-44990) in the default discard mode.
  • Its string parser can differ from how browsers parse HTML, which opens the door to mutation-XSS bypasses. DOMPurify avoids this by using a real DOM.
  • Ships no TypeScript types, so you need the community @types/sanitize-html package.
  • Recent versions need Node 22.12 or newer, and the move into the Apostrophe monorepo makes its repository signals harder to read.

The numbers

npm downloads, 4 weeks
73M ×4.7 in a year
GitHub stars
4.7k
Commits, 12 months
377
npm version
2.18.2 Nov 2026
Versions, 12 months
10
Advisories, 24 months
10 of 17 ever
OpenSSF Scorecard
6.4 out of 10, Nov 2026
Licence
MIT

sanitize-html moved into the ApostropheCMS repository in 2026, so the repository numbers are of all of ApostropheCMS.

Read on 21 November 2026 from GitHub (apostrophecms/apostrophe), npm (sanitize-html), OSV and the OpenSSF Scorecard.

Web security libraries

  1. 8.7DOMPurify
  2. 8.2Helmet
  3. 7.9express-rate-limit
  4. 7.6cors
  5. 7.4rate-limiter-flexible
  6. 7.0Upstash Ratelimit
  7. 6.8sanitize-html
  8. 6.1csrf-csrf
  9. 5.7Arcjet
  10. 5.0js-xss
Compare all 10 on six scores