Agent skill

Xss Prevention

by secondsky in secondsky/claude-skills

XSS attack prevention with input sanitization, output encoding, Content Security Policy.

MITAuto-check passedSecurity

Install Xss Prevention

skills CLI
$ npx skills add secondsky/claude-skills --skill xss-prevention -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install secondsky/claude-skills xss-prevention --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/secondsky/claude-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/xss-prevention/skills/xss-prevention .claude/skills/xss-prevention && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
xss-prevention
GitHub stars
227
Token cost
~1.5k tokens
SKILL.md length
362 words
Files
3 (incl. references)
Skills in repo
169
Repo updated
First seen
Licence
MIT

At a glance

XSS attack prevention with input sanitization, output encoding, Content Security Policy.

  • User-generated content
  • SKILL.md covers Overview, When to Use, XSS Attack Types and Output Encoding (Node.js), plus 9 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md
  • Rich text editors

What it does

Xss Prevention is an agent skill from secondsky/claude-skills. XSS attack prevention with input sanitization, output encoding, Content Security Policy. Use for user-generated content, rich text editors, web application security, or encountering stored XSS, reflected XSS, DOM manipulation, script injection errors.

Its SKILL.md is about 1.5k tokens, which your agent loads only when the skill is triggered. The skill folder holds 3 other files, including reference files (for example `references/nodejs-advanced.md` and `references/python-sanitization.md`).

It sits in Security, covering Web application vulnerabilities and Secure coding. It works with Node.js and Python. The repository describes itself as: Production-ready skills for Claude Code CLI - Cloudflare, React, Tailwind v4, and AI integrations. The licence is MIT.

When your agent uses it

  • User-generated content
  • Rich text editors
  • Web application security
  • Encountering stored XSS

Example prompts

  • “/xss-prevention”

Requirements

  • Python 3
  • Node.js

What it can do on your machine

Read from SKILL.md and the folder at commit 8837836. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are javascript).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • cheatsheetseries.owasp.org
    • github.com
    • content-security-policy.com
    • developer.mozilla.org

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Xss Prevention loads about 1.5k tokens when it runs, and up to ~4.9k if it reads all its reference files. Until then it costs about 67 tokens; SKILL.md has 362 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~67
When it runs · the whole SKILL.md, loaded when a task matches
~1.5k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~4.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from secondsky/claude-skills at commit 8837836, republished under its MIT licence (© secondsky). 362 words, ~1,511 tokens.

Download SKILL.mdSave it as .claude/skills/xss-prevention/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
xss-prevention
description
XSS attack prevention with input sanitization, output encoding, Content Security Policy. Use for user-generated content, rich text editors, web application security, or encountering stored XSS, reflected XSS, DOM manipulation, script injection errors.
metadata.keywords
sanitization, HTML-encoding, DOMPurify, CSP, Content-Security-Policy, rich-text-editor, user-input, escaping, innerHTML, DOM-manipulation, stored-XSS…
license
MIT

XSS Prevention

Overview

Implement comprehensive Cross-Site Scripting attack prevention through input sanitization, output encoding, Content Security Policy headers, and secure coding practices.

When to Use

  • User-generated content display
  • Rich text editors
  • Comment systems
  • Search functionality
  • Dynamic HTML generation
  • Template rendering scenarios

XSS Attack Types

TypeVectorDefense
ReflectedURL parametersOutput encoding
StoredDatabase contentInput sanitization
DOM-basedClient-side JSSafe DOM APIs
MutationHTML parser quirksStrict sanitization

Output Encoding (Node.js)

javascript
function encodeHTML(str) {
  return str
    .replace(/&/g, '&')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#x27;');
}

function encodeForAttribute(str) {
  return str.replace(/[^\w.-]/g, char =>
    `&#x${char.charCodeAt(0).toString(16)};`
  );
}

// Usage in templates
app.get('/profile', (req, res) => {
  const username = encodeHTML(req.query.name);
  res.send(`<h1>Welcome, ${username}</h1>`);
});

DOMPurify Sanitization

javascript
import DOMPurify from 'dompurify';

const config = {
  ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'a', 'p', 'br'],
  ALLOWED_ATTR: ['href', 'title'],
  ALLOW_DATA_ATTR: false
};

function sanitizeHTML(dirty) {
  return DOMPurify.sanitize(dirty, config);
}

// React component
function RichContent({ html }) {
  return (
    <div dangerouslySetInnerHTML={{ __html: sanitizeHTML(html) }} />
  );
}

Content Security Policy

javascript
// Express middleware
app.use((req, res, next) => {
  const nonce = crypto.randomBytes(16).toString('base64');
  res.locals.nonce = nonce;

  res.setHeader('Content-Security-Policy', [
    "default-src 'self'",
    `script-src 'self' 'nonce-${nonce}'`,
    "style-src 'self' 'unsafe-inline'",
    "img-src 'self' data: https:",
    "connect-src 'self' https://api.example.com",
    "frame-ancestors 'none'",
    "base-uri 'self'",
    "form-action 'self'"
  ].join('; '));

  next();
});

