Context-aware output encoding and safe sinks to prevent XSS, SQL injection, and related injection via string composition: HTML/XML, attributes, JS, URL, CSS, SQL/NoSQL parameters, shell argv, and log encoding. Use when output encoding, 输出编码, contextual escaping, encode for HTML, parameterized queries, safe templates, or preventing XSS/SQLi in application code. Complements input-validation-patterns and code-quality-standards; not a full replacement for xss-cross-site-scripting or sqli-sql-injection assessment skills.
Installer avec Codex ou Claude Copiez ce prompt, collez-le dans Codex, Claude ou un autre assistant, puis laissez-le vérifier la page du skill et l'installer pour vous.
Une commande directe contourne le prompt de vérification. Examinez la source avant de l'exécuter.
Context-aware output encoding and safe sinks to prevent XSS, SQL injection, and related injection via string composition: HTML/XML, attributes, JS, URL, CSS, SQL/NoSQL parameters, shell argv, and log encoding. Use when output encoding, 输出编码, contextual escaping, encode for HTML, parameterized queries, safe templates, or preventing XSS/SQLi in application code. Complements input-validation-patterns and code-quality-standards; not a full replacement for xss-cross-site-scripting or sqli-sql-injection assessment skills.
Output Encoding Patterns
Encode or bind data for the consumer context so untrusted values cannot break
out of that context (HTML text, attributes, JavaScript strings, URLs, SQL, shell,
logs). Prefer safe APIs and parameterized interfaces over manual escaping.
Repository templates, ORM/query builders, and CSP/security headers outrank
generic defaults in this skill.
This skill is defensive secure coding for systems you own or are authorized
to harden. It is not guidance for exploiting XSS/SQLi against third-party systems.
Use When
Rendering user or third-party data into HTML, XML, JSON-in-HTML, Markdown→HTML
Building URLs, redirects, headers, or CSS from dynamic values
Writing SQL/NoSQL/LDAP access that might concatenate strings
Choosing template auto-escape, React/Vue text vs raw HTML, or sanitizer libraries
Fixing injection bugs by correcting sink encoding (not only inbound filters)
Reviewing logging of user input (CRLF / forged log lines)
User mentions: output encoding, 输出编码, contextual escaping, HTML encode,
上下文编码, parameterized query, prepared statement, textContent vs
innerHTML, autoescape, OWASP encoders
Repo frameworks, templates, and data-access layers outrank this skill.
Template / UI stack: React/Vue/Svelte/Angular, server templates (Jinja,
Twig, ERB, Razor, Thymeleaf), email HTML builders — use each stack’s
auto-escape defaults and documented “raw HTML” APIs only with policy
Sanitizers already chosen: DOMPurify, Bleach, sanitize-html, OWASP Java
Encoder, etc. — match existing config (allowed tags/attr) rather than adding
a second library
Data access: ORM, query builder, prepared statements, stored procedures —
reuse parameter binding; do not introduce string-SQL helpers beside them
Security headers / CSP: existing CSP, X-Content-Type-Options, cookie flags —
encoding complements CSP; do not weaken CSP to hide encoding bugs
Logging stack: structured loggers and field redaction — follow
logging-message-style conventions already in tree
Neighboring code: copy mature encode/parameterize patterns from the same
service before inventing utilities
I18n templates: locale files and message formats that auto-escape
interpolations — keep user data out of raw HTML message keys
Precedence: If repo rules conflict with defaults below, follow the repo.
Surface conflicts that disable auto-escape globally, use dangerouslySetInnerHTML
without sanitization, or build SQL with string format.
Core Principles
Principle
Practice
Context is king
HTML text ≠ attribute ≠ JS ≠ URL ≠ CSS ≠ SQL; encode for the actual sink
el.innerHTML = userHtml; // full XSS surface// or regex-only strip of "<script>"
Logs
Good
logger.info("login_failed", { userId, reason: "bad_password" });
// user-controlled strings as structured fields, not format strings
Bad
logger.info(`login failed for ${username}\nINFO admin became root`);
Anti-Patterns
Global “disable auto-escape” for convenience
Blacklist filters (replace("<script>", "")) as XSS defense
Storing HTML-escaped data as the only form in the database
Encoding for the wrong context (HTML-escape then put into JS or SQL)
Parameterizing SQL values but concatenating ORDER BY / column names from input
dangerouslySetInnerHTML / v-html / [innerHTML] without sanitizer + policy
Building JSON, XML, or multipart bodies with string templates
Trusting client-side encoding only
Using eval, new Function, or dynamic setTimeout(string) on user data
Assuming validation of “no < character” equals safe HTML attribute/URL use
Weakening CSP (unsafe-inline) instead of fixing encoding sinks
Routing
Situation
Primary
Helper
Context encoding, safe sinks, XSS/SQLi prevention in code, 输出编码
This skill
—
Inbound schemas, allowlists, bounds
input-validation-patterns
this for every sink that still emits data
Implementing encode helpers, templates, tests
code-quality-standards
always apply on code changes
Authorized XSS testing / payload methodology
xss-cross-site-scripting
this when fixing sinks
Authorized SQLi testing methodology
sqli-sql-injection
this when fixing queries
Injection class unknown (assessment)
injection-checking
this for defensive encode map
CSP bypass assessment
content-security-policy-bypass
this for app encoding
CSV formula / export injection assessment
csv-formula-injection
this for defensive export encoding
Log field design and redaction style
logging-message-style
this for CR/LF and injection into logs
Secrets never in logs
secrets-management-hygiene
logging-message-style
Routing to code-quality-standards
Keep this skill primary for which encoding or safe API applies per sink.
Always apply code-quality-standards when implementing or reviewing code:
Prefer clear interfaces that cannot accept “raw HTML” without an explicit type
or reviewed sanitizer boundary
No silent catch of encoding/sanitizer failures on security-critical renders
Tests include breakthrough strings per context (<, quotes, newlines, $ne, ';)
Avoid any flowing into templates or query builders
Document intentional raw-HTML paths with owners and sanitizer config
Regression tests when fixing XSS/SQLi class bugs
Routing to input-validation-patterns
Use input-validation-patterns for parse/allowlist/schema at ingress.
Use this skill wherever data leaves toward a parser (browser, DB, shell).
Features that accept text and render or query it need both.
Routing to assessment skills
xss-cross-site-scripting / sqli-sql-injection: primary for authorized
offensive methodology and impact proof.
This skill: primary when writing or fixing product code to eliminate sinks.
Checklist
Repo template auto-escape, sanitizer, ORM/query, and CSP settings identified
Context-correct encoders used only where safe APIs are unavailable
No global auto-escape off; raw HTML paths explicit, sanitized, and reviewed
URLs: scheme/host allowlist + URL/query APIs for encoding
SQL/NoSQL: parameters for values; allowlists for identifiers/operators
Rich text: tag/attr allowlist sanitizer + CSP defense in depth
Domain models store raw data; encode at output boundaries
Logs structured; CR/LF and format-string injection considered
CSV/export formula-safe handling when Excel consumers exist
Tests cover per-context breakthrough payloads; fixes locked with regression tests
input-validation-patterns applied at ingress for the same feature
code-quality-standards applied for implementation quality and verification
Assessment-depth testing handed to XSS/SQLi skills when engagement requires it
Rules
Encode for the actual consumer context; never one generic “escape all” for every sink.
Prefer APIs that make injection unrepresentable over manual string munging.
Validate input and encode output — neither replaces the other.
Parameterize queries; allowlist identifiers; never shell-interpolate untrusted text.
Repo frameworks and ORMs win; this skill supplies the context map and review bar.
Defensive engineering and authorized hardening only.
Note
This skill owns context-aware output encoding and safe sink selection.
Pair with input-validation-patterns at ingress, code-quality-standards on
implementation, and XSS/SQLi assessment skills when authorized testing depth is
required rather than product-code defense.