# sanitize-html: 6.8 out of 10

Reasonable, with limits. 7th of 10 in [Web security libraries](https://elestia.ai/opensource/web-security/index.md).

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.

## Scores

- **Overall: 6.8** (likely 5.7 to 7.8)
  - Claude Opus 5.5 (6.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.
  - GPT-6.2 Sol (7.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 many: 4.4** (likely 3.4 to 5.4)
  - Claude Opus 5.5 (4.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): 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 lot: 6.9** (likely 5.9 to 7.9)
  - Claude Opus 5.5 (6.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): 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 time: 7.1** (likely 6.0 to 8.2)
  - Claude Opus 5.5 (7.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.
  - GPT-6.2 Sol (7.2): 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 widely: 6.7** (likely 5.7 to 7.7)
  - Claude Opus 5.5 (7.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.
  - GPT-6.2 Sol (6.3): 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.
- **Vouched for: 6.2** (likely 5.1 to 7.5)
  - Claude Opus 5.5 (5.0): 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): 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.
- **Safe: 5.6** (likely 4.6 to 7.0)
  - Claude Opus 5.5 (5.0): 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.
  - GPT-6.2 Sol (6.2): 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

- Downloads, 4 weeks: 73M
- In a year: ×4.7
- GitHub stars: 4.7k
- Commits, 12 months: 377
- Last npm release: Nov 2026
- Advisories, 24 months: 10
- Licence: MIT
- GitHub: https://github.com/apostrophecms/apostrophe
- npm: https://www.npmjs.com/package/sanitize-html

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

Scores run from 0 to 10 and are the mean of the scores of AI reviewers (Claude Opus 5.5, GPT-6.2 Sol), made on 22 November 2026 from GitHub, npm, OSV, OpenSSF Scorecard, ecosyste.ms, Hacker News and Bluesky data and a web search. The ecosyste.ms count of repositories that use a project is far too low for projects that grew in the last few years, and some reviews quote it. Overall is the reviewers' own judgement for a new project today, not an average of the parts. An AI wrote them and can be wrong.
