@h1dr0n/skill-pool 0.1.0
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/LICENSE +21 -0
- package/README.md +296 -0
- package/bin/cli.js +157 -0
- package/package.json +41 -0
- package/skills/api/agents/backend-specialist.md +69 -0
- package/skills/api/agents/database-optimizer.md +176 -0
- package/skills/api/manifest.yaml +20 -0
- package/skills/api/rules/auth-security.md +45 -0
- package/skills/api/skills/api-patterns/SKILL.md +81 -0
- package/skills/api/skills/api-patterns/api-style.md +42 -0
- package/skills/api/skills/api-patterns/auth.md +24 -0
- package/skills/api/skills/api-patterns/documentation.md +26 -0
- package/skills/api/skills/api-patterns/graphql.md +41 -0
- package/skills/api/skills/api-patterns/rate-limiting.md +31 -0
- package/skills/api/skills/api-patterns/response.md +37 -0
- package/skills/api/skills/api-patterns/rest.md +40 -0
- package/skills/api/skills/api-patterns/scripts/api_validator.py +211 -0
- package/skills/api/skills/api-patterns/security-testing.md +122 -0
- package/skills/api/skills/api-patterns/trpc.md +41 -0
- package/skills/api/skills/api-patterns/versioning.md +22 -0
- package/skills/api/skills/database-patterns.md +126 -0
- package/skills/api/skills/deployment-patterns.md +105 -0
- package/skills/api/skills/docker-patterns.md +135 -0
- package/skills/common/agents/code-reviewer.md +78 -0
- package/skills/common/agents/planner.md +80 -0
- package/skills/common/agents/security-reviewer.md +82 -0
- package/skills/common/agents/software-architect.md +81 -0
- package/skills/common/manifest.yaml +25 -0
- package/skills/common/rules/coding-style.md +39 -0
- package/skills/common/rules/git-workflow.md +33 -0
- package/skills/common/rules/security.md +25 -0
- package/skills/common/skills/architecture/SKILL.md +55 -0
- package/skills/common/skills/architecture/context-discovery.md +43 -0
- package/skills/common/skills/architecture/examples.md +94 -0
- package/skills/common/skills/architecture/pattern-selection.md +68 -0
- package/skills/common/skills/architecture/patterns-reference.md +50 -0
- package/skills/common/skills/architecture/trade-off-analysis.md +77 -0
- package/skills/common/skills/brainstorming/SKILL.md +163 -0
- package/skills/common/skills/brainstorming/dynamic-questioning.md +350 -0
- package/skills/common/skills/clean-code.md +99 -0
- package/skills/common/skills/code-review-checklist.md +86 -0
- package/skills/common/skills/plan-writing/SKILL.md +152 -0
- package/skills/common/skills/skill-feedback.md +94 -0
- package/skills/common/skills/tdd-workflow.md +130 -0
- package/skills/common/skills/verification-loop.md +112 -0
- package/skills/cpp/agents/cpp-build-resolver.md +90 -0
- package/skills/cpp/agents/cpp-reviewer.md +72 -0
- package/skills/cpp/manifest.yaml +15 -0
- package/skills/cpp/skills/cpp-coding-standards.md +722 -0
- package/skills/cpp/skills/cpp-testing.md +323 -0
- package/skills/devops/agents/devops-automator.md +376 -0
- package/skills/devops/agents/sre.md +90 -0
- package/skills/devops/manifest.yaml +20 -0
- package/skills/devops/skills/deployment-patterns.md +427 -0
- package/skills/devops/skills/deployment-procedures/SKILL.md +241 -0
- package/skills/devops/skills/docker-patterns.md +364 -0
- package/skills/devops/skills/e2e-testing.md +326 -0
- package/skills/devops/skills/github-ops.md +144 -0
- package/skills/django/manifest.yaml +16 -0
- package/skills/django/skills/django-patterns.md +734 -0
- package/skills/django/skills/django-security.md +593 -0
- package/skills/django/skills/django-tdd.md +729 -0
- package/skills/django/skills/django-verification.md +469 -0
- package/skills/dotnet/agents/csharp-reviewer.md +101 -0
- package/skills/dotnet/manifest.yaml +14 -0
- package/skills/dotnet/skills/csharp-testing.md +321 -0
- package/skills/dotnet/skills/dotnet-patterns.md +321 -0
- package/skills/go/agents/code-reviewer.md +76 -0
- package/skills/go/agents/go-build-resolver.md +94 -0
- package/skills/go/agents/go-reviewer.md +76 -0
- package/skills/go/manifest.yaml +17 -0
- package/skills/go/rules/go-style.md +55 -0
- package/skills/go/skills/golang-patterns.md +674 -0
- package/skills/go/skills/golang-testing.md +720 -0
- package/skills/java/agents/java-build-resolver.md +153 -0
- package/skills/java/agents/java-reviewer.md +92 -0
- package/skills/java/manifest.yaml +18 -0
- package/skills/java/skills/java-coding-standards.md +147 -0
- package/skills/java/skills/jpa-patterns.md +151 -0
- package/skills/java/skills/springboot-patterns.md +314 -0
- package/skills/java/skills/springboot-security.md +272 -0
- package/skills/kotlin/agents/kotlin-build-resolver.md +118 -0
- package/skills/kotlin/agents/kotlin-reviewer.md +159 -0
- package/skills/kotlin/manifest.yaml +17 -0
- package/skills/kotlin/skills/kotlin-coroutines-flows.md +284 -0
- package/skills/kotlin/skills/kotlin-patterns.md +711 -0
- package/skills/kotlin/skills/kotlin-testing.md +824 -0
- package/skills/laravel/manifest.yaml +15 -0
- package/skills/laravel/skills/laravel-patterns.md +409 -0
- package/skills/laravel/skills/laravel-security.md +279 -0
- package/skills/laravel/skills/laravel-tdd.md +277 -0
- package/skills/laravel/skills/laravel-verification.md +173 -0
- package/skills/mobile/agents/dart-build-resolver.md +201 -0
- package/skills/mobile/agents/flutter-reviewer.md +243 -0
- package/skills/mobile/manifest.yaml +19 -0
- package/skills/mobile/skills/android-clean-architecture.md +339 -0
- package/skills/mobile/skills/dart-flutter-patterns.md +563 -0
- package/skills/mobile/skills/swiftui-patterns.md +259 -0
- package/skills/nestjs/manifest.yaml +13 -0
- package/skills/nestjs/skills/nestjs-patterns.md +230 -0
- package/skills/perl/manifest.yaml +13 -0
- package/skills/perl/skills/perl-patterns.md +504 -0
- package/skills/perl/skills/perl-security.md +503 -0
- package/skills/perl/skills/perl-testing.md +475 -0
- package/skills/python/agents/python-reviewer.md +98 -0
- package/skills/python/manifest.yaml +18 -0
- package/skills/python/rules/python-style.md +69 -0
- package/skills/python/skills/python-patterns/SKILL.md +441 -0
- package/skills/python/skills/python-patterns.md +90 -0
- package/skills/python/skills/python-testing.md +81 -0
- package/skills/rust/agents/rust-build-resolver.md +148 -0
- package/skills/rust/agents/rust-reviewer.md +94 -0
- package/skills/rust/manifest.yaml +16 -0
- package/skills/rust/rules/rust-style.md +107 -0
- package/skills/rust/skills/rust-patterns.md +499 -0
- package/skills/rust/skills/rust-testing.md +500 -0
- package/skills/security/agents/accessibility-auditor.md +316 -0
- package/skills/security/agents/security-reviewer.md +108 -0
- package/skills/security/manifest.yaml +19 -0
- package/skills/security/skills/red-team-tactics/SKILL.md +199 -0
- package/skills/security/skills/security-bounty-hunter.md +99 -0
- package/skills/security/skills/security-review.md +495 -0
- package/skills/security/skills/security-scan.md +165 -0
- package/skills/security/skills/vulnerability-scanner/SKILL.md +276 -0
- package/skills/security/skills/vulnerability-scanner/checklists.md +121 -0
- package/skills/security/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/skills/swift/manifest.yaml +16 -0
- package/skills/swift/skills/swift-actor-persistence.md +142 -0
- package/skills/swift/skills/swift-concurrency.md +216 -0
- package/skills/swift/skills/swift-protocol-di-testing.md +190 -0
- package/skills/swift/skills/swiftui-patterns.md +259 -0
- package/skills/unity/agents/game-designer.md +167 -0
- package/skills/unity/agents/unity-architect.md +52 -0
- package/skills/unity/agents/unity-editor-tool-developer.md +310 -0
- package/skills/unity/agents/unity-multiplayer-engineer.md +321 -0
- package/skills/unity/agents/unity-shader-graph-artist.md +269 -0
- package/skills/unity/manifest.yaml +21 -0
- package/skills/unity/rules/csharp-patterns.md +48 -0
- package/skills/unity/rules/unity-specific.md +53 -0
- package/skills/unity/skills/systematic-debugging.md +92 -0
- package/skills/unity/skills/unity-architecture.md +173 -0
- package/skills/unreal/agents/level-designer.md +208 -0
- package/skills/unreal/agents/technical-artist.md +229 -0
- package/skills/unreal/agents/unreal-multiplayer-architect.md +313 -0
- package/skills/unreal/agents/unreal-systems-engineer.md +310 -0
- package/skills/unreal/agents/unreal-technical-artist.md +256 -0
- package/skills/unreal/agents/unreal-world-builder.md +273 -0
- package/skills/unreal/manifest.yaml +21 -0
- package/skills/unreal/skills/unreal-patterns.md +183 -0
- package/skills/web/agents/frontend-specialist.md +71 -0
- package/skills/web/agents/ui-designer.md +383 -0
- package/skills/web/agents/ux-architect.md +469 -0
- package/skills/web/manifest.yaml +22 -0
- package/skills/web/rules/accessibility.md +54 -0
- package/skills/web/rules/css-performance.md +52 -0
- package/skills/web/skills/e2e-testing.md +132 -0
- package/skills/web/skills/frontend-design/SKILL.md +452 -0
- package/skills/web/skills/frontend-design/animation-guide.md +331 -0
- package/skills/web/skills/frontend-design/color-system.md +311 -0
- package/skills/web/skills/frontend-design/decision-trees.md +418 -0
- package/skills/web/skills/frontend-design/motion-graphics.md +306 -0
- package/skills/web/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/skills/web/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/skills/web/skills/frontend-design/typography-system.md +345 -0
- package/skills/web/skills/frontend-design/ux-psychology.md +1116 -0
- package/skills/web/skills/frontend-design/visual-effects.md +383 -0
- package/skills/web/skills/react-nextjs.md +135 -0
- package/skills/web/skills/tailwind-patterns/SKILL.md +269 -0
- package/src/adapters/antigravity.js +164 -0
- package/src/adapters/claude.js +188 -0
- package/src/adapters/cursor.js +161 -0
- package/src/adapters/index.js +67 -0
- package/src/adapters/windsurf.js +158 -0
- package/src/commands/add.js +266 -0
- package/src/commands/create.js +127 -0
- package/src/commands/diff.js +78 -0
- package/src/commands/info.js +88 -0
- package/src/commands/init.js +224 -0
- package/src/commands/install.js +90 -0
- package/src/commands/list.js +54 -0
- package/src/commands/remove.js +101 -0
- package/src/commands/targets.js +32 -0
- package/src/commands/update.js +57 -0
- package/src/core/manifest.js +57 -0
- package/src/core/plugins.js +86 -0
- package/src/core/resolver.js +84 -0
- package/src/core/tracker.js +49 -0
- package/src/utils/fs.js +80 -0
- package/src/utils/git.js +52 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: security-bounty-hunter
|
|
3
|
+
description: Hunt for exploitable, bounty-worthy security issues in repositories. Focuses on remotely reachable vulnerabilities that qualify for real reports instead of noisy local-only findings.
|
|
4
|
+
origin: ECC direct-port adaptation
|
|
5
|
+
version: "1.0.0"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Security Bounty Hunter
|
|
9
|
+
|
|
10
|
+
Use this when the goal is practical vulnerability discovery for responsible disclosure or bounty submission, not a broad best-practices review.
|
|
11
|
+
|
|
12
|
+
## When to Use
|
|
13
|
+
|
|
14
|
+
- Scanning a repository for exploitable vulnerabilities
|
|
15
|
+
- Preparing a Huntr, HackerOne, or similar bounty submission
|
|
16
|
+
- Triage where the question is "does this actually pay?" rather than "is this theoretically unsafe?"
|
|
17
|
+
|
|
18
|
+
## How It Works
|
|
19
|
+
|
|
20
|
+
Bias toward remotely reachable, user-controlled attack paths and throw away patterns that platforms routinely reject as informative or out of scope.
|
|
21
|
+
|
|
22
|
+
## In-Scope Patterns
|
|
23
|
+
|
|
24
|
+
These are the kinds of issues that consistently matter:
|
|
25
|
+
|
|
26
|
+
| Pattern | CWE | Typical impact |
|
|
27
|
+
| --- | --- | --- |
|
|
28
|
+
| SSRF through user-controlled URLs | CWE-918 | internal network access, cloud metadata theft |
|
|
29
|
+
| Auth bypass in middleware or API guards | CWE-287 | unauthorized account or data access |
|
|
30
|
+
| Remote deserialization or upload-to-RCE paths | CWE-502 | code execution |
|
|
31
|
+
| SQL injection in reachable endpoints | CWE-89 | data exfiltration, auth bypass, data destruction |
|
|
32
|
+
| Command injection in request handlers | CWE-78 | code execution |
|
|
33
|
+
| Path traversal in file-serving paths | CWE-22 | arbitrary file read or write |
|
|
34
|
+
| Auto-triggered XSS | CWE-79 | session theft, admin compromise |
|
|
35
|
+
|
|
36
|
+
## Skip These
|
|
37
|
+
|
|
38
|
+
These are usually low-signal or out of bounty scope unless the program says otherwise:
|
|
39
|
+
|
|
40
|
+
- Local-only `pickle.loads`, `torch.load`, or equivalent with no remote path
|
|
41
|
+
- `eval()` or `exec()` in CLI-only tooling
|
|
42
|
+
- `shell=True` on fully hardcoded commands
|
|
43
|
+
- Missing security headers by themselves
|
|
44
|
+
- Generic rate-limiting complaints without exploit impact
|
|
45
|
+
- Self-XSS requiring the victim to paste code manually
|
|
46
|
+
- CI/CD injection that is not part of the target program scope
|
|
47
|
+
- Demo, example, or test-only code
|
|
48
|
+
|
|
49
|
+
## Workflow
|
|
50
|
+
|
|
51
|
+
1. Check scope first: program rules, SECURITY.md, disclosure channel, and exclusions.
|
|
52
|
+
2. Find real entrypoints: HTTP handlers, uploads, background jobs, webhooks, parsers, and integration endpoints.
|
|
53
|
+
3. Run static tooling where it helps, but treat it as triage input only.
|
|
54
|
+
4. Read the real code path end to end.
|
|
55
|
+
5. Prove user control reaches a meaningful sink.
|
|
56
|
+
6. Confirm exploitability and impact with the smallest safe PoC possible.
|
|
57
|
+
7. Check for duplicates before drafting a report.
|
|
58
|
+
|
|
59
|
+
## Example Triage Loop
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
semgrep --config=auto --severity=ERROR --severity=WARNING --json
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Then manually filter:
|
|
66
|
+
|
|
67
|
+
- drop tests, demos, fixtures, vendored code
|
|
68
|
+
- drop local-only or non-reachable paths
|
|
69
|
+
- keep only findings with a clear network or user-controlled route
|
|
70
|
+
|
|
71
|
+
## Report Structure
|
|
72
|
+
|
|
73
|
+
```markdown
|
|
74
|
+
## Description
|
|
75
|
+
[What the vulnerability is and why it matters]
|
|
76
|
+
|
|
77
|
+
## Vulnerable Code
|
|
78
|
+
[File path, line range, and a small snippet]
|
|
79
|
+
|
|
80
|
+
## Proof of Concept
|
|
81
|
+
[Minimal working request or script]
|
|
82
|
+
|
|
83
|
+
## Impact
|
|
84
|
+
[What the attacker can achieve]
|
|
85
|
+
|
|
86
|
+
## Affected Version
|
|
87
|
+
[Version, commit, or deployment target tested]
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Quality Gate
|
|
91
|
+
|
|
92
|
+
Before submitting:
|
|
93
|
+
|
|
94
|
+
- The code path is reachable from a real user or network boundary
|
|
95
|
+
- The input is genuinely user-controlled
|
|
96
|
+
- The sink is meaningful and exploitable
|
|
97
|
+
- The PoC works
|
|
98
|
+
- The issue is not already covered by an advisory, CVE, or open ticket
|
|
99
|
+
- The target is actually in scope for the bounty program
|
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: security-review
|
|
3
|
+
description: Use this skill when adding authentication, handling user input, working with secrets, creating API endpoints, or implementing payment/sensitive features. Provides comprehensive security checklist and patterns.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Security Review Skill
|
|
8
|
+
|
|
9
|
+
This skill ensures all code follows security best practices and identifies potential vulnerabilities.
|
|
10
|
+
|
|
11
|
+
## When to Activate
|
|
12
|
+
|
|
13
|
+
- Implementing authentication or authorization
|
|
14
|
+
- Handling user input or file uploads
|
|
15
|
+
- Creating new API endpoints
|
|
16
|
+
- Working with secrets or credentials
|
|
17
|
+
- Implementing payment features
|
|
18
|
+
- Storing or transmitting sensitive data
|
|
19
|
+
- Integrating third-party APIs
|
|
20
|
+
|
|
21
|
+
## Security Checklist
|
|
22
|
+
|
|
23
|
+
### 1. Secrets Management
|
|
24
|
+
|
|
25
|
+
#### FAIL: NEVER Do This
|
|
26
|
+
```typescript
|
|
27
|
+
const apiKey = "sk-proj-xxxxx" // Hardcoded secret
|
|
28
|
+
const dbPassword = "password123" // In source code
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
#### PASS: ALWAYS Do This
|
|
32
|
+
```typescript
|
|
33
|
+
const apiKey = process.env.OPENAI_API_KEY
|
|
34
|
+
const dbUrl = process.env.DATABASE_URL
|
|
35
|
+
|
|
36
|
+
// Verify secrets exist
|
|
37
|
+
if (!apiKey) {
|
|
38
|
+
throw new Error('OPENAI_API_KEY not configured')
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### Verification Steps
|
|
43
|
+
- [ ] No hardcoded API keys, tokens, or passwords
|
|
44
|
+
- [ ] All secrets in environment variables
|
|
45
|
+
- [ ] `.env.local` in .gitignore
|
|
46
|
+
- [ ] No secrets in git history
|
|
47
|
+
- [ ] Production secrets in hosting platform (Vercel, Railway)
|
|
48
|
+
|
|
49
|
+
### 2. Input Validation
|
|
50
|
+
|
|
51
|
+
#### Always Validate User Input
|
|
52
|
+
```typescript
|
|
53
|
+
import { z } from 'zod'
|
|
54
|
+
|
|
55
|
+
// Define validation schema
|
|
56
|
+
const CreateUserSchema = z.object({
|
|
57
|
+
email: z.string().email(),
|
|
58
|
+
name: z.string().min(1).max(100),
|
|
59
|
+
age: z.number().int().min(0).max(150)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
// Validate before processing
|
|
63
|
+
export async function createUser(input: unknown) {
|
|
64
|
+
try {
|
|
65
|
+
const validated = CreateUserSchema.parse(input)
|
|
66
|
+
return await db.users.create(validated)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (error instanceof z.ZodError) {
|
|
69
|
+
return { success: false, errors: error.errors }
|
|
70
|
+
}
|
|
71
|
+
throw error
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### File Upload Validation
|
|
77
|
+
```typescript
|
|
78
|
+
function validateFileUpload(file: File) {
|
|
79
|
+
// Size check (5MB max)
|
|
80
|
+
const maxSize = 5 * 1024 * 1024
|
|
81
|
+
if (file.size > maxSize) {
|
|
82
|
+
throw new Error('File too large (max 5MB)')
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Type check
|
|
86
|
+
const allowedTypes = ['image/jpeg', 'image/png', 'image/gif']
|
|
87
|
+
if (!allowedTypes.includes(file.type)) {
|
|
88
|
+
throw new Error('Invalid file type')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Extension check
|
|
92
|
+
const allowedExtensions = ['.jpg', '.jpeg', '.png', '.gif']
|
|
93
|
+
const extension = file.name.toLowerCase().match(/\.[^.]+$/)?.[0]
|
|
94
|
+
if (!extension || !allowedExtensions.includes(extension)) {
|
|
95
|
+
throw new Error('Invalid file extension')
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Verification Steps
|
|
103
|
+
- [ ] All user inputs validated with schemas
|
|
104
|
+
- [ ] File uploads restricted (size, type, extension)
|
|
105
|
+
- [ ] No direct use of user input in queries
|
|
106
|
+
- [ ] Whitelist validation (not blacklist)
|
|
107
|
+
- [ ] Error messages don't leak sensitive info
|
|
108
|
+
|
|
109
|
+
### 3. SQL Injection Prevention
|
|
110
|
+
|
|
111
|
+
#### FAIL: NEVER Concatenate SQL
|
|
112
|
+
```typescript
|
|
113
|
+
// DANGEROUS - SQL Injection vulnerability
|
|
114
|
+
const query = `SELECT * FROM users WHERE email = '${userEmail}'`
|
|
115
|
+
await db.query(query)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### PASS: ALWAYS Use Parameterized Queries
|
|
119
|
+
```typescript
|
|
120
|
+
// Safe - parameterized query
|
|
121
|
+
const { data } = await supabase
|
|
122
|
+
.from('users')
|
|
123
|
+
.select('*')
|
|
124
|
+
.eq('email', userEmail)
|
|
125
|
+
|
|
126
|
+
// Or with raw SQL
|
|
127
|
+
await db.query(
|
|
128
|
+
'SELECT * FROM users WHERE email = $1',
|
|
129
|
+
[userEmail]
|
|
130
|
+
)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Verification Steps
|
|
134
|
+
- [ ] All database queries use parameterized queries
|
|
135
|
+
- [ ] No string concatenation in SQL
|
|
136
|
+
- [ ] ORM/query builder used correctly
|
|
137
|
+
- [ ] Supabase queries properly sanitized
|
|
138
|
+
|
|
139
|
+
### 4. Authentication & Authorization
|
|
140
|
+
|
|
141
|
+
#### JWT Token Handling
|
|
142
|
+
```typescript
|
|
143
|
+
// FAIL: WRONG: localStorage (vulnerable to XSS)
|
|
144
|
+
localStorage.setItem('token', token)
|
|
145
|
+
|
|
146
|
+
// PASS: CORRECT: httpOnly cookies
|
|
147
|
+
res.setHeader('Set-Cookie',
|
|
148
|
+
`token=${token}; HttpOnly; Secure; SameSite=Strict; Max-Age=3600`)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### Authorization Checks
|
|
152
|
+
```typescript
|
|
153
|
+
export async function deleteUser(userId: string, requesterId: string) {
|
|
154
|
+
// ALWAYS verify authorization first
|
|
155
|
+
const requester = await db.users.findUnique({
|
|
156
|
+
where: { id: requesterId }
|
|
157
|
+
})
|
|
158
|
+
|
|
159
|
+
if (requester.role !== 'admin') {
|
|
160
|
+
return NextResponse.json(
|
|
161
|
+
{ error: 'Unauthorized' },
|
|
162
|
+
{ status: 403 }
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Proceed with deletion
|
|
167
|
+
await db.users.delete({ where: { id: userId } })
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Row Level Security (Supabase)
|
|
172
|
+
```sql
|
|
173
|
+
-- Enable RLS on all tables
|
|
174
|
+
ALTER TABLE users ENABLE ROW LEVEL SECURITY;
|
|
175
|
+
|
|
176
|
+
-- Users can only view their own data
|
|
177
|
+
CREATE POLICY "Users view own data"
|
|
178
|
+
ON users FOR SELECT
|
|
179
|
+
USING (auth.uid() = id);
|
|
180
|
+
|
|
181
|
+
-- Users can only update their own data
|
|
182
|
+
CREATE POLICY "Users update own data"
|
|
183
|
+
ON users FOR UPDATE
|
|
184
|
+
USING (auth.uid() = id);
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Verification Steps
|
|
188
|
+
- [ ] Tokens stored in httpOnly cookies (not localStorage)
|
|
189
|
+
- [ ] Authorization checks before sensitive operations
|
|
190
|
+
- [ ] Row Level Security enabled in Supabase
|
|
191
|
+
- [ ] Role-based access control implemented
|
|
192
|
+
- [ ] Session management secure
|
|
193
|
+
|
|
194
|
+
### 5. XSS Prevention
|
|
195
|
+
|
|
196
|
+
#### Sanitize HTML
|
|
197
|
+
```typescript
|
|
198
|
+
import DOMPurify from 'isomorphic-dompurify'
|
|
199
|
+
|
|
200
|
+
// ALWAYS sanitize user-provided HTML
|
|
201
|
+
function renderUserContent(html: string) {
|
|
202
|
+
const clean = DOMPurify.sanitize(html, {
|
|
203
|
+
ALLOWED_TAGS: ['b', 'i', 'em', 'strong', 'p'],
|
|
204
|
+
ALLOWED_ATTR: []
|
|
205
|
+
})
|
|
206
|
+
return <div dangerouslySetInnerHTML={{ __html: clean }} />
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
#### Content Security Policy
|
|
211
|
+
```typescript
|
|
212
|
+
// next.config.js
|
|
213
|
+
const securityHeaders = [
|
|
214
|
+
{
|
|
215
|
+
key: 'Content-Security-Policy',
|
|
216
|
+
value: `
|
|
217
|
+
default-src 'self';
|
|
218
|
+
script-src 'self' 'unsafe-eval' 'unsafe-inline';
|
|
219
|
+
style-src 'self' 'unsafe-inline';
|
|
220
|
+
img-src 'self' data: https:;
|
|
221
|
+
font-src 'self';
|
|
222
|
+
connect-src 'self' https://api.example.com;
|
|
223
|
+
`.replace(/\s{2,}/g, ' ').trim()
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Verification Steps
|
|
229
|
+
- [ ] User-provided HTML sanitized
|
|
230
|
+
- [ ] CSP headers configured
|
|
231
|
+
- [ ] No unvalidated dynamic content rendering
|
|
232
|
+
- [ ] React's built-in XSS protection used
|
|
233
|
+
|
|
234
|
+
### 6. CSRF Protection
|
|
235
|
+
|
|
236
|
+
#### CSRF Tokens
|
|
237
|
+
```typescript
|
|
238
|
+
import { csrf } from '@/lib/csrf'
|
|
239
|
+
|
|
240
|
+
export async function POST(request: Request) {
|
|
241
|
+
const token = request.headers.get('X-CSRF-Token')
|
|
242
|
+
|
|
243
|
+
if (!csrf.verify(token)) {
|
|
244
|
+
return NextResponse.json(
|
|
245
|
+
{ error: 'Invalid CSRF token' },
|
|
246
|
+
{ status: 403 }
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Process request
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### SameSite Cookies
|
|
255
|
+
```typescript
|
|
256
|
+
res.setHeader('Set-Cookie',
|
|
257
|
+
`session=${sessionId}; HttpOnly; Secure; SameSite=Strict`)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
#### Verification Steps
|
|
261
|
+
- [ ] CSRF tokens on state-changing operations
|
|
262
|
+
- [ ] SameSite=Strict on all cookies
|
|
263
|
+
- [ ] Double-submit cookie pattern implemented
|
|
264
|
+
|
|
265
|
+
### 7. Rate Limiting
|
|
266
|
+
|
|
267
|
+
#### API Rate Limiting
|
|
268
|
+
```typescript
|
|
269
|
+
import rateLimit from 'express-rate-limit'
|
|
270
|
+
|
|
271
|
+
const limiter = rateLimit({
|
|
272
|
+
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
273
|
+
max: 100, // 100 requests per window
|
|
274
|
+
message: 'Too many requests'
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
// Apply to routes
|
|
278
|
+
app.use('/api/', limiter)
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
#### Expensive Operations
|
|
282
|
+
```typescript
|
|
283
|
+
// Aggressive rate limiting for searches
|
|
284
|
+
const searchLimiter = rateLimit({
|
|
285
|
+
windowMs: 60 * 1000, // 1 minute
|
|
286
|
+
max: 10, // 10 requests per minute
|
|
287
|
+
message: 'Too many search requests'
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
app.use('/api/search', searchLimiter)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
#### Verification Steps
|
|
294
|
+
- [ ] Rate limiting on all API endpoints
|
|
295
|
+
- [ ] Stricter limits on expensive operations
|
|
296
|
+
- [ ] IP-based rate limiting
|
|
297
|
+
- [ ] User-based rate limiting (authenticated)
|
|
298
|
+
|
|
299
|
+
### 8. Sensitive Data Exposure
|
|
300
|
+
|
|
301
|
+
#### Logging
|
|
302
|
+
```typescript
|
|
303
|
+
// FAIL: WRONG: Logging sensitive data
|
|
304
|
+
console.log('User login:', { email, password })
|
|
305
|
+
console.log('Payment:', { cardNumber, cvv })
|
|
306
|
+
|
|
307
|
+
// PASS: CORRECT: Redact sensitive data
|
|
308
|
+
console.log('User login:', { email, userId })
|
|
309
|
+
console.log('Payment:', { last4: card.last4, userId })
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
#### Error Messages
|
|
313
|
+
```typescript
|
|
314
|
+
// FAIL: WRONG: Exposing internal details
|
|
315
|
+
catch (error) {
|
|
316
|
+
return NextResponse.json(
|
|
317
|
+
{ error: error.message, stack: error.stack },
|
|
318
|
+
{ status: 500 }
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// PASS: CORRECT: Generic error messages
|
|
323
|
+
catch (error) {
|
|
324
|
+
console.error('Internal error:', error)
|
|
325
|
+
return NextResponse.json(
|
|
326
|
+
{ error: 'An error occurred. Please try again.' },
|
|
327
|
+
{ status: 500 }
|
|
328
|
+
)
|
|
329
|
+
}
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
#### Verification Steps
|
|
333
|
+
- [ ] No passwords, tokens, or secrets in logs
|
|
334
|
+
- [ ] Error messages generic for users
|
|
335
|
+
- [ ] Detailed errors only in server logs
|
|
336
|
+
- [ ] No stack traces exposed to users
|
|
337
|
+
|
|
338
|
+
### 9. Blockchain Security (Solana)
|
|
339
|
+
|
|
340
|
+
#### Wallet Verification
|
|
341
|
+
```typescript
|
|
342
|
+
import { verify } from '@solana/web3.js'
|
|
343
|
+
|
|
344
|
+
async function verifyWalletOwnership(
|
|
345
|
+
publicKey: string,
|
|
346
|
+
signature: string,
|
|
347
|
+
message: string
|
|
348
|
+
) {
|
|
349
|
+
try {
|
|
350
|
+
const isValid = verify(
|
|
351
|
+
Buffer.from(message),
|
|
352
|
+
Buffer.from(signature, 'base64'),
|
|
353
|
+
Buffer.from(publicKey, 'base64')
|
|
354
|
+
)
|
|
355
|
+
return isValid
|
|
356
|
+
} catch (error) {
|
|
357
|
+
return false
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
#### Transaction Verification
|
|
363
|
+
```typescript
|
|
364
|
+
async function verifyTransaction(transaction: Transaction) {
|
|
365
|
+
// Verify recipient
|
|
366
|
+
if (transaction.to !== expectedRecipient) {
|
|
367
|
+
throw new Error('Invalid recipient')
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Verify amount
|
|
371
|
+
if (transaction.amount > maxAmount) {
|
|
372
|
+
throw new Error('Amount exceeds limit')
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Verify user has sufficient balance
|
|
376
|
+
const balance = await getBalance(transaction.from)
|
|
377
|
+
if (balance < transaction.amount) {
|
|
378
|
+
throw new Error('Insufficient balance')
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return true
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### Verification Steps
|
|
386
|
+
- [ ] Wallet signatures verified
|
|
387
|
+
- [ ] Transaction details validated
|
|
388
|
+
- [ ] Balance checks before transactions
|
|
389
|
+
- [ ] No blind transaction signing
|
|
390
|
+
|
|
391
|
+
### 10. Dependency Security
|
|
392
|
+
|
|
393
|
+
#### Regular Updates
|
|
394
|
+
```bash
|
|
395
|
+
# Check for vulnerabilities
|
|
396
|
+
npm audit
|
|
397
|
+
|
|
398
|
+
# Fix automatically fixable issues
|
|
399
|
+
npm audit fix
|
|
400
|
+
|
|
401
|
+
# Update dependencies
|
|
402
|
+
npm update
|
|
403
|
+
|
|
404
|
+
# Check for outdated packages
|
|
405
|
+
npm outdated
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
#### Lock Files
|
|
409
|
+
```bash
|
|
410
|
+
# ALWAYS commit lock files
|
|
411
|
+
git add package-lock.json
|
|
412
|
+
|
|
413
|
+
# Use in CI/CD for reproducible builds
|
|
414
|
+
npm ci # Instead of npm install
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
#### Verification Steps
|
|
418
|
+
- [ ] Dependencies up to date
|
|
419
|
+
- [ ] No known vulnerabilities (npm audit clean)
|
|
420
|
+
- [ ] Lock files committed
|
|
421
|
+
- [ ] Dependabot enabled on GitHub
|
|
422
|
+
- [ ] Regular security updates
|
|
423
|
+
|
|
424
|
+
## Security Testing
|
|
425
|
+
|
|
426
|
+
### Automated Security Tests
|
|
427
|
+
```typescript
|
|
428
|
+
// Test authentication
|
|
429
|
+
test('requires authentication', async () => {
|
|
430
|
+
const response = await fetch('/api/protected')
|
|
431
|
+
expect(response.status).toBe(401)
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
// Test authorization
|
|
435
|
+
test('requires admin role', async () => {
|
|
436
|
+
const response = await fetch('/api/admin', {
|
|
437
|
+
headers: { Authorization: `Bearer ${userToken}` }
|
|
438
|
+
})
|
|
439
|
+
expect(response.status).toBe(403)
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
// Test input validation
|
|
443
|
+
test('rejects invalid input', async () => {
|
|
444
|
+
const response = await fetch('/api/users', {
|
|
445
|
+
method: 'POST',
|
|
446
|
+
body: JSON.stringify({ email: 'not-an-email' })
|
|
447
|
+
})
|
|
448
|
+
expect(response.status).toBe(400)
|
|
449
|
+
})
|
|
450
|
+
|
|
451
|
+
// Test rate limiting
|
|
452
|
+
test('enforces rate limits', async () => {
|
|
453
|
+
const requests = Array(101).fill(null).map(() =>
|
|
454
|
+
fetch('/api/endpoint')
|
|
455
|
+
)
|
|
456
|
+
|
|
457
|
+
const responses = await Promise.all(requests)
|
|
458
|
+
const tooManyRequests = responses.filter(r => r.status === 429)
|
|
459
|
+
|
|
460
|
+
expect(tooManyRequests.length).toBeGreaterThan(0)
|
|
461
|
+
})
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
## Pre-Deployment Security Checklist
|
|
465
|
+
|
|
466
|
+
Before ANY production deployment:
|
|
467
|
+
|
|
468
|
+
- [ ] **Secrets**: No hardcoded secrets, all in env vars
|
|
469
|
+
- [ ] **Input Validation**: All user inputs validated
|
|
470
|
+
- [ ] **SQL Injection**: All queries parameterized
|
|
471
|
+
- [ ] **XSS**: User content sanitized
|
|
472
|
+
- [ ] **CSRF**: Protection enabled
|
|
473
|
+
- [ ] **Authentication**: Proper token handling
|
|
474
|
+
- [ ] **Authorization**: Role checks in place
|
|
475
|
+
- [ ] **Rate Limiting**: Enabled on all endpoints
|
|
476
|
+
- [ ] **HTTPS**: Enforced in production
|
|
477
|
+
- [ ] **Security Headers**: CSP, X-Frame-Options configured
|
|
478
|
+
- [ ] **Error Handling**: No sensitive data in errors
|
|
479
|
+
- [ ] **Logging**: No sensitive data logged
|
|
480
|
+
- [ ] **Dependencies**: Up to date, no vulnerabilities
|
|
481
|
+
- [ ] **Row Level Security**: Enabled in Supabase
|
|
482
|
+
- [ ] **CORS**: Properly configured
|
|
483
|
+
- [ ] **File Uploads**: Validated (size, type)
|
|
484
|
+
- [ ] **Wallet Signatures**: Verified (if blockchain)
|
|
485
|
+
|
|
486
|
+
## Resources
|
|
487
|
+
|
|
488
|
+
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)
|
|
489
|
+
- [Next.js Security](https://nextjs.org/docs/security)
|
|
490
|
+
- [Supabase Security](https://supabase.com/docs/guides/auth)
|
|
491
|
+
- [Web Security Academy](https://portswigger.net/web-security)
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
**Remember**: Security is not optional. One vulnerability can compromise the entire platform. When in doubt, err on the side of caution.
|