Sanitize untrusted/user-supplied HTML to be XSS-safe using an allowlist library, never hand-rolled regex.
Scanned 9/3/2026
Install to Claude Code
npx -y skills add black141312/ada --skill html-sanitize --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Html Sanitize?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/black141312-html-sanitize)More formats (shields.io, HTML) on the badges page.
---
name: html-sanitize
description: Sanitize untrusted/user-supplied HTML to be XSS-safe using an allowlist library, never hand-rolled regex.
category: html
---
# HTML Sanitize
Use whenever you render HTML you didn't author — comments, rich-text input, CMS content, AI output — into a page. Naive insertion is a stored-XSS hole.
1. Pick a battle-tested allowlist sanitizer: DOMPurify (browser/Node), sanitize-html (Node), Bleach (Python), or the language's equivalent; never write your own escaper.
2. Configure a strict allowlist of tags and attributes (e.g., `p, a, strong, em, ul, li, code` + `href`, `title`); deny everything else by default.
3. Strip dangerous vectors: `<script>`, `<style>`, `<iframe>`, event handlers (`on*`), and `javascript:`/`data:` URLs in `href`/`src`.
4. Force-harden links: set `rel="noopener noreferrer"` and validate the URL scheme against an allowlist (`https`, `mailto`).
5. Sanitize server-side as the source of truth (don't trust client-side sanitization alone) and re-sanitize on render, not just on input.
6. Add a Content-Security-Policy header as defense-in-depth, and test with known XSS payloads (`<img src=x onerror=alert(1)>`, SVG/MathML vectors, mutation-XSS cases).
## Rules
- Never sanitize HTML with regex or string replacement — parsers and mXSS will defeat it.
- Allowlist what's permitted; never blocklist "bad" tags (the bad list is infinite).
- Keep the sanitizer library updated; bypasses are found and patched regularly.
- For plain text, escape (`< > &`) instead of sanitizing — don't allow any HTML at all.
- CSP is a backstop, not a substitute for sanitizing the input.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!