rehype-sanitize

A unified rehype plugin that sanitizes HTML to prevent XSS by dropping anything a schema does not explicitly allow.

Library
npm
v6.0.0
224 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
37 /100 Needs Attention
Development Activity 0
Maintenance 20
Community 48
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 88
Code Quality 95
Innovation 85
Learning Curve 70

rehype-sanitize is a rehype (unified) plugin that makes HTML safe by cleaning a hast syntax tree against a configurable schema, dropping any element or attribute that is not explicitly allowed. It defaults to GitHub’s sanitation rules, so untrusted markup, inline event handlers, dangerous URLs, and injected scripts are stripped out before rendering.

Built on hast-util-sanitize, it slots into any unified/rehype pipeline between parsing and stringifying. It is the standard way to defend against cross-site scripting when rendering user-authored or plugin-generated HTML, and its schema can be extended to safely permit math, syntax highlighting, or other trusted markup.

What You Get

  • A drop-in rehype plugin that sanitizes a hast tree against a configurable allowlist schema.
  • A secure default schema (defaultSchema) modeled on GitHub’s sanitation rules, requiring no configuration to be safe.
  • Protection against XSS, DOM clobbering (via user-content- id/name prefixing), dangerous URLs, and inline event handlers.
  • Full TypeScript types (via JSDoc) and ESM-only distribution with 100% type and test coverage.
  • Extensible schemas so you can safely opt in to math, syntax highlighting, or other trusted markup.

Common Use Cases

  • Sanitizing user-authored HTML or Markdown-derived HTML before rendering it on a page.
  • Hardening a rehype/remark content pipeline against XSS from untrusted authors or third-party plugins.
  • Allowing specific trusted classes so plugins like rehype-katex or rehype-highlight can run safely.
  • Preventing DOM clobbering when generating heading IDs from user content.

Under The Hood

Architecture

The package is intentionally tiny. index.js re-exports defaultSchema from hast-util-sanitize and the default plugin from lib/index.js. lib/index.js defines rehypeSanitize(options), which returns a unified transformer that calls sanitize(tree, options) on the incoming hast Root and returns the cleaned tree. All actual sanitation logic lives in the underlying hast-util-sanitize utility; this plugin is the thin unified-integration layer that lets you drop sanitation into a .use() chain between parse and stringify.

Tech Stack

Written in modern ESM JavaScript (Node 16+), typed entirely through JSDoc with TypeScript checking (tsconfig.json, type-coverage at 100%). Runtime dependencies are just hast-util-sanitize (the sanitizer) and @types/hast (types). Tooling includes xo and prettier for linting/formatting, c8 for coverage, and the built-in node:test runner. The build compiles type declarations with tsc.

Code Quality

Quality is high and rigorously enforced: test.js uses node:test to verify the public API surface, default sanitation of an onmouseover attribute, and schema-merged options, with c8 enforcing 100% line coverage and type-coverage enforcing 100% typed coverage in strict mode. The code is small, documented with JSDoc, and follows consistent unified-ecosystem conventions.

API Design

The public API is minimal and ergonomic: a default export used as .use(rehypeSanitize[, schema]) plus a named defaultSchema export for extension. Being safe by default with zero configuration is the key DX win, and the extensive README documents real-world schema-extension recipes (math, highlighting, DOM-clobbering mitigation). Familiarity with hast/unified is needed only for advanced schema customization.

Used by 33 apps in this directory

Python
64%
Other

Onyx

AI Agents · AI Assistants · Knowledge Management

32,935

Self-hostable AI platform with agentic RAG, 50+ connectors, deep research, code execution, and support for every major LLM provider.

View details
92
Repo Health
83
Technical
68
Dependency
Built with
Python 64%
TypeScript 26%
Updated 5 days ago
TypeScript
56%
MIT

open-notebook

AI Assistants · Note Taking

40,513

A privacy-first, self-hosted AI research notebook with 18+ model providers, multi-speaker podcast generation, and full REST API—your open-source alternative to Google Notebook LM.

View details
89
Repo Health
84
Technical
71
Dependency
Built with
TypeScript 56%
Python 42%
Updated 1 weeks ago
TypeScript
96%
MIT

Orca

AI Agents · AI Code Assistants

104,104

An open-source Agent Development Environment that orchestrates fleets of parallel AI coding agents — Claude Code, Codex, Gemini and more — each running in its own isolated git worktree.

View details
84
Repo Health
85
Technical
74
Dependency
Built with
TypeScript 96%
Updated 5 days ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,266

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
84
Repo Health
80
Technical
59
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 1 months ago
TypeScript
95%
AGPL 3.0

Rallly

Scheduling

5,318

Self-hostable group scheduling polls that eliminate back-and-forth emails and find the best meeting time for everyone.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
TypeScript 95%
Updated 6 days ago
TypeScript
67%
MIT

Scalar

Developer Tools

16,313

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 67%
Vue 29%
Updated 5 days ago
Python
100%
Other

Sourcebot

AI Code Assistants · Developer Tools · Search

4,005

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
86
Repo Health
83
Technical
61
Dependency
Built with
Python 100%
Updated 1 weeks ago
TypeScript
92%
Other

Suna

AI Agents

20,306

Turn your company into a git repo — one config, one command center, a workforce of AI agents that runs the real work around the clock.

View details
90
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 92%
Updated 5 days ago
TypeScript
85%
Apache 2.0

superset

AI Code Assistants · AI Development

15,503

Orchestrate an army of AI coding agents—Claude Code, Codex, Gemini CLI, and more—running simultaneously in isolated git worktrees from a single Electron desktop app.

View details
86
Repo Health
80
Technical
64
Dependency
Built with
TypeScript 85%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers