Secure Development Skill
Implement security best practices to protect user data and prevent common vulnerabilities.
What This Skill Provides
- PII Protection: Hash sensitive data in logs, GDPR compliance
- Input Validation: Prevent SQL injection, XSS, command injection
- Authentication: Secure password storage, session management
- Logging Security: What to log, what to redact
- OWASP Top 10: Prevention strategies for common vulnerabilities
When to Use
- Handling user authentication or authorization
- Logging user inputs (search queries, form data)
- Processing external data (API requests, file uploads)
- Storing sensitive information (passwords, tokens, PII)
- Regulatory compliance (GDPR, HIPAA, SOC 2)
- When user mentions: "security", "authentication", "PII", "GDPR", "vulnerability"
Primitives Included
- Instructions:
pii-protection.instructions.md - Hashing, redaction, compliance
- Instructions:
input-validation.instructions.md - Prevent injection attacks
- Instructions:
secure-authentication.instructions.md - Password storage, sessions
Key Security Principles
1. Defense in Depth
Multiple layers of security - don't rely on single control
2. Fail Securely
When errors occur, fail to secure state (deny access, don't leak info)
3. Principle of Least Privilege
Grant minimum necessary permissions
4. Never Trust User Input
Validate, sanitize, and escape ALL external data
5. Security by Design
Build security in from the start, not as afterthought
Critical: PII in Logs
NEVER log raw user inputs that may contain PII.
Examples of PII:
- Names, email addresses, phone numbers
- Search queries (may contain names/locations)
- IP addresses (GDPR considers PII)
- Credit card numbers, SSNs
- Medical information
- Location data
Safe Logging Pattern:
import { createHash } from 'crypto';
// ❌ NEVER do this
logger.log({ query: userQuery, email: user.email });
// ✅ Hash PII, log metadata
const queryHash = createHash('sha256')
.update(userQuery)
.digest('hex')
.substring(0, 16);
logger.log({
queryHash, // Can correlate same queries
queryLength: userQuery.length, // Metadata OK
userId: user.id // Non-PII identifier OK
});
Example: Secure Search Endpoint
router.post('/search', async (req, res) => {
// 1. Validate input
const schema = z.object({
query: z.string().min(1).max(500),
limit: z.number().int().min(1).max(100).optional()
});
const validated = schema.parse(req.body);
// 2. Sanitize for SQL (use parameterized queries)
const results = await db.query(
'SELECT * FROM items WHERE name LIKE $1 LIMIT $2',
[`%${validated.query}%`, validated.limit || 10]
);
// 3. Log securely (hash PII)
logger.info({
event: 'search',
queryHash: hash(validated.query),
resultCount: results.length,
userId: req.user?.id
});
// 4. Return results (no sensitive internal data)
res.json({ results });
});
Dependencies
- Validation library: Zod, Joi, or class-validator
- Hashing: Node crypto module (SHA256)
- Password hashing: bcrypt or Argon2
- Session management: express-session with secure store
Related Skills: claude-framework (Security S-1 through S-5), fullstack-expertise
1---2name: secure-development3description: Security best practices for production applications including PII protection, input validation, SQL injection prevention, XSS mitigation, and secure logging. Apply when handling user data, authentication, or external inputs.4---5
6# Secure Development Skill
7
8Implement security best practices to protect user data and prevent common vulnerabilities.
9
10## What This Skill Provides
11
12- **PII Protection**: Hash sensitive data in logs, GDPR compliance
13- **Input Validation**: Prevent SQL injection, XSS, command injection
14- **Authentication**: Secure password storage, session management
15- **Logging Security**: What to log, what to redact
16- **OWASP Top 10**: Prevention strategies for common vulnerabilities
17
18## When to Use
19
20- Handling user authentication or authorization
21- Logging user inputs (search queries, form data)
22- Processing external data (API requests, file uploads)
23- Storing sensitive information (passwords, tokens, PII)
24- Regulatory compliance (GDPR, HIPAA, SOC 2)
25- When user mentions: "security", "authentication", "PII", "GDPR", "vulnerability"
26
27## Primitives Included
28
29- **Instructions**: `pii-protection.instructions.md` - Hashing, redaction, compliance
30- **Instructions**: `input-validation.instructions.md` - Prevent injection attacks
31- **Instructions**: `secure-authentication.instructions.md` - Password storage, sessions
32
33## Key Security Principles
34
35### 1. Defense in Depth
36Multiple layers of security - don't rely on single control
37
38### 2. Fail Securely
39When errors occur, fail to secure state (deny access, don't leak info)
40
41### 3. Principle of Least Privilege
42Grant minimum necessary permissions
43
44### 4. Never Trust User Input
45Validate, sanitize, and escape ALL external data
46
47### 5. Security by Design
48Build security in from the start, not as afterthought
49
50## Critical: PII in Logs
51
52**NEVER log raw user inputs that may contain PII.**
53
54**Examples of PII**:
55- Names, email addresses, phone numbers
56- Search queries (may contain names/locations)
57- IP addresses (GDPR considers PII)
58- Credit card numbers, SSNs
59- Medical information
60- Location data
61
62**Safe Logging Pattern**:
63```typescript
64import { createHash } from 'crypto';
65
66// ❌ NEVER do this
67logger.log({ query: userQuery, email: user.email });
68
69// ✅ Hash PII, log metadata
70const queryHash = createHash('sha256')
71 .update(userQuery)
72 .digest('hex')
73 .substring(0, 16);
74
75logger.log({
76 queryHash, // Can correlate same queries
77 queryLength: userQuery.length, // Metadata OK
78 userId: user.id // Non-PII identifier OK
79});
80```
81
82## Example: Secure Search Endpoint
83
84```typescript
85router.post('/search', async (req, res) => {
86 // 1. Validate input
87 const schema = z.object({
88 query: z.string().min(1).max(500),
89 limit: z.number().int().min(1).max(100).optional()
90 });
91
92 const validated = schema.parse(req.body);
93
94 // 2. Sanitize for SQL (use parameterized queries)
95 const results = await db.query(
96 'SELECT * FROM items WHERE name LIKE $1 LIMIT $2',
97 [`%${validated.query}%`, validated.limit || 10]
98 );
99
100 // 3. Log securely (hash PII)
101 logger.info({
102 event: 'search',
103 queryHash: hash(validated.query),
104 resultCount: results.length,
105 userId: req.user?.id
106 });
107
108 // 4. Return results (no sensitive internal data)
109 res.json({ results });
110});
111```
112
113## Dependencies
114
115- Validation library: Zod, Joi, or class-validator
116- Hashing: Node crypto module (SHA256)
117- Password hashing: bcrypt or Argon2
118- Session management: express-session with secure store
119
120---
121
122**Related Skills**: `claude-framework` (Security S-1 through S-5), `fullstack-expertise`