frontend-security
Use when the user asks how to prevent XSS and set a content security policy, CSP nonces, Trusted Types, DOMPurify, CSRF tokens, SRI, secure cookies…
от j4flmao★ 47 звёзд на GitHub
Установить frontend-security в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Frontend Security
Purpose
Prevent XSS, CSRF, and injection attacks. CSP blocks unauthorized scripts. SRI ensures CDN integrity. Cookies locked down. All user output encoded.
Agent Protocol
Trigger
Exact user phrases: "XSS", "CSP", "CSRF", "SRI", "secure cookies", "security headers", "frontend security", "sanitize input", "content security policy", "cross-site scripting".
Input Context
Before activating, verify:
- The framework and build tool (React, Vue, Vite, Next.js, etc.).
- Whether the focus is on a new feature, an audit, or a vulnerability fix.
Output Artifact
No file output. Produces security guidance, header configs, or code fixes as text.
Response Format
Issue: {description}
Severity: {critical/high/medium/low}
Config: {code block or header directive}
No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.
Completion Criteria
- CSP header present and blocks inline scripts (nonce or hash only).
- SRI hashes on all external CSS/JS resources.
- Cookies use HttpOnly + Secure + SameSite=Lax or Strict.
- State-changing requests include CSRF token.
- All user-supplied data is escaped before rendering (no dangerouslySetInnerHTML without DOMPurify).
- Input sanitization on all form fields.
Max Response Length
4096 tokens.
Security Architecture / Decision Trees
CSP Strategy Decision Tree
Are inline scripts needed?
|-- NO (all scripts are separate .js files) -->
| CSP: script-src 'self'
| Simplest, most secure. No nonce or hash needed.
|
|-- YES (inline event handlers, inline <script> tags) -->
| |-- Can generate nonce per request? -->
| | YES: script-src 'self' 'nonce-{random}' (nonce-based CSP)
| | NO: script-src 'self' 'sha256-{hash}' (hash-based CSP, static)
| |
| |-- Use 'strict-dynamic' for modern apps (auto-trusts scripts loaded by trusted scripts)
| CSP: script-src 'self' 'nonce-{random}' 'strict-dynamic'
Vulnerability Triage Decision Tree
What type of vulnerability?
|-- User input rendered as HTML? -->
| Threat: XSS
| Fix: DOMPurify before dangerouslySetInnerHTML or v-html
| Severity: CRITICAL
|
|-- External resource loaded (CDN, third-party)? -->
| Threat: Compromised CDN serves malicious code
| Fix: Add SRI integrity hash + crossorigin attribute
| Severity: HIGH
|
|-- State-changing request (POST/PUT/DELETE)? -->
| Threat: CSRF (cross-site request forgery)
| Fix: CSRF token in header or SameSite=Strict cookie
| Severity: HIGH
|
|-- Cookie contains session data? -->
| Threat: Session hijacking via XSS
| Fix: HttpOnly + Secure + SameSite=Strict
| Severity: CRITICAL
|
|-- Third-party script on page (analytics, ads, widgets)? -->
Threat: Data exfiltration
Fix: CSP restrict-src, SRI on loaded scripts
Severity: MEDIUM
Workflow
Step 1: Content Security Policy
<!-- Strict CSP (recommended) -->
<meta http-equiv="Content-Security-Policy" content="
default-src 'self';
script-src 'self' 'nonce-{random}' 'strict-dynamic';
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
object-src 'none';
base-uri 'none';
form-action 'self';
">
Step 2: Subresource Integrity
<script
src="https://cdn.example.com/lib.js"
integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
crossorigin="anonymous"
></script>
Step 3: Secure Cookies
// Server-side cookie config
document.cookie = 'session=abc123; HttpOnly; Secure; SameSite=Lax; Path=/; Max-Age=86400'
// With js-cookie or similar client library — only for non-sensitive cookies
Cookies.set('preference', 'dark', {
secure: true,
sameSite: 'lax',
expires: 365,
})
Step 4: CSRF Protection
// Include CSRF token in fetch
const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content')
await fetch('/api/transfer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-Token': csrfToken ?? '',
},
body: JSON.stringify({ amount, to }),
})
Step 5: XSS Prevention
// React — default escaping handles most XSS
// But NEVER use dangerouslySetInnerHTML with unsanitized input
import DOMPurify from 'dompurify'
function SafeHtml({ html }: { html: string }) {
const clean = useMemo(() => DOMPurify.sanitize(html), [html])
return <div dangerouslySetInnerHTML={{ __html: clean }} />
}
Step 6: Security Headers Checklist
| Header | Value | Purpose |
|---|---|---|
Content-Security-Policy |
(see above) | Prevents XSS & data injection |
X-Content-Type-Options |
nosniff |
Prevents MIME sniffing |
X-Frame-Options |
DENY |
Prevents clickjacking |
Strict-Transport-Security |
`max-age=64672 |
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/csp-implementation.md
- references/csrf-protection.md
- references/dependency-security.md
- references/web-security-headers.md
- references/xss-prevention.md
- references/xss-protection.md
FAQ
Что делает скилл frontend-security?
Use when the user asks how to prevent XSS and set a content security policy, CSP nonces, Trusted Types, DOMPurify, CSRF tokens, SRI, secure cookies, clickjacking or security headers for a web app. Produces frontend hardening code and header config. Not for server-side OWASP testing (use owasp-web-security) or login flows (use frontend-authentication).
Как установить скилл frontend-security?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл frontend-security запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…