A software security skill that integrates with Project CodeGuard to help AI coding agents write secure code and prevent common vulnerabilities. Use this skill when writing, reviewing, or modifying code to ensure secure-by-default practices are followed.
rule_id: codeguard-0-client-side-web-security
Protect browser clients against code injection, request forgery, UI redress, cross‑site leaks, and unsafe third‑party scripts with layered, context‑aware controls.
textContent. If HTML is required, sanitize with a vetted library (e.g., DOMPurify) and strict allow‑lists.addEventListener.javascript: and data URLs where inappropriate.Example sanitization:
const clean = DOMPurify.sanitize(userHtml, {
ALLOWED_TAGS: ['b','i','p','a','ul','li'],
ALLOWED_ATTR: ['href','target','rel'],
ALLOW_DATA_ATTR: false
});innerHTML, outerHTML, document.write with untrusted data.eval, new Function, string‑based setTimeout/Interval.location or event handler properties.Trusted Types + CSP:
Content-Security-Policy: script-src 'self' 'nonce-{random}'; object-src 'none'; base-uri 'self'; require-trusted-types-for 'script'default-src 'self'; style-src 'self' 'unsafe-inline'; frame-ancestors 'self'; form-action 'self'; object-src 'none'; base-uri 'none'; upgrade-insecure-requests.SameSite=Lax or Strict; sessions Secure and HttpOnly; use __Host- prefix when possible.Content-Security-Policy: frame-ancestors 'none' or a specific allow‑list.X-Frame-Options: DENY or SAMEORIGIN.SameSite cookies appropriately; prefer Strict for sensitive actions.sandbox and postMessage origin checks.SRI example:
<script src="https://cdn.vendor.com/app.js"
integrity="sha384-..." crossorigin="anonymous"></script>event.origin on receive.*; allow‑list origins; validate preflights; do not rely on CORS for authz.wss://, origin checks, auth, message size limits, and safe JSON parsing.localStorage/sessionStorage; prefer HttpOnly cookies; if unavoidable, isolate via Web Workers.rel="noopener noreferrer" to external target=_blank links.nosniff.JSON.stringify; never via string concatenation.textContent/safe attributes over raw HTML insertion.tessl i cisco/software-security@1.2.5evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
rules