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.
npx skills add guyulong/cn-agent-skills --skill xss-preventgit clone --depth 1 https://github.com/guyulong/cn-agent-skillsWrote 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.
[](https://agentmods.dev/skills/guyulong/cn-agent-skills/xss-prevent)<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.
<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>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.
| Model | Per session | Once 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 |
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.
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 = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
};
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
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.
- 10d ago First seen · 123 lines · 13 tokens per session scan A 1e96148fd129
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.
Other skills, from other repositories
data-report
Turns CSV, Excel, or JSON data into a polished visual report page.
article-magazine
Huashu / huashu-md-html-inspired magazine article layout for turning Markdown or notes into a polished long-form HTML essay.
card-xiaohongshu
Xiaohongshu-style knowledge cards, arranged as a swipeable multi-card carousel.
poster-hero
Vertical poster or Moments-style share image with strong visual impact.
card-twitter
Twitter quote or data card designed to pair with a post.
deck-ljg-present
A presentation template that converts an outline or Markdown document into large, poster-like slides while keeping the original wording, order, and content. It uses black, red, or yellow colour themes and assigns document elements to slide layouts.