DOMPurify
A strong pick. 1st of 10 web security libraries.
DOMPurify is the standard HTML, SVG and MathML sanitizer for JavaScript. It comes from the security firm Cure53, is very actively maintained and is safe by default. For cleaning untrusted HTML it is the one to pick today, in the browser and, with jsdom, on the server.
Best for: Any app that has to render HTML from users, markdown or third parties without opening an XSS hole, especially in the browser.
Scores
Overall8.7
How strongly do we recommend it for a new project today?
Claude Opus 5.5: 8.5, likely 8.0 to 9.0
It is the best tool for HTML sanitization: secure defaults, quick security fixes, and Google's backing as the fallback for the native API. It loses points for the clumsy jsdom setup on servers, the constant need to upgrade for advisories, and the long-term threat from native setHTML. Among the HTML sanitizers in the bundle, it ranks clearly above sanitize-html and js-xss.
- peers sanitize-html / js-xss: Fewer downloads and stars; string-based parsing
- github.com/cure53/DOMPurify/releases: Active, non-breaking hardening releases
- developer.chrome.com/docs/modern-web-guidance/guides/security/sanitize-untrusted-html: Recommended fallback
GPT-6.2 Sol: 8.8, likely 7.7 to 9.6
DOMPurify is my first choice among these peers for new browser projects that render untrusted markup. Its tested defaults, flexible output, and active patching support that choice. For HTML-only processing on Node, sanitize-html is simpler to deploy because it supplies its own parser. Dependence on one npm publisher and the cost of a server-side DOM keep the recommendation strongest in browsers.
- cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet: An independent security recommendation for DOMPurify.
- github.com/cure53/DOMPurify/releases/tag/3.4.18: The current stable release continues active security maintenance.
- github.com/apostrophecms/apostrophe/blob/main/packages/sanitize-html/README.md: The Node-oriented peer parses HTML through htmlparser2 without a browser DOM.
- github.com/cure53/DOMPurify/wiki/State-of-the-Project-and-Roadmap: Documents test coverage and dependence on one npm publisher.
Needed by many4.9
How many developers need a tool for this job?
Claude Opus 5.5: 5.0, likely 4.0 to 6.0
Only apps that render untrusted or user-written HTML, such as markdown, rich text, emails or embeds, need an HTML sanitizer. That is a sizable group, but well below all web apps. It covers only the HTML-cleaning part of the category, not headers or rate limits.
- category job: HTML cleaning is one of three jobs in the category
- dependents.repos: 56,633 repos, well below cors and Helmet
GPT-6.2 Sol: 4.8, likely 3.5 to 6.1
HTML sanitization is a recurring need for editors, previews, and apps that render user-supplied markup. DOMPurify works across browser frameworks, and server use requires a DOM implementation. The share of JavaScript projects that render untrusted rich markup is hard to measure.
- cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet: Explains when applications need HTML sanitization.
- raw.githubusercontent.com/cure53/DOMPurify/3.4.18/README.md: Documents browser coverage and the server-side DOM requirement.
- github.com/cloudflare/workerd/issues/5752: A user reports trouble running the jsdom-based wrapper on Cloudflare Workers.
Helps a lot9.0
How well does it do the job for those who need it?
Claude Opus 5.5: 9.0, likely 8.0 to 9.5
It is secure by default, covers HTML, SVG and MathML, and has hooks and Trusted Types support. It ships its own types and is well documented. Using the native DOM parser avoids the parser-mismatch problems of string-based sanitizers like sanitize-html and js-xss. The main limit is the server side, where it needs jsdom, which is heavy and sometimes fragile.
- npm-compare.com/dompurify,sanitize-html,xss: Secure by default and fast; sanitize-html is opt-in and string-based
- npmjs.com/package/isomorphic-dompurify: jsdom memory growth and ESM issues on Node
- npm hasTypes: Ships its own types
- developer.chrome.com/docs/modern-web-guidance/guides/security/sanitize-untrusted-html: Chrome recommends DOMPurify as the fallback sanitizer
GPT-6.2 Sol: 8.9, likely 7.7 to 9.7
Version 3.4.18 combines strong browser defaults with SVG and MathML support, configurable hooks, and Trusted Types output. Bundled types and short examples make routine integrations easy for developers and coding agents to check. An independent Node benchmark found sanitize-html and js-xss faster in its test setup. Current cross-runtime performance and the reliability of agent-written custom policies remain uncertain.
- raw.githubusercontent.com/cure53/DOMPurify/3.4.18/README.md: Documents output types, configuration, and tests across three browser engines.
- raw.githubusercontent.com/cure53/DOMPurify/3.4.18/package.json: Ships declarations for both module formats.
- csecurity.kubg.edu.ua/index.php/journal/article/download/1076/911/3547: A 2025 Node benchmark found higher time and memory use than both JavaScript peers.
- ias.cs.tu-bs.de/publications/parsing_differentials.pdf: Independent testing of older versions found strong browser defaults and weaker results with jsdom 19.
Holds up over time8.3
Will it still be a good choice in two years?
Claude Opus 5.5: 8.5, likely 7.5 to 9.0
The last year shows 353 commits, 23 releases, zero open issues or PRs, and steady patch releases without breaking changes. A security consultancy backs it, but releases depend on a small core around one lead maintainer. The native Sanitizer API is a long-term substitute in the browser, but Safari lacks it and Chrome itself points to DOMPurify as the fallback.
- github commitsLastYear / releasesLastYear: 353 commits, 23 releases
- github openIssues / openPullRequests: 0 open of each
- github.com/cure53/DOMPurify/releases: Frequent hardening releases; nearly all published by the cure53 account
- hacks.mozilla.org/2026/02/goodbye-innerhtml-hello-sethtml-stronger-xss-protection-in-firefox-148: Native setHTML is shipping in Firefox
- web.dev/articles/sanitizer: Safari does not support the Sanitizer API
GPT-6.2 Sol: 8.1, likely 6.9 to 9.1
The project shipped 23 releases on 353 commits in the past year, and a recent release PR was reviewed and merged the same day. Updates mostly stayed in the 3.x line, with a CommonJS declaration fix in 3.4.16. npm publishing depends on one maintainer, and the level of sponsorship is unclear. Growing support for the native browser sanitizer could reduce demand for basic browser use.
- github.commitsLastYear, github.releasesLastYear, github.contributors: 353 commits, 23 releases, and 138 contributors over the life of the repository.
- github.com/cure53/DOMPurify/pull/1671: The 3.4.17 release PR received same-day review and merge.
- github.com/cure53/DOMPurify/releases: Recent 3.x releases include security fixes and a CommonJS declaration correction.
- github.com/cure53/DOMPurify/wiki/State-of-the-Project-and-Roadmap: Describes single-maintainer publishing, sponsorship, and plans for continuity.
- developer.mozilla.org/en-US/docs/Web/API/Element/setHTML: Native sanitization is available in some browsers and still has limited coverage.
Used widely7.1
How many use it, and is that growing?
Claude Opus 5.5: 8.0, likely 7.0 to 9.0
It has about 400M downloads in 4 weeks, up 6.9x on a year ago, above the 4.1x median. Many of these are transitive installs through tools like Mermaid, Monaco and PDF libraries. It has 56.6k dependent repos, fewer than sanitize-html or js-xss, but much use comes from CDNs and bundled copies. It is still the leading HTML sanitizer, with 17.5k stars, the most in the category.
- npm downloadsLast4Weeks: 401.8M vs 58.3M a year ago (6.9x)
- dependents: 56,633 repos, 1,705 packages
- github stars: 17,540, the highest among peers
GPT-6.2 Sol: 6.2, likely 5.0 to 7.4
Four-week downloads rose 6.9× year over year, ahead of the 4.1× catalog median and both sanitizer peers. Ecosyste.ms found 56,633 dependent repositories and 1,705 packages, with more tracked repositories for both sanitize-html and js-xss. DOMPurify drew the most Bluesky links among peers, though the leading posts came from its maintainers. CI and transitive installs inflate download totals, and vendored copies make some use invisible to npm.
- npm.downloadsLast4Weeks, npm.downloadsSame4WeeksYearAgo, medianDownloadsRatio: 401.8 million versus 58.3 million, or 6.9× growth against a 4.1× median.
- dependents, peers: sanitize-html has 89,985 tracked dependent repos and js-xss has 111,112.
- github.stars, bluesky, peers: 17,540 stars and 20 Bluesky links lead the peer group.
- raw.githubusercontent.com/kkomelin/isomorphic-dompurify/master/package.json: The isomorphic wrapper installs DOMPurify as a dependency.
- raw.githubusercontent.com/microsoft/vscode/main/src/vs/base/browser/domSanitize.ts: VS Code uses a vendored copy for browser sanitization.
Vouched for8.6
Who stands behind it being good?
Claude Opus 5.5: 8.5, likely 7.5 to 9.0
Chrome's own security guidance names it as the fallback sanitizer, and major projects such as Monaco and Mermaid build on it. Independent researchers fuzz and audit it all the time. New rivals measure themselves against it. Surveys say little about this niche, so the range stays at one point either way.
- developer.chrome.com/docs/modern-web-guidance/guides/security/sanitize-untrusted-html: Google recommends DOMPurify where the native API is missing
- hackerNews top: Competitors benchmark against DOMPurify
- advisories.gitlab.com/npm/dompurify/CVE-2026-41238: External fuzzing research targets it
- Monaco, Mermaid: Widely used tools bundle DOMPurify
GPT-6.2 Sol: 8.7, likely 7.6 to 9.6
OWASP recommends DOMPurify, and Grafana, VS Code, and Mermaid use it in rendering code. Independent comparisons give useful evidence about its browser defaults and server-side tradeoffs. The comparisons cover older versions, and State of JavaScript provides no DOMPurify satisfaction rating.
- cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet: OWASP recommends DOMPurify for HTML sanitization.
- raw.githubusercontent.com/grafana/grafana/main/packages/grafana-data/src/text/sanitize.ts: Grafana uses it for HTML, SVG, and Trusted Types output.
- raw.githubusercontent.com/microsoft/vscode/main/src/vs/base/browser/domSanitize.ts: VS Code uses it in its browser HTML sanitizer.
- raw.githubusercontent.com/mermaid-js/mermaid/develop/packages/mermaid/src/diagrams/common/common.ts: Mermaid uses it to sanitize diagram labels.
- ias.cs.tu-bs.de/publications/parsing_differentials.pdf: Independent research tested default and relaxed configurations across sanitizers.
- 2025.stateofjs.com/en-US/other-tools: The survey does not report DOMPurify satisfaction.
Safe8.1
How safe is it to depend on?
Claude Opus 5.5: 8.0, likely 7.0 to 9.0
The OpenSSF Scorecard is 9.8, with signed releases, fuzzing and pinned dependencies, and the package has one dependency. The licence is permissive (MPL-2.0 or Apache-2.0). The bundle shows 26 advisories in 24 months. The recent ones are low severity, in niche modes, and fixed quickly, but the steady flow means users must upgrade often.
- scorecard score: 9.8 overall
- advisories: 33 total, 26 in 24 months, recent ones LOW
- npm dependencies: 1 dependency
- advisories.gitlab.io/pkg/npm/dompurify: Bypass advisories with fixed versions
GPT-6.2 Sol: 8.2, likely 7.1 to 9.2
Recent upstream disclosures had patches available at publication, including the November fix in 3.4.18 and an October follow-up to an incomplete fix. The browser package has one optional type dependency and offers a choice of Apache-2.0 or MPL-2.0. The 9.8 OpenSSF Scorecard reflects strong review, fuzzing, and signed releases, with branch protection at 8 and packaging unscored. Recurring bypasses, manual publishing by one maintainer, and reliance on an up-to-date DOM on the server widen the range.
- advisories, scorecard: 26 advisories in 24 months, with a 9.8 Scorecard and full marks for signed releases and fuzzing.
- github.com/cure53/DOMPurify/security/advisories: Upstream disclosures document fixes and an October follow-up.
- github.com/cure53/DOMPurify/releases/tag/3.4.18: The signed November release includes security fixes.
- github.com/cure53/DOMPurify/security/policy: GitHub artifacts carry signatures and build provenance. npm publication is manual.
- raw.githubusercontent.com/cure53/DOMPurify/3.4.18/package.json: The only optional dependency is Trusted Types declarations. The package is dual-licensed.
- raw.githubusercontent.com/cure53/DOMPurify/3.4.18/README.md: Server-side security depends on the DOM implementation and its patch level.
Good
- Safe defaults with no setup: DOMPurify.sanitize(dirty) is enough for most uses.
- A security firm maintains it, with constant fuzzing and hardening, and bypasses get fixed within days.
- It uses the browser's own parser, which avoids parser mismatches and makes it fast and small client-side.
- It has hooks, Trusted Types support and fine-grained configuration for advanced cases.
Bad
- On Node it needs jsdom, which is heavy, can leak memory in long-running processes and has had ESM/CJS breakage.
- It gets a steady stream of bypass advisories (26 in two years), so you must keep upgrading. Most are low severity and in niche modes such as IN_PLACE or RETURN_DOM.
- The native Sanitizer API (setHTML) may cut the need for it in the browser over time.
- It covers only HTML cleaning, not headers, CORS or rate limits.
The numbers
- npm downloads, 4 weeks
- 402M ×6.9 in a year
- GitHub stars
- 18k
- Commits, 12 months
- 353
- npm version
- 3.4.18 Nov 2026
- Versions, 12 months
- 23
- Advisories, 24 months
- 26 of 33 ever
- OpenSSF Scorecard
- 9.8 out of 10, Nov 2026
- Licence
- Apache-2.0
Read on 21 November 2026 from GitHub (cure53/DOMPurify), npm (dompurify), OSV and the OpenSSF Scorecard.
Web security libraries
- 8.7DOMPurify
- 8.2Helmet
- 7.9express-rate-limit
- 7.6cors
- 7.4rate-limiter-flexible
- 7.0Upstash Ratelimit
- 6.8sanitize-html
- 6.1csrf-csrf
- 5.7Arcjet
- 5.0js-xss