---
name: "xss-defense-dompurify-sanitizer"
description: "Sanitize untrusted HTML and prevent Cross-Site Scripting with DOMPurify."
metadata:
  author: "Cure53"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "sanitize html with dompurify"
  - "prevent xss in react"
  - "safe dangerouslysetinnerhtml"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Cross-Site Scripting (XSS) Defense & DOMPurify

Eliminates Stored, Reflected, and DOM-based XSS: HTML entity encoding, sanitizing rich-text with DOMPurify in Node and browser, and configuring safe React dangerouslySetInnerHTML patterns.

## When to Invoke
Invoke this skill whenever you need to:
- sanitize html with dompurify
- prevent xss in react
- safe dangerouslysetinnerhtml

## Execution SOP & Rules
1. Run DOMPurify.sanitize(dirtyHtml, { USE_PROFILES: { html: true } }) on all untrusted HTML.
2. Specify ALLOWED_TAGS and ALLOWED_ATTR explicitly when rendering rich formatting.
3. Ensure links generated from user input enforce target='_blank' and rel='noopener noreferrer'.
4. Never construct HTML strings using unescaped user inputs in client JavaScript.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
