AGENT SKILL

review-xss-output-encoding

Use when user-controlled data may land in HTML, attributes, or the DOM. Traces sinks and contexts, applies context-aware encoding or a sanitiser for rich text, and verifies with a payload.

License 许可
MIT
最近更新
2026-11-15
Stars
★ 81
Forks
17

01 前言 Front Matter

name
review-xss-output-encoding
description
Use when user-controlled data may land in HTML, attributes, or the DOM. Traces sinks and contexts, applies context-aware encoding or a sanitiser for rich text, and verifies with a payload.

02 资源文件 3

03 SKILL.md 正文

Review XSS output encoding

Cross-site scripting is a context bug: the same string is safe in a JS string literal and lethal in an HTML body. Fix it by encoding at the point of output, matching the encoding to where the value lands, never by stripping characters on input.

Procedure

  1. Find the DOM sinks that bypass auto-escaping:

    rg -n "dangerouslySetInnerHTML|innerHTML|outerHTML|document\.write|insertAdjacentHTML|v-html" src/
    rg -n "eval\(|new Function\(|setTimeout\(['\"]|location\.href\s*=|\.src\s*=" src/
    
  2. Find the server-side interpolation that does not escape for its context:

    rg -n '\{\{\{ *[a-z]|\| *safe|innerHTML *=' src/ templates/    # Jijia/Django/Handlebars "untrusted"
    
  3. Classify each sink's context — HTML body, attribute value, URL, JS string, CSS — and encode for that context. HTML-escape < > & " '; for a JS string also escape \ and line terminators; for a URL percent-encode.

  4. Rely on the framework's auto-escaping and do not defeat it. In React keep text in {value}; in Django leave {{ value }} as-is; in Jinja2 do not add |safe.

  5. For rich text (comments, markdown, CMS fields), the input is intentionally HTML. Sanitise it with a maintained allowlist library rather than a regex:

    # Node
    const clean = DOMPurify.sanitize(dirty, { ALLOWED_TAGS: ['b','i','a','p'], ALLOWED_ATTR: ['href'] });
    # Python
    import bleach
    clean = bleach.clean(dirty, tags=["b","i","a","p"], attributes={"a":["href"]})
    
  6. Set a Content-Security-Policy as defence in depth (audit-security-response-headers), accepting that CSP is a backstop, not a substitute for encoding.

  7. Verify by injecting a payload into every user-controlled field and confirming it renders as text. Use a marker that is inert unless it executes:

    value="><img src=x onerror=alert(document.domain)>"
    

Pitfalls

  • Escaping for HTML but interpolating into a <script> block leaves the value in a JS context.
  • \ + escapeHtml before building an attribute is often still wrong; encode per context instead.
  • DOMPurify defaults allow href="javascript:..."; pass a URI policy or allowlist schemes.
  • Markdown renderers that allow raw HTML reintroduce XSS; disable raw HTML or sanitise the output.
  • Server-side templating that auto-escapes still breaks when a value is put back through |safe or {{{ }}} for "formatting".
  • React escapes text but not href={userUrl}; javascript: in an href still fires.

Verification

curl -s "https://app.example.com/?q=%22%3E%3Cimg%20src%3Dx%20onerror%3Dalert(1)%3E" \
  | rg -o '<img src=x onerror=alert\(1\)>' && echo "VULNERABLE (raw payload echoed)"

Pass: the payload appears HTML-encoded (&lt;img ...&gt;) and never as live markup, and the sanitiser output contains no event-handler attributes. Report each sink, its context, and the encoding or sanitiser applied.

04 同仓库更多 Skills

jiayaoqijia
jiayaoqijia/cryptoskill

troves

Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

trade

Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

staking

Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

send

Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

portfolio

View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

multi-swap

Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.

★ 81