knowzcode 0.4.0 → 0.5.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.
Files changed (79) hide show
  1. package/.claude-plugin/marketplace.json +61 -61
  2. package/.claude-plugin/plugin.json +8 -8
  3. package/LICENSE +121 -121
  4. package/README.md +379 -354
  5. package/agents/analyst.md +114 -114
  6. package/agents/architect.md +200 -200
  7. package/agents/builder.md +104 -104
  8. package/agents/closer.md +177 -177
  9. package/agents/context-scout.md +54 -54
  10. package/agents/knowledge-migrator.md +349 -349
  11. package/agents/knowz-scout.md +83 -83
  12. package/agents/knowz-scribe.md +180 -180
  13. package/agents/microfix-specialist.md +135 -135
  14. package/agents/project-advisor.md +111 -111
  15. package/agents/reviewer.md +172 -172
  16. package/agents/security-officer.md +194 -194
  17. package/agents/test-advisor.md +162 -162
  18. package/agents/update-coordinator.md +394 -394
  19. package/bin/knowzcode.mjs +1457 -1199
  20. package/commands/audit.md +328 -328
  21. package/commands/connect-mcp.md +574 -549
  22. package/commands/fix.md +107 -107
  23. package/commands/init.md +616 -500
  24. package/commands/learn.md +332 -332
  25. package/commands/plan.md +272 -272
  26. package/commands/register.md +757 -733
  27. package/commands/status.md +338 -309
  28. package/commands/telemetry-setup.md +368 -368
  29. package/commands/telemetry.md +188 -188
  30. package/commands/work.md +1204 -1204
  31. package/knowzcode/automation_manifest.md +59 -59
  32. package/knowzcode/claude_code_execution.md +431 -431
  33. package/knowzcode/copilot_execution.md +231 -231
  34. package/knowzcode/enterprise/compliance_manifest.md +137 -137
  35. package/knowzcode/enterprise/compliance_status.md +30 -30
  36. package/knowzcode/enterprise/guidelines/code-quality.md +67 -67
  37. package/knowzcode/enterprise/guidelines/security.md +355 -355
  38. package/knowzcode/enterprise/templates/guideline-template.md +55 -55
  39. package/knowzcode/gitignore.template +13 -13
  40. package/knowzcode/knowzcode_architecture.md +51 -51
  41. package/knowzcode/knowzcode_log.md +142 -142
  42. package/knowzcode/knowzcode_loop.md +601 -596
  43. package/knowzcode/knowzcode_orchestration.md +66 -66
  44. package/knowzcode/knowzcode_project.md +48 -48
  45. package/knowzcode/knowzcode_tracker.md +40 -40
  46. package/knowzcode/knowzcode_vaults.md +257 -257
  47. package/knowzcode/mcp_config.md +196 -191
  48. package/knowzcode/planning/Readme.md +6 -6
  49. package/knowzcode/platform_adapters.md +2577 -1260
  50. package/knowzcode/prompts/Execute_Micro_Fix.md +57 -57
  51. package/knowzcode/prompts/Investigate_Codebase.md +227 -227
  52. package/knowzcode/prompts/Migrate_Knowledge.md +301 -301
  53. package/knowzcode/prompts/Refactor_Node.md +72 -72
  54. package/knowzcode/prompts/Spec_Verification_Checkpoint.md +59 -59
  55. package/knowzcode/prompts/[LOOP_1A]__Propose_Change_Set.md +52 -52
  56. package/knowzcode/prompts/[LOOP_1B]__Draft_Specs.md +75 -75
  57. package/knowzcode/prompts/[LOOP_2A]__Implement_Change_Set.md +55 -55
  58. package/knowzcode/prompts/[LOOP_2B]__Verify_Implementation.md +72 -72
  59. package/knowzcode/prompts/[LOOP_3]__Finalize_And_Commit.md +67 -67
  60. package/knowzcode/specs/Readme.md +10 -10
  61. package/knowzcode/telemetry_config.md +89 -89
  62. package/knowzcode/user_preferences.md +120 -120
  63. package/package.json +53 -53
  64. package/skills/alias-resolver.json +15 -15
  65. package/skills/architecture-diff.json +12 -12
  66. package/skills/check-installation-status.json +14 -14
  67. package/skills/continue.md +126 -126
  68. package/skills/environment-guard.json +12 -12
  69. package/skills/generate-workgroup-id.json +25 -25
  70. package/skills/install-knowzcode.json +21 -21
  71. package/skills/load-core-context.json +18 -18
  72. package/skills/log-entry-builder.json +15 -15
  73. package/skills/spec-quality-check.json +14 -14
  74. package/skills/spec-template.json +15 -15
  75. package/skills/spec-validator.json +25 -25
  76. package/skills/start-work.md +224 -224
  77. package/skills/tracker-scan.json +12 -12
  78. package/skills/tracker-update.json +28 -28
  79. package/skills/validate-installation.json +14 -14