Safe DOM APIs

❌ NEVER do any of the following with user-controlled input — these are XSS sinks and there is no safe way to call them with untrusted data:

  • Assign it to element.innerHTML / element.outerHTML
  • Pass it to eval()
  • Pass it to document.write()
  • Pass it to setTimeout / setInterval as a string
  • Insert it into an inline event handler (e.g. onclick="...")
javascript
// SAFE — use these instead
element.textContent = userInput;      // Escaped automatically
element.setAttribute('data-id', id);  // Safe for attributes
document.createTextNode(userInput);   // Creates safe text node

The safe patterns above (textContent, attribute escaping via setAttribute, DOMPurify.sanitize) are the only correct ways to handle user input in the DOM.

URL Validation

javascript
function isSafeURL(url) {
  try {
    const parsed = new URL(url);
    return ['http:', 'https:'].includes(parsed.protocol);
  } catch {
    return false;
  }
}

// Usage
const href = isSafeURL(userURL) ? userURL : '#';

Context-Specific Encoding

Different contexts require different encoding approaches:

  • HTML Entity Encoding: Safest option for text content
  • Attribute Encoding: For HTML attributes
  • JavaScript Escaping: For script contexts
  • URL Encoding: For URL parameters
  • CSS Escaping: For stylesheet contexts

Always encode output by the specific context where data will be rendered.

Show full SKILL.md (155 more words)Show less

Additional Implementations

See references/python-sanitization.md for:

  • Python bleach library usage
  • Flask/Django template escaping
  • Server-side validation patterns

See references/nodejs-advanced.md for:

  • Complete XSSPrevention class with all methods
  • Express middleware (xssProtection)
  • React components (SafeText, SafeHTML, SafeLink, useSanitizedInput)
  • Helmet CSP configuration

Best Practices

✅ DO:

  • Encode output by default
  • Use templating engines with auto-escaping
  • Implement CSP headers
  • Sanitize rich content with allowlists
  • Validate URLs with protocol whitelisting
  • Use HTTPOnly cookies
  • Conduct regular security testing
  • Leverage secure frameworks

❌ DON'T:

  • Trust user input
  • Use unsafe functions (eval, innerHTML)
  • Disable security features for convenience
  • Rely solely on client-side validation
  • Use blocklists instead of allowlists
  • Skip context-specific encoding
  • Allow arbitrary script execution

Security Checklist

  • Encode all output by context (HTML, attribute, JS)
  • Sanitize HTML with allowlist (not blocklist)
  • Implement strict CSP headers
  • Use HTTPOnly cookies for sessions
  • Validate and sanitize URLs
  • Avoid innerHTML with user content
  • Regular security testing

Resources

© secondsky, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files (references) in plugins/xss-prevention/skills/xss-prevention of secondsky/claude-skills.

  • SKILL.md
  • references/nodejs-advanced.md
  • references/python-sanitization.md

Open the folder on GitHubat commit 8837836

Compare with similar skills

Xss Prevention next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Xss Prevention compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Xss Prevention this skillsecondsky/claude-skills227—~1.5kAutomated safety check: PassMIT
Security Verification Gatefengshao1227/ccg-workflow5.9k—~621Automated safety check: NotesMIT
Security Auditjellydn/my-ai-tools123—~2.9kAutomated safety check: NotesMIT
Security Auditoreigent-ai/eigent15k—~1.8kAutomated safety check: NotesApache-2.0
Fix Strix Security Findingsusestrix/strix67k—~1.5kAutomated safety check: PassApache-2.0
CodeQL Security Scantrailofbits/skills7.4k—~4.6kAutomated safety check: NotesCC-BY-SA-4.0

Similar skills

  • Security Verification Gate

    fengshao1227/ccg-workflow

    Scans code with a bundled Node script for injection, secrets, XSS and other risky patterns, ranks findings by severity and checks that security decisions are documented.

    5.9k GitHub stars~621 tokensUpdated 23 days ago
    SecurityAuto-check: notes
  • Security Audit

    jellydn/my-ai-tools

    A skill your agent uses when reviewing code for security vulnerabilities, hardening an application, or deriving security requirements from OWASP/ASVS guidance.

    123 GitHub stars~2.9k tokensUpdated yesterday
    SecurityAuto-check: notes
  • Security Auditor

    eigent-ai/eigent

    Audits source code, dependencies and config files for vulnerabilities and hardcoded secrets, using two bundled Python scanners and an OWASP Top 10 checklist.

    15k GitHub stars~1.8k tokensUpdated yesterday
    SecurityAuto-check: notes
  • Triages findings from a Strix pentest by severity, fixes each root cause with a minimal change, and re-runs Strix to confirm the exploit no longer works.

    67k GitHub stars~1.5k tokensUpdated yesterday
    SecurityAuto-check passed
  • CodeQL Security Scan

    trailofbits/skills

    Official

    Scans a codebase for vulnerabilities with CodeQL's data flow and taint tracking in run-all or important-only modes, including data extensions for project-specific sources and sinks.

    7.4k GitHub stars~4.6k tokensUpdated yesterday
    SecurityAuto-check: notes
  • Runs claude-flow CLI security scans for input validation, path traversal, SQL injection, XSS, hardcoded secrets and known CVEs, and writes an audit report.

    74k GitHub starsUsed in 2 repos~823 tokens
    SecurityAuto-check passed

