xss-prevent

xss-prevent is a skill for Claude Code, Codex from guyulong/cn-agent-skills. It costs 13 tokens per session (922 once invoked), scanned A, original, MIT.

A security guide for finding and fixing cross-site scripting (XSS) vulnerabilities. XSS is an attack where untrusted input causes a website to run an attacker's script in a visitor's browser.

In plain words
What is it for?
Use it to review web code for XSS risks and plan fixes for unsafe HTML output, user comments, URL parameters, or direct DOM updates.
Why use it?
It explains reflected, stored, and DOM-based XSS and gives defensive approaches such as browser security rules, output escaping, and safer DOM APIs.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to review web code for XSS risks and plan fixes for unsafe HTML output, user comments, URL parameters, or direct DOM updates.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/guyulong/cn-agent-skills/xss-prevent
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 guyulong/cn-agent-skills --skill xss-prevent
Clone the repo
git clone --depth 1 https://github.com/guyulong/cn-agent-skills

Made for: Claude Code, Codex.

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-prevent

README.md
[![agentmods](https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/xss-prevent/github.svg)](https://agentmods.dev/skills/guyulong/cn-agent-skills/xss-prevent)
Your own site
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/xss-prevent"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/xss-prevent/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-prevent

Your own site · 80×15
<a href="https://agentmods.dev/skills/guyulong/cn-agent-skills/xss-prevent"><img src="https://agentmods.dev/badge/skills/guyulong/cn-agent-skills/xss-prevent.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 13 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 922 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.00013 $0.00922
Opus 5 $0.00006 $0.00461
Sonnet 5 $0.00003 $0.00184
Haiku 4.5 $0.00001 $0.00092

Measured 10d ago against content hash 1e96148fd129, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

xss-prevent 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 10d 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.

skills/xss-prevent/SKILL.md · 123 lines

How it starts

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

XSS 攻击防护

使用场景

检查代码中的 XSS 漏洞并提供修复方案。

XSS 类型

1. 反射型 XSS

URL: https://example.com/search?q=<script>alert(1)</script>
页面直接输出 q 参数,导致脚本执行

2. 存储型 XSS

用户提交的评论包含恶意脚本
其他用户查看评论时脚本执行

3. DOM 型 XSS

// 危险:直接操作 DOM
document.getElementById('output').innerHTML = location.hash.slice(1);

防护方法(按优先级)

1. Content-Security-Policy(CSP)— 最重要

# 严格 CSP — 阻止内联脚本执行
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'

# 允许特定 CDN
Content-Security-Policy: script-src 'self' https://cdn.example.com

CSP 是浏览器级别的防护,即使存在 XSS 漏洞也能阻止脚本执行。优先配置。

2. 输出编码 / 转义

// 前端:HTML 转义
function escapeHtml(text) {
    const map = {
        '&': '&amp;',
        '<': '&lt;',
        '>': '&gt;',
        '"': '&quot;',
        "'": '&#039;'
    };
    return text.replace(/[&<>"']/g, m => map[m]);
}

// 安全做法:使用 textContent 而非 innerHTML
element.textContent = userInput;  // 安全
element.innerHTML = userInput;    // 危险 — 除非已经过 sanitize
# 后端:使用模板引擎自动转义
# Jinja2 默认开启自动转义;确保未被标记为 safe
from markupsafe import escape
safe_content = escape(user_input)

3. Trusted Types(现代浏览器)

// 配合 CSP: require-trusted-types-for 'script'
// 强制所有 DOM XSS sink 使用 Trusted Types API
const policy = trustedTypes.createPolicy('default', {
    createHTML: (str) => DOMPurify.sanitize(str)
});
element.innerHTML = policy.createHTML(userInput);

4. DOMPurify(需要 innerHTML 时)

import DOMPurify from 'dompurify';
element.innerHTML = DOMPurify.sanitize(userInput);

5. Cookie 安全属性

Set-Cookie: session=abc; HttpOnly; Secure; SameSite=Strict
  • HttpOnly:JS 无法读取 cookie(防止 cookie 窃取)
  • Secure:仅通过 HTTPS 发送
  • SameSite=Strict:阻止跨站请求携带 cookie

6. 安全响应头

Content-Security-Policy: ...
X-Content-Type-Options: nosniff

关于 X-XSS-Protection 该响应头已被废弃。现代浏览器已移除其内建的 XSS auditor,设为 1; mode=block 反而在某些旧浏览器中可能引入新的攻击向量。不要使用它,改用 CSP。

检查清单

  • 配置了 Content-Security-Policy
  • 所有用户输入在输出时做了转义
  • 不使用 innerHTML 插入未消毒的用户内容
  • Cookie 设置了 HttpOnly + Secure + SameSite
  • API 响应设置了正确的 Content-Type
  • 第三方内容使用 sandbox iframe
  • 考虑启用 Trusted Types(如果目标浏览器支持)
  • 未使用 X-XSS-Protection

Read the full file on GitHub · 123 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. 10d ago First seen · 123 lines · 13 tokens per session scan A 1e96148fd129

Subscribe to this mod's changes

xss-prevent is a skill published in the GitHub repository guyulong/cn-agent-skills (3 stars, last pushed 3mo ago), licensed MIT. It adds 13 tokens to every session and 922 once invoked, about $0.0001 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-08-31.