sanitize-html-cleanup
暂无简介
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-11
- Stars
- ★ 13
- Forks
- 1
03 SKILL.md 正文
/sanitize-html-cleanup
When to Use
- Fix malformed HTML (unclosed tags, broken nesting) from LLM output
- Sanitize HTML from web scraping before storing in agent knowledge base
- Configure per-tag attribute rules more granularly than DOMPurify
- Server-side Node.js HTML sanitization without JSDOM overhead
Do NOT use for
- Pure XSS prevention in high-security contexts (use [[dompurify-xss-prevention]])
- Plain text extraction (empty allowedTags list works but use regex instead)
Strict config
import sanitizeHtml from 'sanitize-html'
const STRICT_OPTIONS: sanitizeHtml.IOptions = {
allowedTags: ['p', 'br', 'b', 'i', 'em', 'strong', 'ul', 'ol', 'li', 'code', 'pre',
'h1', 'h2', 'h3', 'blockquote', 'table', 'thead', 'tbody', 'tr', 'th', 'td'],
allowedAttributes: {
'*': ['class'],
'a': ['href', 'title'],
'code': ['class'], // for syntax highlighting classes
'pre': ['class'],
},
allowedSchemes: ['https', 'mailto'],
allowedSchemesByTag: { 'a': ['https', 'mailto'] },
// Auto-repair unclosed tags
selfClosing: ['br', 'hr', 'img', 'input'],
// Transform: strip onclick but keep the element
transformTags: {
'a': sanitizeHtml.simpleTransform('a', { rel: 'noopener noreferrer' }),
},
disallowedTagsMode: 'discard', // 'discard' | 'escape' | 'recursiveEscape'
}
const clean = sanitizeHtml(dirtyHtml, STRICT_OPTIONS)
Text-only extraction
const text = sanitizeHtml(html, {
allowedTags: [],
allowedAttributes: {},
})
// Preserves text content, strips all markup
LLM output pipeline
function cleanLLMHtml(raw: string): string {
// 1. sanitize-html fixes malformed structure + strips dangerous content
const sanitized = sanitizeHtml(raw, STRICT_OPTIONS)
// 2. Strip empty paragraphs
return sanitized.replace(/<p>\s*<\/p>/g, '')
}
Allow CSS with constraints
{
allowedAttributes: { '*': ['style'] },
allowedStyles: {
'*': {
color: [/^#[0-9a-f]{3,6}$/i, /^rgb\(\d{1,3},\s*\d{1,3},\s*\d{1,3}\)$/],
'font-size': [/^\d+(px|em|rem|%)$/],
// Block: expression(), url(), behavior: — these are not in the allowlist
},
},
}
Anti-Fake-Pass Checklist
❌ allowedTags not set → sanitize-html uses its default list (may include script)
❌ href allowed without allowedSchemes → javascript: and data: URIs pass through
❌ disallowedTagsMode:'escape' → script tags rendered as visible text but NOT removed
❌ Nested allowedAttributes { 'a': ['onclick'] } → XSS via event handler
❌ CSS url() in style attribute not blocked by allowedStyles → SSRF via CSS
❌ transformTags not a function but array → TypeError at runtime
04 同仓库更多 Skills
openai--sentry--sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
ito-basket-compare
Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.
implementing-network-traffic-baselining
Build network traffic baselines from NetFlow/IPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly/daily traffic pattern profiling
detecting-evasion-techniques-in-endpoint-logs
Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.
implementing-microsegmentation-with-guardicore
Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.
ramdisk-tmpfs-patterns
暂无简介