xss-prevention

xss-prevention is a skill for Claude Code from latestaiagents/agent-skills. It costs 75 tokens per session (2,350 once invoked), scanned A, original, MIT.

A security review guide for preventing cross-site scripting, where attacker-controlled text is treated as webpage code in a browser.

In plain words
What is it for?
Use it when reviewing HTML rendering, DOM updates, templates, search results, markdown, and frontend components.
Why use it?
It helps stop malicious scripts from running when applications display user input, URLs, HTML, or rich text.

Skill for Claude Code

Written for Claude Code: shipped in a Claude Code plugin.

Part of the security-guardian plugin — 10 skills, 2 commands shipped together

Good fit Use it when reviewing HTML rendering, DOM updates, templates, search results, markdown, and frontend components.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/latestaiagents/agent-skills/xss-prevention
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add latestaiagents/agent-skills --skill xss-prevention
Clone the repo
git clone --depth 1 https://github.com/latestaiagents/agent-skills

Made for: Claude Code.

Or install security-guardian, the plugin that ships this one along with the rest of its 10 skills, 2 commands.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for xss-prevention

README.md
[![agentmods](https://agentmods.dev/badge/skills/latestaiagents/agent-skills/xss-prevention/github.svg)](https://agentmods.dev/skills/latestaiagents/agent-skills/xss-prevention)
Your own site
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/xss-prevention"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/xss-prevention/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for xss-prevention

Your own site · 80×15
<a href="https://agentmods.dev/skills/latestaiagents/agent-skills/xss-prevention"><img src="https://agentmods.dev/badge/skills/latestaiagents/agent-skills/xss-prevention.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 75 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,350 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00075 $0.02350
Opus 5 $0.00037 $0.01175
Sonnet 5 $0.00015 $0.00470
Haiku 4.5 $0.00007 $0.00235

Measured 7d ago against content hash 5dfc5159b606, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-11, from the pricing page.

Security

Grade A, and why

xss-prevention scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/security-guardian/skills/owasp/xss-prevention/SKILL.md · 346 lines

How it starts

The opening of the file, as written. The whole thing — 346 lines — stays where its author put it; the contents beside it link to each section on GitHub.

XSS Prevention (OWASP A07)

Prevent Cross-Site Scripting attacks by properly encoding output and sanitizing user input.

When to Use

  • Displaying user-generated content
  • Building dynamic HTML
  • Implementing rich text editors
  • Rendering markdown or HTML
  • Working with URL parameters in pages
  • Building search results pages

XSS Types

Type Vector Example
Reflected URL parameters ?search=<script>alert(1)</script>
Stored Database content Comment with malicious script
DOM-based Client-side JS document.write(location.hash)

Vulnerable Patterns

Server-Side

// VULNERABLE - Direct interpolation
app.get('/search', (req, res) => {
  res.send(`<h1>Results for: ${req.query.q}</h1>`);
});

// VULNERABLE - Template without escaping
res.render('profile', { bio: user.bio }); // If template doesn't auto-escape

Client-Side

// VULNERABLE - innerHTML with user data
element.innerHTML = userInput;
document.getElementById('output').innerHTML = data;

// VULNERABLE - document.write
document.write(location.search);

// VULNERABLE - eval with user data
eval(userCode);

// VULNERABLE - jQuery html()
$('#output').html(userData);

// VULNERABLE - React dangerouslySetInnerHTML
<div dangerouslySetInnerHTML={{__html: userContent}} />

Secure Implementation

1. Output Encoding

// HTML entity encoding
function escapeHtml(text) {
  const map = {
    '&': '&amp;',
    '<': '&lt;',
    '>': '&gt;',
    '"': '&quot;',
    "'": '&#x27;',
    '/': '&#x2F;'
  };
  return text.replace(/[&<>"'/]/g, char => map[char]);
}

// Usage
app.get('/search', (req, res) => {
  const safeQuery = escapeHtml(req.query.q);
  res.send(`<h1>Results for: ${safeQuery}</h1>`);
});

2. Context-Aware Encoding

// Different contexts need different encoding
const encoders = {
  // HTML body context
  html: (str) => str
    .replace(/&/g, '&amp;')
    .replace(/</g, '&lt;')
    .replace(/>/g, '&gt;'),

  // HTML attribute context
  attr: (str) => str
    .replace(/&/g, '&amp;')
    .replace(/"/g, '&quot;')
    .replace(/'/g, '&#x27;'),

  // JavaScript string context
  js: (str) => str
    .replace(/\\/g, '\\\\')
    .replace(/'/g, "\\'")
    .replace(/"/g, '\\"')
    .replace(/\n/g, '\\n'),

  // URL parameter context
  url: (str) => encodeURIComponent(str),

  // CSS context
  css: (str) => str.replace(/[^a-zA-Z0-9]/g, char =>
    '\\' + char.charCodeAt(0).toString(16) + ' '
  )
};

// Usage based on context
`<div>${encoders.html(userInput)}</div>`
`<input value="${encoders.attr(userInput)}">`
`<script>var x = '${encoders.js(userInput)}';</script>`
`<a href="/search?q=${encoders.url(userInput)}">`

Read the full file on GitHub · 346 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 346 lines · 75 tokens per session scan A 5dfc5159b606

Subscribe to this mod's changes

xss-prevention is a skill published in the GitHub repository latestaiagents/agent-skills (5 stars, last pushed 4mo ago), licensed MIT. It adds 75 tokens to every session and 2,350 once invoked, about $0.0004 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.