@@ -1,355 +1,355 @@
1
- ---
2
- guideline_id: SEC-001
3
- name: Security Guidelines
4
- version: "1.0"
5
- last_updated: "2025-01-29"
6
- enforcement: blocking
7
- applies_to: both
8
- categories:
9
- - authentication
10
- - authorization
11
- - data-protection
12
- - injection-prevention
13
- - logging
14
- priority: critical
15
- owner: security-team
16
- ---
17
-
18
- # Security Guidelines
19
-
20
- **Purpose:** Ensure all specifications and implementations meet enterprise security requirements based on industry best practices and OWASP guidelines.
21
-
22
- ---
23
-
24
- ## 1. Authentication Requirements
25
-
26
- ### SEC-AUTH-01: Secure Password Handling
27
-
28
- **Requirement:** All passwords MUST be hashed using bcrypt (cost >= 10) or Argon2. Plaintext passwords MUST never be stored or logged.
29
-
30
- **Applies To:** implementation
31
-
32
- **Severity:** critical
33
-
34
- **ARC Verification:**
35
- - ARC_SEC_AUTH_01a: Verify password storage uses bcrypt with cost >= 10 OR Argon2
36
- - ARC_SEC_AUTH_01b: Verify plaintext passwords are never logged or stored in databases
37
- - ARC_SEC_AUTH_01c: Verify password comparison uses constant-time comparison function
38
-
39
- **Compliant Example:**
40
- ```typescript
41
- import bcrypt from 'bcrypt';
42
-
43
- async function hashPassword(password: string): Promise<string> {
44
- const saltRounds = 12; // cost factor >= 10
45
- return bcrypt.hash(password, saltRounds);
46
- }
47
-
48
- async function verifyPassword(password: string, hash: string): Promise<boolean> {
49
- return bcrypt.compare(password, hash); // constant-time comparison
50
- }
51
- ```
52
-
53
- **Non-Compliant Example:**
54
- ```typescript
55
- // VIOLATION: Storing plaintext password
56
- db.users.insert({ password: userPassword });
57
-
58
- // VIOLATION: Using weak hashing algorithm
59
- const hash = crypto.createHash('md5').update(password).digest('hex');
60
-
61
- // VIOLATION: Non-constant-time comparison
62
- if (storedPassword === inputPassword) { /* ... */ }
63
- ```
64
-
65
- **Remediation:** Replace plaintext storage or weak hashing with bcrypt. Use library's built-in compare function for constant-time comparison.
66
-
67
- ---
68
-
69
- ### SEC-AUTH-02: Session Management
70
-
71
- **Requirement:** Sessions MUST have secure cookie settings and configurable expiry. Session tokens MUST be regenerated after authentication.
72
-
73
- **Applies To:** both
74
-
75
- **Severity:** high
76
-
77
- **ARC Verification:**
78
- - ARC_SEC_AUTH_02a: Verify session cookies have HttpOnly flag set to true
79
- - ARC_SEC_AUTH_02b: Verify session cookies have Secure flag in production environment
80
- - ARC_SEC_AUTH_02c: Verify session expiry is configurable and defaults to <= 24 hours
81
- - ARC_SEC_AUTH_02d: Verify session token is regenerated after successful login
82
- - ARC_SEC_AUTH_02e: Spec MUST document session lifecycle and security properties
83
-
84
- **Compliant Example:**
85
- ```typescript
86
- app.use(session({
87
- secret: process.env.SESSION_SECRET,
88
- cookie: {
89
- httpOnly: true,
90
- secure: process.env.NODE_ENV === 'production',
91
- sameSite: 'strict',
92
- maxAge: 24 * 60 * 60 * 1000 // 24 hours max
93
- },
94
- resave: false,
95
- saveUninitialized: false
96
- }));
97
-
98
- // Regenerate session after login
99
- req.session.regenerate((err) => {
100
- req.session.userId = user.id;
101
- });
102
- ```
103
-
104
- **Non-Compliant Example:**
105
- ```typescript
106
- // VIOLATION: Insecure cookie settings
107
- app.use(session({
108
- secret: 'hardcoded-secret', // Never hardcode secrets
109
- cookie: {
110
- httpOnly: false, // Allows XSS to steal session
111
- secure: false, // Allows interception over HTTP
112
- // Missing maxAge = potential infinite session
113
- }
114
- }));
115
- ```
116
-
117
- ---
118
-
119
- ## 2. Authorization Requirements
120
-
121
- ### SEC-AUTHZ-01: Role-Based Access Control
122
-
123
- **Requirement:** All protected resources MUST implement server-side authorization checks. Authorization MUST NOT rely solely on client-side controls.
124
-
125
- **Applies To:** both
126
-
127
- **Severity:** critical
128
-
129
- **ARC Verification:**
130
- - ARC_SEC_AUTHZ_01a: Verify all API endpoints have authorization middleware
131
- - ARC_SEC_AUTHZ_01b: Verify authorization is enforced server-side, not client-only
132
- - ARC_SEC_AUTHZ_01c: Verify Spec documents required roles/permissions per endpoint
133
- - ARC_SEC_AUTHZ_01d: Verify authorization failures return 403 Forbidden (not 404)
134
-
135
- **Compliant Example:**
136
- ```typescript
137
- // Server-side authorization middleware
138
- const authorize = (roles: string[]) => (req, res, next) => {
139
- if (!req.user || !roles.includes(req.user.role)) {
140
- return res.status(403).json({ error: 'Forbidden' });
141
- }
142
- next();
143
- };
144
-
145
- router.delete('/users/:id',
146
- authenticate,
147
- authorize(['admin']), // Server-side role check
148
- deleteUserHandler
149
- );
150
- ```
151
-
152
- **Non-Compliant Example:**
153
- ```typescript
154
- // VIOLATION: No server-side authorization
155
- router.delete('/users/:id', deleteUserHandler); // Anyone can delete!
156
-
157
- // VIOLATION: Client-only authorization (easily bypassed)
158
- // Frontend: if (user.role === 'admin') showDeleteButton()
159
- // Backend: router.delete('/users/:id', deleteUserHandler); // No check!
160
- ```
161
-
162
- ---
163
-
164
- ### SEC-AUTHZ-02: IDOR Prevention
165
-
166
- **Requirement:** Resource access MUST verify the requesting user has permission to access the specific resource, not just the resource type.
167
-
168
- **Applies To:** implementation
169
-
170
- **Severity:** critical
171
-
172
- **ARC Verification:**
173
- - ARC_SEC_AUTHZ_02a: Verify resource ownership is checked before returning data
174
- - ARC_SEC_AUTHZ_02b: Verify users cannot access other users' data by changing IDs in requests
175
-
176
- **Compliant Example:**
177
- ```typescript
178
- // Check ownership before returning resource
179
- async function getDocument(req, res) {
180
- const doc = await Document.findById(req.params.id);
181
- if (!doc) return res.status(404).json({ error: 'Not found' });
182
-
183
- // IDOR prevention: verify ownership
184
- if (doc.ownerId !== req.user.id && !req.user.isAdmin) {
185
- return res.status(403).json({ error: 'Forbidden' });
186
- }
187
-
188
- res.json(doc);
189
- }
190
- ```
191
-
192
- ---
193
-
194
- ## 3. Data Protection Requirements
195
-
196
- ### SEC-DATA-01: Sensitive Data Handling
197
-
198
- **Requirement:** PII and sensitive data MUST be encrypted at rest and in transit. Data classification MUST be documented in specs.
199
-
200
- **Applies To:** both
201
-
202
- **Severity:** critical
203
-
204
- **ARC Verification:**
205
- - ARC_SEC_DATA_01a: Verify database connections use TLS/SSL
206
- - ARC_SEC_DATA_01b: Verify PII fields are encrypted or appropriately protected
207
- - ARC_SEC_DATA_01c: Verify Spec includes data classification (Public/Internal/Confidential/Secret)
208
- - ARC_SEC_DATA_01d: Verify sensitive data is not included in logs or error messages
209
-
210
- **Compliant Example:**
211
- ```typescript
212
- // TLS connection to database
213
- const pool = new Pool({
214
- connectionString: process.env.DATABASE_URL,
215
- ssl: { rejectUnauthorized: true }
216
- });
217
-
218
- // Encrypt sensitive fields
219
- const encryptedSSN = encrypt(user.ssn, process.env.ENCRYPTION_KEY);
220
- ```
221
-
222
- ---
223
-
224
- ## 4. Injection Prevention
225
-
226
- ### SEC-INJ-01: SQL Injection Prevention
227
-
228
- **Requirement:** All database queries MUST use parameterized queries, prepared statements, or ORM methods. String concatenation in queries is PROHIBITED.
229
-
230
- **Applies To:** implementation
231
-
232
- **Severity:** critical
233
-
234
- **ARC Verification:**
235
- - ARC_SEC_INJ_01a: Verify no string concatenation or template literals in SQL queries
236
- - ARC_SEC_INJ_01b: Verify ORM is used OR parameterized queries exclusively
237
-
238
- **Compliant Example:**
239
- ```typescript
240
- // Using ORM (Prisma)
241
- const user = await prisma.user.findUnique({ where: { id: userId } });
242
-
243
- // Using parameterized query
244
- const result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
245
-
246
- // Using prepared statement
247
- const stmt = db.prepare('SELECT * FROM users WHERE email = ?');
248
- const user = stmt.get(email);
249
- ```
250
-
251
- **Non-Compliant Example:**
252
- ```typescript
253
- // VIOLATION: SQL Injection vulnerable - string concatenation
254
- const result = await db.query(`SELECT * FROM users WHERE id = ${userId}`);
255
-
256
- // VIOLATION: SQL Injection vulnerable - template literal
257
- const query = `SELECT * FROM users WHERE name = '${userName}'`;
258
- ```
259
-
260
- ---
261
-
262
- ### SEC-INJ-02: XSS Prevention
263
-
264
- **Requirement:** All user input displayed in HTML MUST be properly escaped or sanitized. Framework auto-escaping should not be bypassed without explicit security review.
265
-
266
- **Applies To:** implementation
267
-
268
- **Severity:** high
269
-
270
- **ARC Verification:**
271
- - ARC_SEC_INJ_02a: Verify user input is escaped before rendering in HTML
272
- - ARC_SEC_INJ_02b: Verify dangerouslySetInnerHTML (React) or v-html (Vue) usage is justified and sanitized
273
- - ARC_SEC_INJ_02c: Verify Content-Security-Policy headers are configured
274
-
275
- **Compliant Example:**
276
- ```typescript
277
- // React auto-escapes by default
278
- return <div>{userInput}</div>; // Safe
279
-
280
- // If HTML is required, sanitize first
281
- import DOMPurify from 'dompurify';
282
- const sanitized = DOMPurify.sanitize(userInput);
283
- return <div dangerouslySetInnerHTML={{ __html: sanitized }} />;
284
- ```
285
-
286
- **Non-Compliant Example:**
287
- ```typescript
288
- // VIOLATION: Unsanitized HTML injection
289
- return <div dangerouslySetInnerHTML={{ __html: userInput }} />;
290
- ```
291
-
292
- ---
293
-
294
- ## 5. Logging Requirements
295
-
296
- ### SEC-LOG-01: Security Event Logging
297
-
298
- **Requirement:** Authentication events (login success/failure, logout, password changes) MUST be logged with audit trail. Logs MUST NOT contain passwords, tokens, or other secrets.
299
-
300
- **Applies To:** implementation
301
-
302
- **Severity:** high
303
-
304
- **ARC Verification:**
305
- - ARC_SEC_LOG_01a: Verify login attempts (success and failure) are logged
306
- - ARC_SEC_LOG_01b: Verify logs do NOT contain passwords, tokens, or API keys
307
- - ARC_SEC_LOG_01c: Verify log entries include timestamp, user ID, event type, IP address
308
- - ARC_SEC_LOG_01d: Verify password change events are logged
309
-
310
- **Compliant Example:**
311
- ```typescript
312
- // Structured security logging
313
- logger.info({
314
- event: 'login_success',
315
- userId: user.id,
316
- email: user.email,
317
- ip: req.ip,
318
- userAgent: req.headers['user-agent'],
319
- timestamp: new Date().toISOString()
320
- });
321
-
322
- // Never log sensitive data
323
- logger.info({ event: 'login_attempt', email }); // Good
324
- logger.info({ event: 'login_attempt', email, password }); // NEVER!
325
- ```
326
-
327
- **Non-Compliant Example:**
328
- ```typescript
329
- // VIOLATION: Logging sensitive data
330
- logger.info(`User ${email} logged in with password ${password}`);
331
- logger.debug({ user, token: authToken }); // Leaking token
332
- ```
333
-
334
- ---
335
-
336
- ## Compliance Summary
337
-
338
- | ID | Requirement | Severity | Scope | Category |
339
- |:---|:------------|:---------|:------|:---------|
340
- | SEC-AUTH-01 | Secure Password Handling | critical | implementation | authentication |
341
- | SEC-AUTH-02 | Session Management | high | both | authentication |
342
- | SEC-AUTHZ-01 | Role-Based Access Control | critical | both | authorization |
343
- | SEC-AUTHZ-02 | IDOR Prevention | critical | implementation | authorization |
344
- | SEC-DATA-01 | Sensitive Data Handling | critical | both | data-protection |
345
- | SEC-INJ-01 | SQL Injection Prevention | critical | implementation | injection-prevention |
346
- | SEC-INJ-02 | XSS Prevention | high | implementation | injection-prevention |
347
- | SEC-LOG-01 | Security Event Logging | high | implementation | logging |
348
-
349
- ---
350
-
351
- ## References
352
-
353
- - [OWASP Top 10](https://owasp.org/Top10/)
354
- - [OWASP Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)
355
- - [OWASP Session Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)
1
+ ---
2
+ guideline_id: SEC-001
3
+ name: Security Guidelines
4
+ version: "1.0"
5
+ last_updated: "2025-01-29"
6
+ enforcement: blocking
7
+ applies_to: both
8
+ categories:
9
+ - authentication
10
+ - authorization
11
+ - data-protection
12
+ - injection-prevention
13
+ - logging
14
+ priority: critical
15
+ owner: security-team
16
+ ---
17
+
18
+ # Security Guidelines
19
+
20
+ **Purpose:** Ensure all specifications and implementations meet enterprise security requirements based on industry best practices and OWASP guidelines.
21
+
22
+ ---
23
+
24
+ ## 1. Authentication Requirements
25
+
26
+ ### SEC-AUTH-01: Secure Password Handling
27
+
28
+ **Requirement:** All passwords MUST be hashed using bcrypt (cost >= 10) or Argon2. Plaintext passwords MUST never be stored or logged.
29
+
30
+ **Applies To:** implementation
31
+
32
+ **Severity:** critical
33
+
34
+ **ARC Verification:**
35
+ - ARC_SEC_AUTH_01a: Verify password storage uses bcrypt with cost >= 10 OR Argon2
36
+ - ARC_SEC_AUTH_01b: Verify plaintext passwords are never logged or stored in databases
37
+ - ARC_SEC_AUTH_01c: Verify password comparison uses constant-time comparison function
38
+
39
+ **Compliant Example:**
40
+ ```typescript
41
+ import bcrypt from 'bcrypt';
42
+
43
+ async function hashPassword(password: string): Promise<string> {
44
+ const saltRounds = 12; // cost factor >= 10
45
+ return bcrypt.hash(password, saltRounds);
46
+ }
47
+
48
+ async function verifyPassword(password: string, hash: string): Promise<boolean> {
49
+ return bcrypt.compare(password, hash); // constant-time comparison
50
+ }
51
+ ```
52
+
53
+ **Non-Compliant Example:**
54
+ ```typescript
55
+ // VIOLATION: Storing plaintext password
56
+ db.users.insert({ password: userPassword });
57
+
58
+ // VIOLATION: Using weak hashing algorithm
59
+ const hash = crypto.createHash('md5').update(password).digest('hex');
60
+
61
+ // VIOLATION: Non-constant-time comparison
62
+ if (storedPassword === inputPassword) { /* ... */ }
63
+ ```
64
+
65
+ **Remediation:** Replace plaintext storage or weak hashing with bcrypt. Use library's built-in compare function for constant-time comparison.
66
+
67
+ ---
68
+
69
+ ### SEC-AUTH-02: Session Management
70
+
71
+ **Requirement:** Sessions MUST have secure cookie settings and configurable expiry. Session tokens MUST be regenerated after authentication.
72
+
73
+ **Applies To:** both
74
+
75
+ **Severity:** high
76
+
77
+ **ARC Verification:**
78
+ - ARC_SEC_AUTH_02a: Verify session cookies have HttpOnly flag set to true
79
+ - ARC_SEC_AUTH_02b: Verify session cookies have Secure flag in production environment
80
+ - ARC_SEC_AUTH_02c: Verify session expiry is configurable and defaults to <= 24 hours
81
+ - ARC_SEC_AUTH_02d: Verify session token is regenerated after successful login
82
+ - ARC_SEC_AUTH_02e: Spec MUST document session lifecycle and security properties
83
+
84
+ **Compliant Example:**
85
+ ```typescript
86
+ app.use(session({
87
+ secret: process.env.SESSION_SECRET,
88
+ cookie: {
89
+ httpOnly: true,
90
+ secure: process.env.NODE_ENV === 'production',
91
+ sameSite: 'strict',
92
+ maxAge: 24 * 60 * 60 * 1000 // 24 hours max
93
+ },
94
+ resave: false,
95
+ saveUninitialized: false
96
+ }));
97
+
98
+ // Regenerate session after login
99
+ req.session.regenerate((err) => {
100
+ req.session.userId = user.id;
101
+ });
102
+ ```
103
+
104
+ **Non-Compliant Example:**
105
+ ```typescript
106
+ // VIOLATION: Insecure cookie settings
107
+ app.use(session({
108
+ secret: 'hardcoded-secret', // Never hardcode secrets
109
+ cookie: {
110
+ httpOnly: false, // Allows XSS to steal session
111
+ secure: false, // Allows interception over HTTP
112
+ // Missing maxAge = potential infinite session
113
+ }
114
+ }));
115
+ ```
116
+
117
+ ---
118
+
119
+ ## 2. Authorization Requirements
120
+
121
+ ### SEC-AUTHZ-01: Role-Based Access Control
122
+
123
+ **Requirement:** All protected resources MUST implement server-side authorization checks. Authorization MUST NOT rely solely on client-side controls.
124
+
125
+ **Applies To:** both
126
+
127
+ **Severity:** critical
128
+
129
+ **ARC Verification:**
130
+ - ARC_SEC_AUTHZ_01a: Verify all API endpoints have authorization middleware
131
+ - ARC_SEC_AUTHZ_01b: Verify authorization is enforced server-side, not client-only
132
+ - ARC_SEC_AUTHZ_01c: Verify Spec documents required roles/permissions per endpoint
133
+ - ARC_SEC_AUTHZ_01d: Verify authorization failures return 403 Forbidden (not 404)
134
+
135
+ **Compliant Example:**
136
+ ```typescript
137
+ // Server-side authorization middleware
138
+ const authorize = (roles: string[]) => (req, res, next) => {
139
+ if (!req.user || !roles.includes(req.user.role)) {
140
+ return res.status(403).json({ error: 'Forbidden' });
141
+ }
142
+ next();
143
+ };
144
+
145
+ router.delete('/users/:id',
146
+ authenticate,
147
+ authorize(['admin']), // Server-side role check
148
+ deleteUserHandler
149
+ );
150
+ ```
151
+
152
+ **Non-Compliant Example:**
153
+ ```typescript
154
+ // VIOLATION: No server-side authorization
155
+ router.delete('/users/:id', deleteUserHandler); // Anyone can delete!
156
+
157
+ // VIOLATION: Client-only authorization (easily bypassed)
158
+ // Frontend: if (user.role === 'admin') showDeleteButton()
159
+ // Backend: router.delete('/users/:id', deleteUserHandler); // No check!
160
+ ```
161
+
162
+ ---
163
+
164
+ ### SEC-AUTHZ-02: IDOR Prevention
165
+
166
+ **Requirement:** Resource access MUST verify the requesting user has permission to access the specific resource, not just the resource type.
167
+
168
+ **Applies To:** implementation
169
+
170
+ **Severity:** critical
171
+
172
+ **ARC Verification:**
173
+ - ARC_SEC_AUTHZ_02a: Verify resource ownership is checked before returning data
174
+ - ARC_SEC_AUTHZ_02b: Verify users cannot access other users' data by changing IDs in requests
175
+
176
+ **Compliant Example:**
177
+ ```typescript
178
+ // Check ownership before returning resource
179
+ async function getDocument(req, res) {
180
+ const doc = await Document.findById(req.params.id);
181
+ if (!doc) return res.status(404).json({ error: 'Not found' });
182
+
183
+ // IDOR prevention: verify ownership
184
+ if (doc.ownerId !== req.user.id && !req.user.isAdmin) {
185
+ return res.status(403).json({ error: 'Forbidden' });
186
+ }
187
+
188
+ res.json(doc);
189
+ }
190
+ ```
191
+
192
+ ---
193
+
194
+ ## 3. Data Protection Requirements
195
+
196
+ ### SEC-DATA-01: Sensitive Data Handling
197
+
198
+ **Requirement:** PII and sensitive data MUST be encrypted at rest and in transit. Data classification MUST be documented in specs.
199
+
200
+ **Applies To:** both
201
+
202
+ **Severity:** critical
203
+
204
+ **ARC Verification:**
205
+ - ARC_SEC_DATA_01a: Verify database connections use TLS/SSL
206
+ - ARC_SEC_DATA_01b: Verify PII fields are encrypted or appropriately protected
207
+ - ARC_SEC_DATA_01c: Verify Spec includes data classification (Public/Internal/Confidential/Secret)
208
+ - ARC_SEC_DATA_01d: Verify sensitive data is not included in logs or error messages
209
+
210
+ **Compliant Example:**
211
+ ```typescript
212
+ // TLS connection to database
213
+ const pool = new Pool({
214
+ connectionString: process.env.DATABASE_URL,
215
+ ssl: { rejectUnauthorized: true }
216
+ });
217
+
218
+ // Encrypt sensitive fields
219
+ const encryptedSSN = encrypt(user.ssn, process.env.ENCRYPTION_KEY);
220
+ ```
221
+
222
+ ---
223
+
224
+ ## 4. Injection Prevention
225
+
226
+ ### SEC-INJ-01: SQL Injection Prevention
227
+
228
+ **Requirement:** All database queries MUST use parameterized queries, prepared statements, or ORM methods. String concatenation in queries is PROHIBITED.
229
+
230
+ **Applies To:** implementation
231
+
232
+ **Severity:** critical
233
+
234
+ **ARC Verification:**
235
+ - ARC_SEC_INJ_01a: Verify no string concatenation or template literals in SQL queries
236
+ - ARC_SEC_INJ_01b: Verify ORM is used OR parameterized queries exclusively
237
+
238
+ **Compliant Example:**
239
+ ```typescript
240
+ // Using ORM (Prisma)
241
+ const user = await prisma.user.findUnique({ where: { id: userId } });
242
+
243
+ // Using parameterized query
244
+ const result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
245
+
246
+ // Using prepared statement
247
+ const stmt = db.prepare('SELECT * FROM users WHERE email = ?');
248
+ const user = stmt.get(email);
249
+ ```
250
+
251
+ **Non-Compliant Example:**
252
+ ```typescript
253
+ // VIOLATION: SQL Injection vulnerable - string concatenation
254
+ const result = await db.query(`SELECT * FROM users WHERE id = ${userId}`);
255
+
256
+ // VIOLATION: SQL Injection vulnerable - template literal
257
+ const query = `SELECT * FROM users WHERE name = '${userName}'`;
258
+ ```
259
+
260
+ ---
261
+
262
+ ### SEC-INJ-02: XSS Prevention
263
+
264
+ **Requirement:** All user input displayed in HTML MUST be properly escaped or sanitized. Framework auto-escaping should not be bypassed without explicit security review.
265
+
266
+ **Applies To:** implementation
267
+
268
+ **Severity:** high
269
+
270
+ **ARC Verification:**
271
+ - ARC_SEC_INJ_02a: Verify user input is escaped before rendering in HTML
272
+ - ARC_SEC_INJ_02b: Verify dangerouslySetInnerHTML (React) or v-html (Vue) usage is justified and sanitized
273
+ - ARC_SEC_INJ_02c: Verify Content-Security-Policy headers are configured
274
+
275
+ **Compliant Example:**
276
+ ```typescript
277
+ // React auto-escapes by default
278
+ return <div>{userInput}</div>; // Safe
279
+
280
+ // If HTML is required, sanitize first
281
+ import DOMPurify from 'dompurify';
282
+ const sanitized = DOMPurify.sanitize(userInput);
283
+ return <div dangerouslySetInnerHTML={{ __html: sanitized }} />;
284
+ ```
285
+
286
+ **Non-Compliant Example:**
287
+ ```typescript
288
+ // VIOLATION: Unsanitized HTML injection
289
+ return <div dangerouslySetInnerHTML={{ __html: userInput }} />;
290
+ ```
291
+
292
+ ---
293
+
294
+ ## 5. Logging Requirements
295
+
296
+ ### SEC-LOG-01: Security Event Logging
297
+
298
+ **Requirement:** Authentication events (login success/failure, logout, password changes) MUST be logged with audit trail. Logs MUST NOT contain passwords, tokens, or other secrets.
299
+
300
+ **Applies To:** implementation
301
+
302
+ **Severity:** high
303
+
304
+ **ARC Verification:**
305
+ - ARC_SEC_LOG_01a: Verify login attempts (success and failure) are logged
306
+ - ARC_SEC_LOG_01b: Verify logs do NOT contain passwords, tokens, or API keys
307
+ - ARC_SEC_LOG_01c: Verify log entries include timestamp, user ID, event type, IP address
308
+ - ARC_SEC_LOG_01d: Verify password change events are logged
309
+
310
+ **Compliant Example:**
311
+ ```typescript
312
+ // Structured security logging
313
+ logger.info({
314
+ event: 'login_success',
315
+ userId: user.id,
316
+ email: user.email,
317
+ ip: req.ip,
318
+ userAgent: req.headers['user-agent'],
319
+ timestamp: new Date().toISOString()
320
+ });
321
+
322
+ // Never log sensitive data
323
+ logger.info({ event: 'login_attempt', email }); // Good
324
+ logger.info({ event: 'login_attempt', email, password }); // NEVER!
325
+ ```
326
+
327
+ **Non-Compliant Example:**
328
+ ```typescript
329
+ // VIOLATION: Logging sensitive data
330
+ logger.info(`User ${email} logged in with password ${password}`);
331
+ logger.debug({ user, token: authToken }); // Leaking token
332
+ ```
333
+
334
+ ---
335
+
336
+ ## Compliance Summary
337
+
338
+ | ID | Requirement | Severity | Scope | Category |
339
+ |:---|:------------|:---------|:------|:---------|
340
+ | SEC-AUTH-01 | Secure Password Handling | critical | implementation | authentication |
341
+ | SEC-AUTH-02 | Session Management | high | both | authentication |
342
+ | SEC-AUTHZ-01 | Role-Based Access Control | critical | both | authorization |
343
+ | SEC-AUTHZ-02 | IDOR Prevention | critical | implementation | authorization |
344
+ | SEC-DATA-01 | Sensitive Data Handling | critical | both | data-protection |
345
+ | SEC-INJ-01 | SQL Injection Prevention | critical | implementation | injection-prevention |
346
+ | SEC-INJ-02 | XSS Prevention | high | implementation | injection-prevention |
347
+ | SEC-LOG-01 | Security Event Logging | high | implementation | logging |
348
+
349
+ ---
350
+
351
+ ## References
352
+
353
+ - [OWASP Top 10](https://owasp.org/Top10/)
354
+ - [OWASP Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)
355
+ - [OWASP Session Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html)