ai-spector 0.1.1
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 +169 -0
- package/_templates/basic_design/db-design-template.md +177 -0
- package/_templates/basic_design/detail-api-template.md +278 -0
- package/_templates/basic_design/detail-screen-template.md +281 -0
- package/_templates/basic_design/list-api-template.md +130 -0
- package/_templates/basic_design/list-screen-template.md +242 -0
- package/_templates/detail_design/common/architecture-overview-template.md +302 -0
- package/_templates/detail_design/common/deployment-infrastructure-template.md +461 -0
- package/_templates/detail_design/common/error-handling-patterns-template.md +460 -0
- package/_templates/detail_design/common/integration-patterns-template.md +410 -0
- package/_templates/detail_design/common/performance-standards-template.md +406 -0
- package/_templates/detail_design/common/security-patterns-template.md +395 -0
- package/_templates/detail_design/feature-detail-design-template.md +773 -0
- package/_templates/detail_design/feature-list-template.md +39 -0
- package/_templates/srs/1-introduction.md +58 -0
- package/_templates/srs/2-overall-description.md +91 -0
- package/_templates/srs/3-use-case-detail-template.md +142 -0
- package/_templates/srs/3-use-cases.md +53 -0
- package/_templates/srs/4-system-feature-detail-template.md +131 -0
- package/_templates/srs/4-system-features-list-template.md +39 -0
- package/_templates/srs/5-data-requirements.md +59 -0
- package/_templates/srs/6-external-interfaces.md +56 -0
- package/_templates/srs/7-quality-attributes.md +74 -0
- package/_templates/srs/8-internationalization.md +36 -0
- package/_templates/srs/9-other-requirements.md +46 -0
- package/assets/cursor/commands/analyze.md +39 -0
- package/assets/cursor/commands/generate-detail-design.md +35 -0
- package/assets/cursor/commands/generate-srs.md +38 -0
- package/assets/cursor/skills/spec-writer/SKILL.md +33 -0
- package/assets/workflow/config/analyze.graphify.json +36 -0
- package/assets/workflow/config/completeness-rules.detail-design.json +57 -0
- package/assets/workflow/config/completeness-rules.srs.json +72 -0
- package/assets/workflow/config/dag.detail-design.json +64 -0
- package/assets/workflow/config/dag.srs.json +87 -0
- package/assets/workflow/state/state.template.json +26 -0
- package/assets/workflow/templates/basic_design/db-design-template.md +177 -0
- package/assets/workflow/templates/basic_design/detail-api-template.md +278 -0
- package/assets/workflow/templates/basic_design/detail-screen-template.md +281 -0
- package/assets/workflow/templates/basic_design/list-api-template.md +130 -0
- package/assets/workflow/templates/basic_design/list-screen-template.md +242 -0
- package/assets/workflow/templates/detail_design/common/architecture-overview-template.md +302 -0
- package/assets/workflow/templates/detail_design/common/deployment-infrastructure-template.md +461 -0
- package/assets/workflow/templates/detail_design/common/error-handling-patterns-template.md +460 -0
- package/assets/workflow/templates/detail_design/common/integration-patterns-template.md +410 -0
- package/assets/workflow/templates/detail_design/common/performance-standards-template.md +406 -0
- package/assets/workflow/templates/detail_design/common/security-patterns-template.md +395 -0
- package/assets/workflow/templates/detail_design/feature-detail-design-template.md +773 -0
- package/assets/workflow/templates/detail_design/feature-list-template.md +39 -0
- package/assets/workflow/templates/srs/1-introduction.md +58 -0
- package/assets/workflow/templates/srs/2-overall-description.md +91 -0
- package/assets/workflow/templates/srs/3-use-case-detail-template.md +142 -0
- package/assets/workflow/templates/srs/3-use-cases.md +53 -0
- package/assets/workflow/templates/srs/4-system-feature-detail-template.md +131 -0
- package/assets/workflow/templates/srs/4-system-features-list-template.md +39 -0
- package/assets/workflow/templates/srs/5-data-requirements.md +59 -0
- package/assets/workflow/templates/srs/6-external-interfaces.md +56 -0
- package/assets/workflow/templates/srs/7-quality-attributes.md +74 -0
- package/assets/workflow/templates/srs/8-internationalization.md +36 -0
- package/assets/workflow/templates/srs/9-other-requirements.md +46 -0
- package/bin/spec-writer.js +56 -0
- package/package.json +25 -0
- package/src/cli/helpers/fs.js +50 -0
- package/src/cli/init.js +178 -0
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
# Security Patterns: <Project Name>
|
|
2
|
+
|
|
3
|
+
> This document defines common security patterns, authentication mechanisms, authorization strategies, and security standards used across all features.
|
|
4
|
+
|
|
5
|
+
**Source Requirements:** SRS Section 7.3 (Security Requirements)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 1. Overview
|
|
10
|
+
|
|
11
|
+
**Purpose:**
|
|
12
|
+
> This document establishes security patterns and standards that should be followed by all features to ensure consistent security implementation across the system.
|
|
13
|
+
|
|
14
|
+
**Security Principles:**
|
|
15
|
+
- Defense in depth
|
|
16
|
+
- Least privilege
|
|
17
|
+
- Secure by default
|
|
18
|
+
- Fail securely
|
|
19
|
+
- Security through obscurity is not security
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 2. Authentication
|
|
24
|
+
|
|
25
|
+
**Authentication Method:** <JWT/OAuth2/Session-based>
|
|
26
|
+
|
|
27
|
+
### 2.1 JWT Authentication (Example)
|
|
28
|
+
|
|
29
|
+
**Token Structure:**
|
|
30
|
+
```json
|
|
31
|
+
{
|
|
32
|
+
"header": {
|
|
33
|
+
"alg": "HS256",
|
|
34
|
+
"typ": "JWT"
|
|
35
|
+
},
|
|
36
|
+
"payload": {
|
|
37
|
+
"sub": "user_id",
|
|
38
|
+
"email": "user@example.com",
|
|
39
|
+
"roles": ["user", "admin"],
|
|
40
|
+
"iat": 1234567890,
|
|
41
|
+
"exp": 1234571490
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Token Lifecycle:**
|
|
47
|
+
1. User authenticates with credentials
|
|
48
|
+
2. System validates credentials
|
|
49
|
+
3. System generates JWT access token (short-lived) and refresh token (long-lived)
|
|
50
|
+
4. Client stores tokens securely
|
|
51
|
+
5. Client includes access token in Authorization header
|
|
52
|
+
6. When access token expires, client uses refresh token to obtain new access token
|
|
53
|
+
|
|
54
|
+
**Token Storage:**
|
|
55
|
+
- **Access Token:** <In-memory/HttpOnly cookie>
|
|
56
|
+
- **Refresh Token:** <HttpOnly cookie/Secure storage>
|
|
57
|
+
|
|
58
|
+
**Token Expiration:**
|
|
59
|
+
- Access Token: <Duration, e.g., 15 minutes>
|
|
60
|
+
- Refresh Token: <Duration, e.g., 7 days>
|
|
61
|
+
|
|
62
|
+
### 2.2 OAuth2 Authentication (Alternative)
|
|
63
|
+
|
|
64
|
+
**Flow Type:** <Authorization Code Flow/Client Credentials>
|
|
65
|
+
|
|
66
|
+
**OAuth2 Providers:**
|
|
67
|
+
- <Provider 1>: <Purpose>
|
|
68
|
+
- <Provider 2>: <Purpose>
|
|
69
|
+
|
|
70
|
+
**Implementation:**
|
|
71
|
+
> Describe OAuth2 implementation if used
|
|
72
|
+
|
|
73
|
+
### 2.3 Session-Based Authentication (Alternative)
|
|
74
|
+
|
|
75
|
+
**Session Management:**
|
|
76
|
+
- Session Storage: <Redis/Database>
|
|
77
|
+
- Session Expiration: <Duration>
|
|
78
|
+
- Session Security: <CSRF protection, secure cookies>
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 3. Authorization
|
|
83
|
+
|
|
84
|
+
**Authorization Model:** <RBAC/ABAC/Attribute-based>
|
|
85
|
+
|
|
86
|
+
### 3.1 Role-Based Access Control (RBAC)
|
|
87
|
+
|
|
88
|
+
**Roles:**
|
|
89
|
+
| Role | Permissions | Description |
|
|
90
|
+
|------|-------------|-------------|
|
|
91
|
+
| Admin | <All permissions> | Full system access |
|
|
92
|
+
| Manager | <Subset of permissions> | Department/team management |
|
|
93
|
+
| User | <Limited permissions> | Basic user operations |
|
|
94
|
+
|
|
95
|
+
**Role Hierarchy:**
|
|
96
|
+
```
|
|
97
|
+
Admin
|
|
98
|
+
└── Manager
|
|
99
|
+
└── User
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Permission Model:**
|
|
103
|
+
- **Resource:** <Entity, e.g., Employee, Document>
|
|
104
|
+
- **Action:** <Operation, e.g., Create, Read, Update, Delete>
|
|
105
|
+
- **Permission Format:** `<resource>:<action>`, e.g., `employee:create`
|
|
106
|
+
|
|
107
|
+
### 3.2 Attribute-Based Access Control (ABAC)
|
|
108
|
+
|
|
109
|
+
**Attributes:**
|
|
110
|
+
- User attributes: <Role, Department, Location>
|
|
111
|
+
- Resource attributes: <Owner, Department, Classification>
|
|
112
|
+
- Environment attributes: <Time, IP Address, Device>
|
|
113
|
+
|
|
114
|
+
**Policy Examples:**
|
|
115
|
+
- Users can only access resources in their department
|
|
116
|
+
- Managers can approve requests during business hours
|
|
117
|
+
- Admins can access all resources regardless of location
|
|
118
|
+
|
|
119
|
+
### 3.3 Authorization Implementation
|
|
120
|
+
|
|
121
|
+
**Middleware Pattern:**
|
|
122
|
+
```javascript
|
|
123
|
+
// Example authorization middleware
|
|
124
|
+
function authorize(permission) {
|
|
125
|
+
return (req, res, next) => {
|
|
126
|
+
if (userHasPermission(req.user, permission)) {
|
|
127
|
+
next();
|
|
128
|
+
} else {
|
|
129
|
+
res.status(403).json({ error: 'Forbidden' });
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**Usage:**
|
|
136
|
+
- Apply at API endpoint level
|
|
137
|
+
- Apply at feature/component level
|
|
138
|
+
- Apply at data access level
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## 4. Data Protection
|
|
143
|
+
|
|
144
|
+
### 4.1 Encryption
|
|
145
|
+
|
|
146
|
+
**Encryption at Rest:**
|
|
147
|
+
- Database: <Encryption method, e.g., AES-256>
|
|
148
|
+
- File Storage: <Encryption method>
|
|
149
|
+
- Backup Storage: <Encryption method>
|
|
150
|
+
|
|
151
|
+
**Encryption in Transit:**
|
|
152
|
+
- Protocol: <TLS 1.2+>
|
|
153
|
+
- Certificate Management: <Approach>
|
|
154
|
+
- Certificate Rotation: <Strategy>
|
|
155
|
+
|
|
156
|
+
**Sensitive Data Encryption:**
|
|
157
|
+
- Fields to encrypt: <PII, passwords, payment info>
|
|
158
|
+
- Encryption Algorithm: <AES-256>
|
|
159
|
+
- Key Management: <AWS KMS/HashiCorp Vault>
|
|
160
|
+
|
|
161
|
+
### 4.2 Data Masking
|
|
162
|
+
|
|
163
|
+
**Masking Rules:**
|
|
164
|
+
- Email: <Show first 3 characters, mask rest>
|
|
165
|
+
- Phone: <Show last 4 digits, mask rest>
|
|
166
|
+
- Credit Card: <Show last 4 digits, mask rest>
|
|
167
|
+
|
|
168
|
+
**When to Apply:**
|
|
169
|
+
- Logging sensitive data
|
|
170
|
+
- Displaying data in UI
|
|
171
|
+
- Sharing data with third parties
|
|
172
|
+
|
|
173
|
+
### 4.3 Password Security
|
|
174
|
+
|
|
175
|
+
**Password Requirements:**
|
|
176
|
+
- Minimum Length: <8-12 characters>
|
|
177
|
+
- Complexity: <Uppercase, lowercase, numbers, special characters>
|
|
178
|
+
- Password History: <Prevent reuse of last N passwords>
|
|
179
|
+
- Expiration: <90 days or never>
|
|
180
|
+
|
|
181
|
+
**Password Storage:**
|
|
182
|
+
- Hashing Algorithm: <bcrypt/Argon2>
|
|
183
|
+
- Salt: <Random salt per password>
|
|
184
|
+
- Never store plain text passwords
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## 5. Input Validation
|
|
189
|
+
|
|
190
|
+
### 5.1 Validation Rules
|
|
191
|
+
|
|
192
|
+
**Validation Layers:**
|
|
193
|
+
1. **Client-side:** Immediate feedback, better UX
|
|
194
|
+
2. **API Gateway:** First line of defense
|
|
195
|
+
3. **Application:** Business logic validation
|
|
196
|
+
4. **Database:** Data integrity constraints
|
|
197
|
+
|
|
198
|
+
**Common Validations:**
|
|
199
|
+
- **Length:** Min/max length constraints
|
|
200
|
+
- **Format:** Email, phone, URL patterns
|
|
201
|
+
- **Type:** String, number, date validation
|
|
202
|
+
- **Range:** Numeric range validation
|
|
203
|
+
- **Sanitization:** Remove/escape dangerous characters
|
|
204
|
+
|
|
205
|
+
### 5.2 SQL Injection Prevention
|
|
206
|
+
|
|
207
|
+
**Prevention Methods:**
|
|
208
|
+
- Use parameterized queries/prepared statements
|
|
209
|
+
- Never concatenate user input into SQL queries
|
|
210
|
+
- Use ORM/query builders with parameter binding
|
|
211
|
+
- Validate and sanitize all inputs
|
|
212
|
+
|
|
213
|
+
### 5.3 XSS Prevention
|
|
214
|
+
|
|
215
|
+
**Prevention Methods:**
|
|
216
|
+
- Escape user input before rendering
|
|
217
|
+
- Use Content Security Policy (CSP)
|
|
218
|
+
- Validate and sanitize HTML input
|
|
219
|
+
- Use framework's built-in XSS protection
|
|
220
|
+
|
|
221
|
+
### 5.4 CSRF Prevention
|
|
222
|
+
|
|
223
|
+
**Prevention Methods:**
|
|
224
|
+
- Use CSRF tokens
|
|
225
|
+
- SameSite cookie attribute
|
|
226
|
+
- Verify origin/referer headers
|
|
227
|
+
- Use framework's CSRF protection
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## 6. Security Headers
|
|
232
|
+
|
|
233
|
+
**Required HTTP Headers:**
|
|
234
|
+
|
|
235
|
+
| Header | Value | Purpose |
|
|
236
|
+
|--------|-------|---------|
|
|
237
|
+
| `Content-Security-Policy` | <Policy> | Prevents XSS attacks |
|
|
238
|
+
| `X-Frame-Options` | `DENY` or `SAMEORIGIN` | Prevents clickjacking |
|
|
239
|
+
| `X-Content-Type-Options` | `nosniff` | Prevents MIME sniffing |
|
|
240
|
+
| `Strict-Transport-Security` | `max-age=31536000` | Enforces HTTPS |
|
|
241
|
+
| `X-XSS-Protection` | `1; mode=block` | XSS protection |
|
|
242
|
+
| `Referrer-Policy` | `strict-origin-when-cross-origin` | Controls referrer info |
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## 7. Security Logging and Monitoring
|
|
247
|
+
|
|
248
|
+
### 7.1 Security Events to Log
|
|
249
|
+
|
|
250
|
+
**Authentication Events:**
|
|
251
|
+
- Login attempts (successful and failed)
|
|
252
|
+
- Logout events
|
|
253
|
+
- Token refresh
|
|
254
|
+
- Password reset requests
|
|
255
|
+
|
|
256
|
+
**Authorization Events:**
|
|
257
|
+
- Permission denied attempts
|
|
258
|
+
- Role changes
|
|
259
|
+
- Access to sensitive resources
|
|
260
|
+
|
|
261
|
+
**Security Violations:**
|
|
262
|
+
- Failed authentication attempts
|
|
263
|
+
- Unauthorized access attempts
|
|
264
|
+
- Suspicious activity patterns
|
|
265
|
+
- Data access violations
|
|
266
|
+
|
|
267
|
+
### 7.2 Log Format
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{
|
|
271
|
+
"timestamp": "2025-01-15T10:30:00Z",
|
|
272
|
+
"event_type": "authentication_failed",
|
|
273
|
+
"user_id": "user123",
|
|
274
|
+
"ip_address": "192.168.1.1",
|
|
275
|
+
"user_agent": "Mozilla/5.0...",
|
|
276
|
+
"details": {
|
|
277
|
+
"reason": "invalid_password"
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### 7.3 Monitoring and Alerting
|
|
283
|
+
|
|
284
|
+
**Alerts:**
|
|
285
|
+
- Multiple failed login attempts from same IP
|
|
286
|
+
- Unusual access patterns
|
|
287
|
+
- Privilege escalation attempts
|
|
288
|
+
- Data exfiltration attempts
|
|
289
|
+
|
|
290
|
+
**Monitoring Tools:**
|
|
291
|
+
- <SIEM tool>
|
|
292
|
+
- <Security monitoring platform>
|
|
293
|
+
- <Log aggregation tool>
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## 8. API Security
|
|
298
|
+
|
|
299
|
+
### 8.1 API Authentication
|
|
300
|
+
|
|
301
|
+
**Methods:**
|
|
302
|
+
- Bearer Token (JWT)
|
|
303
|
+
- API Key (for service-to-service)
|
|
304
|
+
- OAuth2 Client Credentials
|
|
305
|
+
|
|
306
|
+
### 8.2 Rate Limiting
|
|
307
|
+
|
|
308
|
+
**Limits:**
|
|
309
|
+
- Per IP: <X requests per minute>
|
|
310
|
+
- Per User: <X requests per minute>
|
|
311
|
+
- Per API Key: <X requests per minute>
|
|
312
|
+
|
|
313
|
+
**Implementation:**
|
|
314
|
+
- Use rate limiting middleware
|
|
315
|
+
- Return appropriate HTTP status (429 Too Many Requests)
|
|
316
|
+
- Include retry-after header
|
|
317
|
+
|
|
318
|
+
### 8.3 API Versioning
|
|
319
|
+
|
|
320
|
+
**Versioning Strategy:**
|
|
321
|
+
- URL path: `/api/v1/`, `/api/v2/`
|
|
322
|
+
- Header: `Accept: application/vnd.api+json;version=1`
|
|
323
|
+
|
|
324
|
+
**Deprecation:**
|
|
325
|
+
- Announce deprecation 6 months in advance
|
|
326
|
+
- Maintain backward compatibility during transition
|
|
327
|
+
- Provide migration guide
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## 9. Secure Development Practices
|
|
332
|
+
|
|
333
|
+
**Code Review Checklist:**
|
|
334
|
+
- [ ] Input validation implemented
|
|
335
|
+
- [ ] Authentication and authorization checked
|
|
336
|
+
- [ ] Sensitive data encrypted
|
|
337
|
+
- [ ] SQL injection prevention
|
|
338
|
+
- [ ] XSS prevention
|
|
339
|
+
- [ ] CSRF protection
|
|
340
|
+
- [ ] Security headers set
|
|
341
|
+
- [ ] Error messages don't leak sensitive info
|
|
342
|
+
- [ ] Logging doesn't expose sensitive data
|
|
343
|
+
|
|
344
|
+
**Dependency Management:**
|
|
345
|
+
- Regularly update dependencies
|
|
346
|
+
- Scan for known vulnerabilities
|
|
347
|
+
- Use dependency scanning tools
|
|
348
|
+
- Keep security patches up to date
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 10. Compliance and Standards
|
|
353
|
+
|
|
354
|
+
**Compliance Requirements:**
|
|
355
|
+
- <GDPR/PCI-DSS/HIPAA/SOC 2>
|
|
356
|
+
|
|
357
|
+
**Security Standards:**
|
|
358
|
+
- OWASP Top 10 compliance
|
|
359
|
+
- CWE Top 25 awareness
|
|
360
|
+
- Industry-specific standards
|
|
361
|
+
|
|
362
|
+
**Audit and Compliance:**
|
|
363
|
+
- Regular security audits
|
|
364
|
+
- Penetration testing
|
|
365
|
+
- Vulnerability assessments
|
|
366
|
+
- Compliance reporting
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## 11. References
|
|
371
|
+
|
|
372
|
+
**Related Documents:**
|
|
373
|
+
- [Architecture Overview](../common/architecture-overview-template.md)
|
|
374
|
+
- [Error Handling Patterns](../common/error-handling-patterns-template.md)
|
|
375
|
+
- [Feature Detail Design Template](../feature-detail-design-template.md)
|
|
376
|
+
|
|
377
|
+
**SRS References:**
|
|
378
|
+
- SRS Section 7.3: Security Requirements
|
|
379
|
+
|
|
380
|
+
**External Resources:**
|
|
381
|
+
- OWASP Top 10: <Link>
|
|
382
|
+
- OWASP API Security Top 10: <Link>
|
|
383
|
+
- Security Best Practices: <Link>
|
|
384
|
+
|
|
385
|
+
---
|
|
386
|
+
|
|
387
|
+
## 12. Notes
|
|
388
|
+
|
|
389
|
+
**Security Considerations:**
|
|
390
|
+
- <Consideration 1>
|
|
391
|
+
- <Consideration 2>
|
|
392
|
+
|
|
393
|
+
**Future Enhancements:**
|
|
394
|
+
- <Enhancement 1>
|
|
395
|
+
- <Enhancement 2>
|