openhermes 1.2.2
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/README.md +281 -0
- package/autorecall.mjs +167 -0
- package/bootstrap.mjs +255 -0
- package/curator.mjs +470 -0
- package/harness/commands/build-fix.md +60 -0
- package/harness/commands/code-review.md +71 -0
- package/harness/commands/doctor.md +42 -0
- package/harness/commands/learn.md +37 -0
- package/harness/commands/memory-search.md +37 -0
- package/harness/commands/plan.md +53 -0
- package/harness/commands/security.md +93 -0
- package/harness/constitution/soul.md +76 -0
- package/harness/instructions/RUNTIME.md +21 -0
- package/harness/prompts/architect.txt +175 -0
- package/harness/prompts/build-error-resolver.md +37 -0
- package/harness/prompts/code-reviewer.md +33 -0
- package/harness/prompts/e2e-runner.txt +305 -0
- package/harness/prompts/explore.md +29 -0
- package/harness/prompts/planner.md +30 -0
- package/harness/prompts/security-reviewer.md +35 -0
- package/harness/rules/audit.md +84 -0
- package/harness/rules/checkpointing.md +75 -0
- package/harness/rules/context-loading.md +33 -0
- package/harness/rules/credential-exposure.md +0 -0
- package/harness/rules/delegation.md +76 -0
- package/harness/rules/memory-management.md +28 -0
- package/harness/rules/precedence.md +52 -0
- package/harness/rules/promotion.md +46 -0
- package/harness/rules/ranking.md +64 -0
- package/harness/rules/retrieval.md +94 -0
- package/harness/rules/runtime-guards.md +196 -0
- package/harness/rules/self-heal.md +79 -0
- package/harness/rules/session-start.md +34 -0
- package/harness/rules/skills-management.md +165 -0
- package/harness/rules/state-drift.md +192 -0
- package/harness/rules/verification.md +88 -0
- package/harness/skills/.bundled_manifest +17 -0
- package/harness/skills/.usage.json +6 -0
- package/harness/skills/api-design/SKILL.md +523 -0
- package/harness/skills/backend-patterns/SKILL.md +598 -0
- package/harness/skills/coding-standards/SKILL.md +549 -0
- package/harness/skills/e2e-testing/SKILL.md +326 -0
- package/harness/skills/frontend-patterns/SKILL.md +642 -0
- package/harness/skills/frontend-slides/SKILL.md +184 -0
- package/harness/skills/security-review/SKILL.md +495 -0
- package/harness/skills/strategic-compact/SKILL.md +131 -0
- package/harness/skills/tdd-workflow/SKILL.md +463 -0
- package/harness/skills/verification-loop/SKILL.md +126 -0
- package/index.mjs +5 -0
- package/lib/hardening.mjs +113 -0
- package/lib/memory-tools-plugin.mjs +265 -0
- package/lib/schema-validator.mjs +77 -0
- package/lib/tools/_memory.mjs +230 -0
- package/lib/tools/hm_get.mjs +13 -0
- package/lib/tools/hm_latest.mjs +12 -0
- package/lib/tools/hm_list.mjs +13 -0
- package/lib/tools/hm_put.mjs +14 -0
- package/lib/tools/hm_search.mjs +16 -0
- package/package.json +49 -0
- package/schemas/audit.schema.json +61 -0
- package/schemas/backlog.schema.json +42 -0
- package/schemas/checkpoint.schema.json +44 -0
- package/schemas/constraint.schema.json +41 -0
- package/schemas/decision.schema.json +42 -0
- package/schemas/instinct.schema.json +42 -0
- package/schemas/loop-state.schema.json +33 -0
- package/schemas/mistake.schema.json +43 -0
- package/schemas/verification_receipt.schema.json +67 -0
- package/skill-builder.mjs +113 -0
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: frontend-slides
|
|
3
|
+
description: Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.
|
|
4
|
+
origin: ECC
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Frontend Slides
|
|
8
|
+
|
|
9
|
+
Create zero-dependency, animation-rich HTML presentations that run entirely in the browser.
|
|
10
|
+
|
|
11
|
+
Inspired by the visual exploration approach showcased in work by zarazhangrui (credit: @zarazhangrui).
|
|
12
|
+
|
|
13
|
+
## When to Activate
|
|
14
|
+
|
|
15
|
+
- Creating a talk deck, pitch deck, workshop deck, or internal presentation
|
|
16
|
+
- Converting `.ppt` or `.pptx` slides into an HTML presentation
|
|
17
|
+
- Improving an existing HTML presentation's layout, motion, or typography
|
|
18
|
+
- Exploring presentation styles with a user who does not know their design preference yet
|
|
19
|
+
|
|
20
|
+
## Non-Negotiables
|
|
21
|
+
|
|
22
|
+
1. **Zero dependencies**: default to one self-contained HTML file with inline CSS and JS.
|
|
23
|
+
2. **Viewport fit is mandatory**: every slide must fit inside one viewport with no internal scrolling.
|
|
24
|
+
3. **Show, don't tell**: use visual previews instead of abstract style questionnaires.
|
|
25
|
+
4. **Distinctive design**: avoid generic purple-gradient, Inter-on-white, template-looking decks.
|
|
26
|
+
5. **Production quality**: keep code commented, accessible, responsive, and performant.
|
|
27
|
+
|
|
28
|
+
Before generating, read `STYLE_PRESETS.md` for the viewport-safe CSS base, density limits, preset catalog, and CSS gotchas.
|
|
29
|
+
|
|
30
|
+
## Workflow
|
|
31
|
+
|
|
32
|
+
### 1. Detect Mode
|
|
33
|
+
|
|
34
|
+
Choose one path:
|
|
35
|
+
- **New presentation**: user has a topic, notes, or full draft
|
|
36
|
+
- **PPT conversion**: user has `.ppt` or `.pptx`
|
|
37
|
+
- **Enhancement**: user already has HTML slides and wants improvements
|
|
38
|
+
|
|
39
|
+
### 2. Discover Content
|
|
40
|
+
|
|
41
|
+
Ask only the minimum needed:
|
|
42
|
+
- purpose: pitch, teaching, conference talk, internal update
|
|
43
|
+
- length: short (5-10), medium (10-20), long (20+)
|
|
44
|
+
- content state: finished copy, rough notes, topic only
|
|
45
|
+
|
|
46
|
+
If the user has content, ask them to paste it before styling.
|
|
47
|
+
|
|
48
|
+
### 3. Discover Style
|
|
49
|
+
|
|
50
|
+
Default to visual exploration.
|
|
51
|
+
|
|
52
|
+
If the user already knows the desired preset, skip previews and use it directly.
|
|
53
|
+
|
|
54
|
+
Otherwise:
|
|
55
|
+
1. Ask what feeling the deck should create: impressed, energized, focused, inspired.
|
|
56
|
+
2. Generate **3 single-slide preview files** in `.ecc-design/slide-previews/`.
|
|
57
|
+
3. Each preview must be self-contained, show typography/color/motion clearly, and stay under roughly 100 lines of slide content.
|
|
58
|
+
4. Ask the user which preview to keep or what elements to mix.
|
|
59
|
+
|
|
60
|
+
Use the preset guide in `STYLE_PRESETS.md` when mapping mood to style.
|
|
61
|
+
|
|
62
|
+
### 4. Build the Presentation
|
|
63
|
+
|
|
64
|
+
Output either:
|
|
65
|
+
- `presentation.html`
|
|
66
|
+
- `[presentation-name].html`
|
|
67
|
+
|
|
68
|
+
Use an `assets/` folder only when the deck contains extracted or user-supplied images.
|
|
69
|
+
|
|
70
|
+
Required structure:
|
|
71
|
+
- semantic slide sections
|
|
72
|
+
- a viewport-safe CSS base from `STYLE_PRESETS.md`
|
|
73
|
+
- CSS custom properties for theme values
|
|
74
|
+
- a presentation controller class for keyboard, wheel, and touch navigation
|
|
75
|
+
- Intersection Observer for reveal animations
|
|
76
|
+
- reduced-motion support
|
|
77
|
+
|
|
78
|
+
### 5. Enforce Viewport Fit
|
|
79
|
+
|
|
80
|
+
Treat this as a hard gate.
|
|
81
|
+
|
|
82
|
+
Rules:
|
|
83
|
+
- every `.slide` must use `height: 100vh; height: 100dvh; overflow: hidden;`
|
|
84
|
+
- all type and spacing must scale with `clamp()`
|
|
85
|
+
- when content does not fit, split into multiple slides
|
|
86
|
+
- never solve overflow by shrinking text below readable sizes
|
|
87
|
+
- never allow scrollbars inside a slide
|
|
88
|
+
|
|
89
|
+
Use the density limits and mandatory CSS block in `STYLE_PRESETS.md`.
|
|
90
|
+
|
|
91
|
+
### 6. Validate
|
|
92
|
+
|
|
93
|
+
Check the finished deck at these sizes:
|
|
94
|
+
- 1920x1080
|
|
95
|
+
- 1280x720
|
|
96
|
+
- 768x1024
|
|
97
|
+
- 375x667
|
|
98
|
+
- 667x375
|
|
99
|
+
|
|
100
|
+
If browser automation is available, use it to verify no slide overflows and that keyboard navigation works.
|
|
101
|
+
|
|
102
|
+
### 7. Deliver
|
|
103
|
+
|
|
104
|
+
At handoff:
|
|
105
|
+
- delete temporary preview files unless the user wants to keep them
|
|
106
|
+
- open the deck with the platform-appropriate opener when useful
|
|
107
|
+
- summarize file path, preset used, slide count, and easy theme customization points
|
|
108
|
+
|
|
109
|
+
Use the correct opener for the current OS:
|
|
110
|
+
- macOS: `open file.html`
|
|
111
|
+
- Linux: `xdg-open file.html`
|
|
112
|
+
- Windows: `start "" file.html`
|
|
113
|
+
|
|
114
|
+
## PPT / PPTX Conversion
|
|
115
|
+
|
|
116
|
+
For PowerPoint conversion:
|
|
117
|
+
1. Prefer `python3` with `python-pptx` to extract text, images, and notes.
|
|
118
|
+
2. If `python-pptx` is unavailable, ask whether to install it or fall back to a manual/export-based workflow.
|
|
119
|
+
3. Preserve slide order, speaker notes, and extracted assets.
|
|
120
|
+
4. After extraction, run the same style-selection workflow as a new presentation.
|
|
121
|
+
|
|
122
|
+
Keep conversion cross-platform. Do not rely on macOS-only tools when Python can do the job.
|
|
123
|
+
|
|
124
|
+
## Implementation Requirements
|
|
125
|
+
|
|
126
|
+
### HTML / CSS
|
|
127
|
+
|
|
128
|
+
- Use inline CSS and JS unless the user explicitly wants a multi-file project.
|
|
129
|
+
- Fonts may come from Google Fonts or Fontshare.
|
|
130
|
+
- Prefer atmospheric backgrounds, strong type hierarchy, and a clear visual direction.
|
|
131
|
+
- Use abstract shapes, gradients, grids, noise, and geometry rather than illustrations.
|
|
132
|
+
|
|
133
|
+
### JavaScript
|
|
134
|
+
|
|
135
|
+
Include:
|
|
136
|
+
- keyboard navigation
|
|
137
|
+
- touch / swipe navigation
|
|
138
|
+
- mouse wheel navigation
|
|
139
|
+
- progress indicator or slide index
|
|
140
|
+
- reveal-on-enter animation triggers
|
|
141
|
+
|
|
142
|
+
### Accessibility
|
|
143
|
+
|
|
144
|
+
- use semantic structure (`main`, `section`, `nav`)
|
|
145
|
+
- keep contrast readable
|
|
146
|
+
- support keyboard-only navigation
|
|
147
|
+
- respect `prefers-reduced-motion`
|
|
148
|
+
|
|
149
|
+
## Content Density Limits
|
|
150
|
+
|
|
151
|
+
Use these maxima unless the user explicitly asks for denser slides and readability still holds:
|
|
152
|
+
|
|
153
|
+
| Slide type | Limit |
|
|
154
|
+
|------------|-------|
|
|
155
|
+
| Title | 1 heading + 1 subtitle + optional tagline |
|
|
156
|
+
| Content | 1 heading + 4-6 bullets or 2 short paragraphs |
|
|
157
|
+
| Feature grid | 6 cards max |
|
|
158
|
+
| Code | 8-10 lines max |
|
|
159
|
+
| Quote | 1 quote + attribution |
|
|
160
|
+
| Image | 1 image constrained by viewport |
|
|
161
|
+
|
|
162
|
+
## Anti-Patterns
|
|
163
|
+
|
|
164
|
+
- generic startup gradients with no visual identity
|
|
165
|
+
- system-font decks unless intentionally editorial
|
|
166
|
+
- long bullet walls
|
|
167
|
+
- code blocks that need scrolling
|
|
168
|
+
- fixed-height content boxes that break on short screens
|
|
169
|
+
- invalid negated CSS functions like `-clamp(...)`
|
|
170
|
+
|
|
171
|
+
## Related ECC Skills
|
|
172
|
+
|
|
173
|
+
- `frontend-patterns` for component and interaction patterns around the deck
|
|
174
|
+
- `liquid-glass-design` when a presentation intentionally borrows Apple glass aesthetics
|
|
175
|
+
- `e2e-testing` if you need automated browser verification for the final deck
|
|
176
|
+
|
|
177
|
+
## Deliverable Checklist
|
|
178
|
+
|
|
179
|
+
- presentation runs from a local file in a browser
|
|
180
|
+
- every slide fits the viewport without scrolling
|
|
181
|
+
- style is distinctive and intentional
|
|
182
|
+
- animation is meaningful, not noisy
|
|
183
|
+
- reduced motion is respected
|
|
184
|
+
- file paths and customization points are explained at handoff
|
|
@@ -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.
|