@neyugn/agent-kits 0.5.1 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/skills/filter-agent/SKILL.md +33 -45
- package/common/skills/filter-skill/SKILL.md +51 -73
- package/common/skills/scan-techstack/SKILL.md +30 -36
- package/kits/coder/agents/ai-engineer.md +27 -39
- package/kits/coder/agents/backend-specialist.md +31 -45
- package/kits/coder/agents/cloud-architect.md +31 -45
- package/kits/coder/agents/code-reviewer.md +45 -67
- package/kits/coder/agents/data-engineer.md +22 -32
- package/kits/coder/agents/database-specialist.md +30 -44
- package/kits/coder/agents/debugger.md +28 -42
- package/kits/coder/agents/devops-engineer.md +35 -53
- package/kits/coder/agents/documentation-writer.md +48 -68
- package/kits/coder/agents/frontend-specialist.md +30 -46
- package/kits/coder/agents/i18n-specialist.md +37 -51
- package/kits/coder/agents/integration-specialist.md +38 -54
- package/kits/coder/agents/mobile-developer.md +37 -53
- package/kits/coder/agents/multi-tenant-architect.md +25 -37
- package/kits/coder/agents/orchestrator.md +20 -32
- package/kits/coder/agents/performance-analyst.md +43 -65
- package/kits/coder/agents/project-planner.md +25 -39
- package/kits/coder/agents/queue-specialist.md +26 -38
- package/kits/coder/agents/realtime-specialist.md +44 -64
- package/kits/coder/agents/security-auditor.md +44 -64
- package/kits/coder/agents/test-engineer.md +30 -44
- package/kits/coder/agents/ux-researcher.md +26 -38
- package/kits/coder/rules/AGENTS.md +3 -1
- package/kits/coder/rules/CLAUDE.md +3 -1
- package/kits/coder/rules/CURSOR.md +8 -1
- package/kits/coder/rules/GEMINI.md +6 -1
- package/kits/coder/rules/OPENCODE.md +3 -1
- package/kits/coder/rules/sections/classifier.md +11 -7
- package/kits/coder/rules/sections/code.md +5 -4
- package/kits/coder/rules/sections/routing.md +10 -2
- package/kits/coder/rules/sections/universal.md +2 -0
- package/kits/coder/skills/accessibility-patterns/SKILL.md +67 -81
- package/kits/coder/skills/ai-rag-patterns/SKILL.md +27 -23
- package/kits/coder/skills/api-patterns/SKILL.md +40 -43
- package/kits/coder/skills/auth-patterns/SKILL.md +47 -51
- package/kits/coder/skills/aws-patterns/SKILL.md +52 -57
- package/kits/coder/skills/brainstorming/SKILL.md +26 -23
- package/kits/coder/skills/clean-code/SKILL.md +74 -90
- package/kits/coder/skills/database-design/SKILL.md +32 -31
- package/kits/coder/skills/docker-patterns/SKILL.md +46 -49
- package/kits/coder/skills/documentation-templates/SKILL.md +21 -13
- package/kits/coder/skills/e2e-testing/SKILL.md +52 -58
- package/kits/coder/skills/flutter-patterns/SKILL.md +44 -46
- package/kits/coder/skills/frontend-design/SKILL.md +28 -24
- package/kits/coder/skills/github-actions/SKILL.md +43 -45
- package/kits/coder/skills/gitlab-ci-patterns/SKILL.md +35 -33
- package/kits/coder/skills/graphql-patterns/SKILL.md +35 -33
- package/kits/coder/skills/i18n-localization/SKILL.md +37 -35
- package/kits/coder/skills/kubernetes-patterns/SKILL.md +35 -33
- package/kits/coder/skills/mermaid-diagrams/SKILL.md +54 -60
- package/kits/coder/skills/mobile-design/SKILL.md +51 -61
- package/kits/coder/skills/monitoring-observability/SKILL.md +32 -30
- package/kits/coder/skills/multi-tenancy/SKILL.md +16 -8
- package/kits/coder/skills/nodejs-best-practices/SKILL.md +19 -14
- package/kits/coder/skills/performance-profiling/SKILL.md +31 -29
- package/kits/coder/skills/plan-writing/SKILL.md +52 -59
- package/kits/coder/skills/postgres-patterns/SKILL.md +39 -39
- package/kits/coder/skills/prompt-engineering/SKILL.md +40 -42
- package/kits/coder/skills/queue-patterns/SKILL.md +22 -16
- package/kits/coder/skills/react-native-patterns/SKILL.md +35 -33
- package/kits/coder/skills/react-patterns/SKILL.md +46 -52
- package/kits/coder/skills/realtime-patterns/SKILL.md +44 -46
- package/kits/coder/skills/redis-patterns/SKILL.md +35 -33
- package/kits/coder/skills/security-fundamentals/SKILL.md +45 -46
- package/kits/coder/skills/seo-patterns/SKILL.md +56 -62
- package/kits/coder/skills/systematic-debugging/SKILL.md +38 -39
- package/kits/coder/skills/tailwind-patterns/SKILL.md +21 -13
- package/kits/coder/skills/terraform-patterns/SKILL.md +53 -57
- package/kits/coder/skills/testing-patterns/SKILL.md +42 -47
- package/kits/coder/skills/typescript-patterns/SKILL.md +54 -68
- package/kits/coder/skills/ui-ux-pro-max/SKILL.md +362 -364
- package/package.json +1 -1
|
@@ -6,17 +6,25 @@ allowed-tools: Read, Write, Edit, Glob, Grep
|
|
|
6
6
|
|
|
7
7
|
# React Patterns
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## ⚡ Quick Reference
|
|
10
|
+
|
|
11
|
+
- **State**: Local → useState · Shared → Context/Zustand · Server → React Query · avoid Redux for new projects
|
|
12
|
+
- **Performance**: `memo` for expensive renders · `useMemo` for costly computations · `useCallback` for stable refs
|
|
13
|
+
- **Hooks rules**: Top-level only · No conditionals · Custom hooks extract logic not UI
|
|
14
|
+
- **Keys**: Stable unique IDs not array index · Missing keys = bugs in list reorder
|
|
15
|
+
- **Async**: React Query for server state · `useEffect` with cleanup for subscriptions · no fire-and-forget
|
|
16
|
+
- **Avoid**: Prop drilling > 2 levels (use context) · useEffect for derived state (useMemo) · `any` in TypeScript
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
10
20
|
|
|
11
21
|
---
|
|
12
22
|
|
|
13
23
|
## 📑 Content Map
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
| `references/performance.md` | Deep performance optimization |
|
|
19
|
-
| `references/nextjs-patterns.md` | Next.js App Router specific |
|
|
25
|
+
- `references/hook-patterns.md`: Advanced custom hooks
|
|
26
|
+
- `references/performance.md`: Deep performance optimization
|
|
27
|
+
- `references/nextjs-patterns.md`: Next.js App Router specific
|
|
20
28
|
|
|
21
29
|
---
|
|
22
30
|
|
|
@@ -33,12 +41,10 @@ allowed-tools: Read, Write, Edit, Glob, Grep
|
|
|
33
41
|
|
|
34
42
|
### Design Rules
|
|
35
43
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
| Composition over inheritance | Flexibility, avoid prop drilling |
|
|
41
|
-
| Small, focused components | Better tree shaking, readability |
|
|
44
|
+
- One responsibility: Easier testing, reuse
|
|
45
|
+
- Props down, events up: Predictable data flow
|
|
46
|
+
- Composition over inheritance: Flexibility, avoid prop drilling
|
|
47
|
+
- Small, focused components: Better tree shaking, readability
|
|
42
48
|
|
|
43
49
|
---
|
|
44
50
|
|
|
@@ -46,23 +52,19 @@ allowed-tools: Read, Write, Edit, Glob, Grep
|
|
|
46
52
|
|
|
47
53
|
### When to Extract Custom Hooks
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
| `useClickOutside` | Multiple modal/dropdown components |
|
|
56
|
-
| `usePrevious` | Need previous value in multiple places |
|
|
55
|
+
- `useLocalStorage`: Same storage logic needed
|
|
56
|
+
- `useDebounce`: Multiple debounced values
|
|
57
|
+
- `useFetch`: Repeated fetch patterns
|
|
58
|
+
- `useForm`: Complex form state
|
|
59
|
+
- `useClickOutside`: Multiple modal/dropdown components
|
|
60
|
+
- `usePrevious`: Need previous value in multiple places
|
|
57
61
|
|
|
58
62
|
### Hook Rules (CRITICAL)
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
| Prefix with "use" | Lint error, convention violation |
|
|
65
|
-
| Clean up effects | Memory leaks, stale closures |
|
|
64
|
+
- Top level only: Inconsistent state
|
|
65
|
+
- Same order every render: React loses track of state
|
|
66
|
+
- Prefix with "use": Lint error, convention violation
|
|
67
|
+
- Clean up effects: Memory leaks, stale closures
|
|
66
68
|
|
|
67
69
|
### React 19 New Hooks
|
|
68
70
|
|
|
@@ -182,12 +184,10 @@ State scope?
|
|
|
182
184
|
|
|
183
185
|
### Recovery Pattern
|
|
184
186
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
| 3 | Offer retry option |
|
|
190
|
-
| 4 | Preserve user data if possible |
|
|
187
|
+
- 1: Show fallback UI
|
|
188
|
+
- 2: Log error (Sentry, DataDog)
|
|
189
|
+
- 3: Offer retry option
|
|
190
|
+
- 4: Preserve user data if possible
|
|
191
191
|
|
|
192
192
|
---
|
|
193
193
|
|
|
@@ -203,12 +203,10 @@ State scope?
|
|
|
203
203
|
|
|
204
204
|
### Essential Types
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
| Ref | `RefObject<Element>` |
|
|
211
|
-
| Component ref | `ComponentRef<typeof X>` |
|
|
206
|
+
- Children: `ReactNode`
|
|
207
|
+
- Event handler: `MouseEventHandler<T>`
|
|
208
|
+
- Ref: `RefObject<Element>`
|
|
209
|
+
- Component ref: `ComponentRef<typeof X>`
|
|
212
210
|
|
|
213
211
|
---
|
|
214
212
|
|
|
@@ -261,13 +259,11 @@ Does component need...?
|
|
|
261
259
|
|
|
262
260
|
### File Conventions
|
|
263
261
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
| `error.tsx` | Error boundary |
|
|
270
|
-
| `not-found.tsx` | 404 page |
|
|
262
|
+
- `page.tsx`: Route UI
|
|
263
|
+
- `layout.tsx`: Shared layout
|
|
264
|
+
- `loading.tsx`: Loading skeleton
|
|
265
|
+
- `error.tsx`: Error boundary
|
|
266
|
+
- `not-found.tsx`: 404 page
|
|
271
267
|
|
|
272
268
|
### Caching Strategy
|
|
273
269
|
|
|
@@ -306,13 +302,11 @@ Simple local? → useState
|
|
|
306
302
|
|
|
307
303
|
## Related Skills
|
|
308
304
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
| TypeScript advanced | `typescript-patterns` |
|
|
315
|
-
| Performance deep-dive | `performance-profiling` |
|
|
305
|
+
- Styling: `tailwind-patterns`
|
|
306
|
+
- Testing: `testing-patterns`
|
|
307
|
+
- API integration: `api-patterns`
|
|
308
|
+
- TypeScript advanced: `typescript-patterns`
|
|
309
|
+
- Performance deep-dive: `performance-profiling`
|
|
316
310
|
|
|
317
311
|
---
|
|
318
312
|
|
|
@@ -6,7 +6,17 @@ allowed-tools: Read, Write, Edit, Bash
|
|
|
6
6
|
|
|
7
7
|
# Realtime Patterns - Event-Driven Communication Architecture
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## ⚡ Quick Reference
|
|
10
|
+
|
|
11
|
+
- **Protocol selection**: Chat/games → WebSocket · News/notifications → SSE · Simple push → Long-polling
|
|
12
|
+
- **Reconnection**: Exponential backoff (1s → 2s → 4s max 30s) · Client-side always handles reconnect
|
|
13
|
+
- **Rooms/channels**: `socket.join(roomId)` · `io.to(room).emit()` · Clean up on disconnect
|
|
14
|
+
- **Auth**: JWT in handshake query/header (not cookie for WS) · Validate on every connection
|
|
15
|
+
- **Scaling**: Redis adapter for Socket.IO multi-instance · Sticky sessions OR pub/sub architecture
|
|
16
|
+
- **State sync**: Send missed events on reconnect · Event sequence numbers · Client-side reconciliation
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
10
20
|
|
|
11
21
|
---
|
|
12
22
|
|
|
@@ -84,12 +94,10 @@ interface ConnectionState {
|
|
|
84
94
|
|
|
85
95
|
### Keep-Alive (Heartbeat)
|
|
86
96
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
| **On Timeout** | Trigger reconnection |
|
|
92
|
-
| **Payload** | Minimal (empty or timestamp only) |
|
|
97
|
+
- **Interval**: 25-30 seconds (under typical 60s timeout)
|
|
98
|
+
- **Pong Timeout**: 5-10 seconds after ping sent
|
|
99
|
+
- **On Timeout**: Trigger reconnection
|
|
100
|
+
- **Payload**: Minimal (empty or timestamp only)
|
|
93
101
|
|
|
94
102
|
```typescript
|
|
95
103
|
// Heartbeat pattern
|
|
@@ -313,13 +321,11 @@ io.adapter(createAdapter(pubClient, subClient));
|
|
|
313
321
|
|
|
314
322
|
### Scaling Considerations
|
|
315
323
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
| **N-Squared Problem** | Sharded Redis adapter (Redis 7.0+) |
|
|
322
|
-
| **Message Order** | Use sequence numbers or timestamps |
|
|
324
|
+
- **Sticky Sessions**: Use consistent hashing or client IP-based
|
|
325
|
+
- **Cross-Server Emit**: Redis Pub/Sub adapter
|
|
326
|
+
- **Connection State**: Store in Redis, not in-memory
|
|
327
|
+
- **N-Squared Problem**: Sharded Redis adapter (Redis 7.0+)
|
|
328
|
+
- **Message Order**: Use sequence numbers or timestamps
|
|
323
329
|
|
|
324
330
|
---
|
|
325
331
|
|
|
@@ -350,14 +356,12 @@ io.use(async (socket, next) => {
|
|
|
350
356
|
|
|
351
357
|
### Security Checklist
|
|
352
358
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
| **Message Size** | Limit max payload size |
|
|
360
|
-
| **Origin Check** | Configure CORS properly |
|
|
359
|
+
- **Authentication**: Validate token before accepting socket
|
|
360
|
+
- **Authorization**: Check permissions before joining rooms
|
|
361
|
+
- **Rate Limiting**: Limit events per second per client
|
|
362
|
+
- **Payload Validation**: Validate and sanitize all incoming data
|
|
363
|
+
- **Message Size**: Limit max payload size
|
|
364
|
+
- **Origin Check**: Configure CORS properly
|
|
361
365
|
|
|
362
366
|
---
|
|
363
367
|
|
|
@@ -399,14 +403,12 @@ socket.on("error", (error) => {
|
|
|
399
403
|
|
|
400
404
|
### Key Metrics
|
|
401
405
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
| **Messages/Second** | Throughput, capacity planning |
|
|
409
|
-
| **Error Rate** | System health |
|
|
406
|
+
- **Active Connections**: Current load, scaling needs
|
|
407
|
+
- **Connection Rate**: Traffic patterns, spikes
|
|
408
|
+
- **Reconnection Rate**: Connection stability issues
|
|
409
|
+
- **Message Latency**: System responsiveness
|
|
410
|
+
- **Messages/Second**: Throughput, capacity planning
|
|
411
|
+
- **Error Rate**: System health
|
|
410
412
|
|
|
411
413
|
### Debugging Tips
|
|
412
414
|
|
|
@@ -433,16 +435,14 @@ socket.io.on("reconnect_error", (error) => {
|
|
|
433
435
|
|
|
434
436
|
## 🚨 Anti-Patterns
|
|
435
437
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
| Send sensitive data in events | Encrypt or use HTTPS/WSS only |
|
|
445
|
-
| Process without validation | Validate all incoming payloads |
|
|
438
|
+
- Send large objects over socket: Send IDs, fetch data via HTTP
|
|
439
|
+
- Block in event handlers: Process async, return quickly
|
|
440
|
+
- Trust client-sent room names: Validate and authorize room access
|
|
441
|
+
- Reconnect immediately on failure: Use exponential backoff with jitter
|
|
442
|
+
- Store state in single server memory: Use Redis for cross-server state
|
|
443
|
+
- Ignore connection state: Track and display to user
|
|
444
|
+
- Send sensitive data in events: Encrypt or use HTTPS/WSS only
|
|
445
|
+
- Process without validation: Validate all incoming payloads
|
|
446
446
|
|
|
447
447
|
---
|
|
448
448
|
|
|
@@ -494,12 +494,10 @@ socket.io.on("reconnect_error", (error) => {
|
|
|
494
494
|
|
|
495
495
|
## 🔗 Related Skills
|
|
496
496
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
| Queue/worker patterns | `queue-patterns` |
|
|
502
|
-
| Database for state | `database-design` |
|
|
497
|
+
- API design for HTTP calls: `api-patterns`
|
|
498
|
+
- Performance optimization: `performance-profiling`
|
|
499
|
+
- Queue/worker patterns: `queue-patterns`
|
|
500
|
+
- Database for state: `database-design`
|
|
503
501
|
|
|
504
502
|
---
|
|
505
503
|
|
|
@@ -7,21 +7,29 @@ version: 2.0
|
|
|
7
7
|
|
|
8
8
|
# Redis Patterns - Caching & Real-Time
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
## ⚡ Quick Reference
|
|
11
|
+
|
|
12
|
+
- **Structures**: String (simple cache) · Hash (objects) · List (queues/history) · Set (unique items) · Sorted Set (leaderboards/priority)
|
|
13
|
+
- **Expiry**: Always set TTL · `SET key val EX 3600` · no orphaned keys
|
|
14
|
+
- **Key naming**: `tenant:{id}:user:{id}` prefix convention · colon separator · descriptive
|
|
15
|
+
- **Caching**: Cache-aside pattern · Invalidate on write · Short TTL for volatile data
|
|
16
|
+
- **Concurrency**: `INCR` for atomic counters · Lua scripts for multi-key atomicity · `SETNX` for locks
|
|
17
|
+
- **Persistence**: AOF for production · RDB for dev only · `maxmemory-policy allkeys-lru` for cache use
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
11
21
|
|
|
12
22
|
---
|
|
13
23
|
|
|
14
24
|
## When to Use This Skill
|
|
15
25
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
| Real-time leaderboards | Large document storage |
|
|
24
|
-
| Queue/Job patterns | Complex aggregations |
|
|
26
|
+
- Caching strategies: Primary database design
|
|
27
|
+
- Session management: Complex querying
|
|
28
|
+
- Rate limiting: Relational data
|
|
29
|
+
- Pub/Sub messaging: Durable storage requirements
|
|
30
|
+
- Distributed locking: ACID transactions
|
|
31
|
+
- Real-time leaderboards: Large document storage
|
|
32
|
+
- Queue/Job patterns: Complex aggregations
|
|
25
33
|
|
|
26
34
|
---
|
|
27
35
|
|
|
@@ -391,13 +399,11 @@ await redis.expire("leaderboard:weekly", 604800); // 7 days
|
|
|
391
399
|
|
|
392
400
|
### Eviction Policies
|
|
393
401
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
| `allkeys-lfu` | Frequency-based eviction |
|
|
400
|
-
| `allkeys-random` | Random eviction |
|
|
402
|
+
- `noeviction`: Fail writes when memory full
|
|
403
|
+
- `allkeys-lru`: General caching (recommended)
|
|
404
|
+
- `volatile-lru`: Only evict keys with TTL
|
|
405
|
+
- `allkeys-lfu`: Frequency-based eviction
|
|
406
|
+
- `allkeys-random`: Random eviction
|
|
401
407
|
|
|
402
408
|
### Memory Optimization
|
|
403
409
|
|
|
@@ -442,16 +448,14 @@ Examples:
|
|
|
442
448
|
|
|
443
449
|
## Anti-Patterns
|
|
444
450
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
| Store complex relational data | Use proper database for relations |
|
|
454
|
-
| Ignore memory limits | Configure maxmemory + eviction policy |
|
|
451
|
+
- Store without TTL: Always set expiration
|
|
452
|
+
- Use KEYS in production: Use SCAN for iteration
|
|
453
|
+
- Large values (>1MB): Split or use different storage
|
|
454
|
+
- Create connection per request: Use connection pooling
|
|
455
|
+
- Use as primary database: Use as cache/session/queue layer
|
|
456
|
+
- Block with BLPOP in main thread: Dedicated subscriber connections
|
|
457
|
+
- Store complex relational data: Use proper database for relations
|
|
458
|
+
- Ignore memory limits: Configure maxmemory + eviction policy
|
|
455
459
|
|
|
456
460
|
---
|
|
457
461
|
|
|
@@ -472,12 +476,10 @@ Before deployment:
|
|
|
472
476
|
|
|
473
477
|
## Related Skills
|
|
474
478
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
| Real-time patterns | `realtime-patterns` |
|
|
480
|
-
| Performance profiling | `performance-profiling` |
|
|
479
|
+
- Message queues: `queue-patterns`
|
|
480
|
+
- Database caching: `database-design`
|
|
481
|
+
- Real-time patterns: `realtime-patterns`
|
|
482
|
+
- Performance profiling: `performance-profiling`
|
|
481
483
|
|
|
482
484
|
---
|
|
483
485
|
|
|
@@ -6,7 +6,16 @@ allowed-tools: Read, Edit, Glob, Grep
|
|
|
6
6
|
|
|
7
7
|
# Security Fundamentals - Thinking Like an Attacker
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## ⚡ Quick Reference
|
|
10
|
+
|
|
11
|
+
- **Zero Trust**: Validate all inputs · No trust by location · Fail secure (deny on error)
|
|
12
|
+
- **OWASP Top 10**: Access Control · Security Misconfig · Supply Chain · Crypto Failures · Injection · Auth Failures
|
|
13
|
+
- **Input**: Validate type+length+format · Parameterized queries (no string concat) · Sanitize HTML output
|
|
14
|
+
- **Auth**: bcrypt/Argon2 for passwords · JWT 15min expiry · httpOnly cookies for refresh · Rate limit login
|
|
15
|
+
- **Secrets**: Never in code/logs · `.env` for local · Vault/SecretsManager for prod · Rotate regularly
|
|
16
|
+
- **HTTPS**: TLS 1.2+ only · HSTS header · CSP header · No mixed content
|
|
17
|
+
|
|
18
|
+
---
|
|
10
19
|
|
|
11
20
|
---
|
|
12
21
|
|
|
@@ -150,18 +159,16 @@ function createUser(input: unknown) {
|
|
|
150
159
|
|
|
151
160
|
### Common Validation Rules
|
|
152
161
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
| Number | Min/max bounds, integer vs float |
|
|
164
|
-
| Free text | Max length, no control chars |
|
|
162
|
+
- Username: ^[a-zA-Z0-9_]{3,20}$
|
|
163
|
+
- Email: RFC 5322 regex + domain check
|
|
164
|
+
- Password: Min 12 chars, complexity rules
|
|
165
|
+
- Phone: Digits only, length 10-15
|
|
166
|
+
- UUID: ^[0-9a-f]{8}-... pattern
|
|
167
|
+
- URL: Scheme allowlist (https), domain allowlist
|
|
168
|
+
- File: Extension allowlist, magic bytes, max size
|
|
169
|
+
- Date: ISO 8601, reasonable range
|
|
170
|
+
- Number: Min/max bounds, integer vs float
|
|
171
|
+
- Free text: Max length, no control chars
|
|
165
172
|
|
|
166
173
|
---
|
|
167
174
|
|
|
@@ -199,14 +206,12 @@ const cleanHTML = DOMPurify.sanitize(dirtyHTML, {
|
|
|
199
206
|
|
|
200
207
|
### Output Encoding
|
|
201
208
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
| URL parameter | URL encode (`%20`) |
|
|
209
|
-
| JSON | JSON.stringify (auto-escapes) |
|
|
209
|
+
- HTML body: HTML entity encode (`<` → `<`)
|
|
210
|
+
- HTML attribute: Attribute encode + quote
|
|
211
|
+
- JavaScript string: JS escape + avoid eval
|
|
212
|
+
- CSS value: CSS escape, avoid `url()`
|
|
213
|
+
- URL parameter: URL encode (`%20`)
|
|
214
|
+
- JSON: JSON.stringify (auto-escapes)
|
|
210
215
|
|
|
211
216
|
---
|
|
212
217
|
|
|
@@ -223,13 +228,11 @@ Cost factor: ~100ms per hash (adjust for hardware)
|
|
|
223
228
|
|
|
224
229
|
### Session Security
|
|
225
230
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
| Expiration | Reasonable timeout, absolute + idle |
|
|
232
|
-
| Rotation | New ID after privilege change |
|
|
231
|
+
- Session ID: Cryptographically random, 128+ bits
|
|
232
|
+
- Storage: HttpOnly cookie (not localStorage)
|
|
233
|
+
- Transmission: Secure flag (HTTPS only)
|
|
234
|
+
- Expiration: Reasonable timeout, absolute + idle
|
|
235
|
+
- Rotation: New ID after privilege change
|
|
233
236
|
|
|
234
237
|
### JWT Security
|
|
235
238
|
|
|
@@ -292,18 +295,16 @@ const securityHeaders = {
|
|
|
292
295
|
|
|
293
296
|
## 🚨 Anti-Patterns
|
|
294
297
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
| Disable security features "temporarily" | Never—find proper solution |
|
|
306
|
-
| Roll your own crypto | Use established libraries |
|
|
298
|
+
- Store passwords in plain text: Use bcrypt/Argon2 with proper cost
|
|
299
|
+
- Concatenate SQL strings: Use parameterized queries
|
|
300
|
+
- Disable SSL verification: Fix certificate issues properly
|
|
301
|
+
- Log sensitive data: Mask/redact before logging
|
|
302
|
+
- Use `eval()` with user input: Find alternative approach
|
|
303
|
+
- Trust client-side validation: Always validate server-side
|
|
304
|
+
- Commit secrets to repo: Use environment variables
|
|
305
|
+
- Use `*` for CORS origin: Explicit domain allowlist
|
|
306
|
+
- Disable security features "temporarily": Never—find proper solution
|
|
307
|
+
- Roll your own crypto: Use established libraries
|
|
307
308
|
|
|
308
309
|
---
|
|
309
310
|
|
|
@@ -343,12 +344,10 @@ const securityHeaders = {
|
|
|
343
344
|
|
|
344
345
|
## 🔗 Related Skills
|
|
345
346
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
| Testing for security | `testing-patterns` |
|
|
351
|
-
| Clean code principles | `clean-code` |
|
|
347
|
+
- API design patterns: `api-patterns`
|
|
348
|
+
- Database security: `database-design`
|
|
349
|
+
- Testing for security: `testing-patterns`
|
|
350
|
+
- Clean code principles: `clean-code`
|
|
352
351
|
|
|
353
352
|
---
|
|
354
353
|
|