security-hardening
Hardens client-side security by enforcing CSP and sanitizing user inputs.
Install
mkdir -p .claude/skills/security-hardening && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/9733" && unzip -o skill.zip -d .claude/skills/security-hardening && rm skill.zipInstalls to .claude/skills/security-hardening
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Implement client-side security measures including Content Security Policy, input sanitization, XSS prevention, and secure data handling. Use when handling user input, displaying dynamic content, or storing sensitive data.Key capabilities
- →Sanitize user-generated HTML content
- →Validate URLs to prevent javascript protocol injection
- →Implement subresource integrity for external scripts
- →Apply sandbox attributes to iframes
How it works
The skill provides patterns for sanitizing HTML using DOMPurify, configuring CSP meta tags, and applying security attributes to iframes and links.
Inputs & outputs
When to use security-hardening
- →Sanitizing user-generated content
- →Implementing Content Security Policy
- →Securing data storage
- →Preventing XSS in React apps
About this skill
Security Hardening
When to Use This Skill
Use when:
- Handling user-generated content
- Storing sensitive data client-side
- Embedding external content
- Implementing authentication flows
XSS Prevention
Never Use dangerouslySetInnerHTML Unsafely
// ❌ Dangerous
<div dangerouslySetInnerHTML={{ __html: userContent }} />
// ✅ Safe - use a sanitizer
import DOMPurify from 'dompurify';
<div
dangerouslySetInnerHTML={{
__html: DOMPurify.sanitize(userContent)
}}
/>
Sanitize with DOMPurify
import DOMPurify from 'dompurify';
// Basic sanitization
const clean = DOMPurify.sanitize(dirty);
// Allow specific tags only
const cleanStrict = DOMPurify.sanitize(dirty, {
ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'a'],
ALLOWED_ATTR: ['href']
});
// Remove all HTML
const textOnly = DOMPurify.sanitize(dirty, { ALLOWED_TAGS: [] });
Content Security Policy (CSP)
Meta Tag CSP
<meta
http-equiv="Content-Security-Policy"
content="
default-src 'self';
script-src 'self' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
font-src 'self';
connect-src 'self' https://api.example.com;
"
>
Common CSP Directives
| Directive | Purpose |
|---|---|
default-src | Fallback for other directives |
script-src | JavaScript sources |
style-src | CSS sources |
img-src | Image sources |
connect-src | XHR, WebSocket, fetch |
frame-src | iframe sources |
Secure Data Storage
Sensitive Data Handling
// ❌ Don't store sensitive data in localStorage
localStorage.setItem('token', secretToken);
// ✅ Use sessionStorage for session-bound data
sessionStorage.setItem('token', secretToken);
// ✅ Better: Use httpOnly cookies (server-set)
// ✅ Best: Don't store on client if possible
Encrypt Before Storing (if necessary)
// Using SubtleCrypto API
async function encrypt(data: string, key: CryptoKey): Promise<string> {
const iv = crypto.getRandomValues(new Uint8Array(12));
const encoded = new TextEncoder().encode(data);
const encrypted = await crypto.subtle.encrypt(
{ name: 'AES-GCM', iv },
key,
encoded
);
return btoa(
String.fromCharCode(...iv) +
String.fromCharCode(...new Uint8Array(encrypted))
);
}
URL Handling
Validate URLs
function isValidUrl(url: string): boolean {
try {
const parsed = new URL(url);
return ['http:', 'https:'].includes(parsed.protocol);
} catch {
return false;
}
}
// ❌ Don't allow javascript: URLs
function sanitizeHref(href: string): string {
if (href.toLowerCase().startsWith('javascript:')) {
return '#';
}
return href;
}
Open External Links Safely
<a
href={externalUrl}
target="_blank"
rel="noopener noreferrer" // Prevents window.opener attacks
>
External Link
</a>
Input Validation
// Validate on both client AND server
function validateEmail(email: string): boolean {
const pattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return pattern.test(email);
}
// Limit input length
<input
type="text"
maxLength={100}
value={value}
onChange={(e) => setValue(e.target.value.slice(0, 100))}
/>
Iframe Security
// Sandbox iframes
<iframe
src={externalContent}
sandbox="allow-scripts allow-same-origin"
referrerPolicy="no-referrer"
/>
Subresource Integrity
<script
src="https://cdn.example.com/library.js"
integrity="sha384-abc123..."
crossorigin="anonymous"
></script>
Security Checklist
- Sanitize all user-generated HTML content
- Validate URLs before using
- Use
rel="noopener noreferrer"on external links - Implement CSP headers/meta tags
- Never store secrets in client code
- Use HTTPS only
- Validate all inputs client-side AND server-side
- Sandbox iframes from untrusted sources
When not to use it
- →When server-side validation is absent
- →When storing secrets in client-side code
Limitations
- →Requires manual implementation of security headers
- →Client-side validation is not a substitute for server-side checks
How it compares
It provides specific code-level security patterns for React and TypeScript rather than general security advice.
Compared to similar skills
security-hardening side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| security-hardening (this skill) | 0 | 6mo | No flags | Intermediate |
| xss-scan | 0 | 6mo | Review | Beginner |
| fullstack-guardian | 1 | 3mo | No flags | Advanced |
| tauri | 0 | 5mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
xss-scan
itsimonfredlingjack
You are a frontend security specialist focusing on Cross-Site Scripting (XSS) vulnerability detection and prevention. Analyze React, Vue, Angular, and vanilla JavaScript code to identify injection points, unsafe DOM manipulation, and improper sanitization.
fullstack-guardian
Jeffallan
Use when implementing features across frontend and backend, building APIs with UI, or creating end-to-end data flows. Invoke for feature implementation, API development, UI building, cross-stack work.
tauri
BiFangKNT
构建、调试与发布 Tauri v2 应用的工程化工作流。覆盖项目初始化(create-tauri-app)、前端与 Rust 命令通信(`#[tauri::command]` + `invoke`)、状态管理、Capabilities 权限建模、插件接入、跨平台构建与问题排查。当用户需求涉及“创建 Tauri 项目”“把 Web 前端接到 Rust 后端”“最小权限配置(fs/http/shell)”“接入 Tauri 官方插件”“执行 tauri dev/build”“排查 Tauri 构建或运行错误”时使用此 skill。
frontend-mobile-security-xss-scan
sickn33
You are a frontend security specialist focusing on Cross-Site Scripting (XSS) vulnerability detection and prevention. Analyze React, Vue, Angular, and vanilla JavaScript code to identify injection poi
skills
xDaijobu
How to work with TLS Watch - a TLS certificate monitoring application
ui-ux-pro-max
nextlevelbuilder
UI/UX design intelligence. 50 styles, 21 palettes, 50 font pairings, 20 charts, 8 stacks (React, Next.js, Vue, Svelte, SwiftUI, React Native, Flutter, Tailwind). Actions: plan, build, create, design, implement, review, fix, improve, optimize, enhance, refactor, check UI/UX code. Projects: website, landing page, dashboard, admin panel, e-commerce, SaaS, portfolio, blog, mobile app, .html, .tsx, .vue, .svelte. Elements: button, modal, navbar, sidebar, card, table, form, chart. Styles: glassmorphism, claymorphism, minimalism, brutalism, neumorphism, bento grid, dark mode, responsive, skeuomorphism, flat design. Topics: color palette, accessibility, animation, layout, typography, font pairing, spacing, hover, shadow, gradient.