More from secondsky/claude-skills

All 169 skills in this repo
  • Tanstack AI

    secondsky/claude-skills

    TanStack AI (alpha) provider-agnostic type-safe chat with streaming for OpenAI, Anthropic, Gemini, Ollama.

    227 GitHub starsUsed in 1 repo~3.6k tokens
    Auto-check: notes
  • Auto Animate

    secondsky/claude-skills

    AutoAnimate (@formkit/auto-animate) zero-config animations for React.

    227 GitHub stars~2.9k tokensUpdated 10 days ago
    Auto-check passed
  • Base UI React

    secondsky/claude-skills

    MUI Base UI unstyled React components with Floating UI. An agent skill from secondsky/claude-skills.

    227 GitHub stars~1.9k tokensUpdated 10 days ago
    Auto-check passed
  • Cloudflare Images

    secondsky/claude-skills

    This skill should be used when the user asks to "upload images to Cloudflare", "implement direct creator upload", "configure image transformations", "optimize WebP/AVIF", "create image variants"…

    227 GitHub stars~3.6k tokensUpdated 10 days ago
    Auto-check: notes
  • Cloudflare Nextjs

    secondsky/claude-skills

    Deploy Next.js to Cloudflare Workers via the OpenNext adapter (@opennextjs/cloudflare).

    227 GitHub stars~5.3k tokensUpdated 10 days ago
    Auto-check: notes
  • Cloudflare Sandbox

    secondsky/claude-skills

    Cloudflare Sandboxes SDK for secure code execution in Linux containers at edge.

    227 GitHub stars~4.5k tokensUpdated 10 days ago
    Auto-check passed

Works with

Categories

Questions about Xss Prevention

What does Xss Prevention do?

XSS attack prevention with input sanitization, output encoding, Content Security Policy. Xss Prevention is an agent skill from secondsky/claude-skills. XSS attack prevention with input sanitization, output encoding, Content Security Policy.

When should I use Xss Prevention?

Xss Prevention fits situations like: user-generated content; rich text editors; web application security; encountering stored XSS.

How do I install Xss Prevention in Claude Code?

Run `npx skills add secondsky/claude-skills --skill xss-prevention -a claude-code`. Or copy the skill folder (plugins/xss-prevention/skills/xss-prevention in secondsky/claude-skills) into .claude/skills/xss-prevention in your project. Claude Code loads it when a task matches its description.

How do I install Xss Prevention in Codex?

Run `npx skills add secondsky/claude-skills --skill xss-prevention -a codex`. Or copy the skill folder (plugins/xss-prevention/skills/xss-prevention in secondsky/claude-skills) into .agents/skills/xss-prevention in your project. Codex loads it when a task matches its description.

Can I use Xss Prevention in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add secondsky/claude-skills --skill xss-prevention -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/xss-prevention, .gemini/skills/xss-prevention, .github/skills/xss-prevention and .opencode/skills/xss-prevention in your project.

What does Xss Prevention need to run?

SKILL.md names no scripts, command-line tools or credentials: Xss Prevention is instructions for the agent only. Our summary lists: Python 3; Node.js.

Does Xss Prevention access the network?

SKILL.md names 4 domains. As links in the text: cheatsheetseries.owasp.org, github.com, content-security-policy.com and developer.mozilla.org. This is read from the text; nothing was executed.

Is Xss Prevention safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Xss Prevention use?

Xss Prevention is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Xss Prevention use?

About 1.5k tokens (SKILL.md is roughly 6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 3.4k tokens, read only when the agent opens those files.

What are the alternatives to Xss Prevention?

Skills that share tags, products or a category with Xss Prevention: Security Verification Gate (fengshao1227/ccg-workflow, 5.9k stars), Security Audit (jellydn/my-ai-tools, 123 stars), Security Auditor (eigent-ai/eigent, 15k stars) and Fix Strix Security Findings (usestrix/strix, 67k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Xss Prevention?

secondsky (a GitHub user) maintains it in secondsky/claude-skills, which has 227 GitHub stars. The repository holds 169 skills in this directory. The repository was last updated on September 28, 2026.

Source: secondsky/claude-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.