tribunal-kit 4.4.1 → 4.4.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/.agent/history/architecture-graph.yaml +140 -0
- package/.agent/history/graph-cache.json +262 -0
- package/.agent/history/snapshots/bin__tribunal-kit.js.json +19 -0
- package/.agent/history/snapshots/eslint.config.js.json +9 -0
- package/.agent/history/snapshots/migrate_refs.js.json +11 -0
- package/.agent/history/snapshots/scripts__changelog.js.json +13 -0
- package/.agent/history/snapshots/scripts__sync-version.js.json +12 -0
- package/.agent/history/snapshots/scripts__validate-payload.js.json +12 -0
- package/.agent/history/snapshots/test__integration__bridges.test.js.json +14 -0
- package/.agent/history/snapshots/test__integration__init.test.js.json +14 -0
- package/.agent/history/snapshots/test__integration__routing.test.js.json +12 -0
- package/.agent/history/snapshots/test__integration__swarm_dispatcher.test.js.json +14 -0
- package/.agent/history/snapshots/test__integration__wave2.test.js.json +14 -0
- package/.agent/history/snapshots/test__unit__args.test.js.json +20 -0
- package/.agent/history/snapshots/test__unit__case_law_manager.test.js.json +11 -0
- package/.agent/history/snapshots/test__unit__context_broker.test.js.json +11 -0
- package/.agent/history/snapshots/test__unit__copyDir.test.js.json +23 -0
- package/.agent/history/snapshots/test__unit__graph_tools.test.js.json +12 -0
- package/.agent/history/snapshots/test__unit__inner_loop_validator.test.js.json +11 -0
- package/.agent/history/snapshots/test__unit__selfInstall.test.js.json +23 -0
- package/.agent/history/snapshots/test__unit__semver.test.js.json +20 -0
- package/.agent/history/snapshots/test__unit__swarm_dispatcher.test.js.json +12 -0
- package/.agent/scripts/_colors.js +170 -18
- package/.agent/scripts/_utils.js +244 -42
- package/.agent/scripts/bundle_analyzer.js +261 -290
- package/.agent/scripts/case_law_manager.js +1 -7
- package/.agent/scripts/checklist.js +278 -266
- package/.agent/scripts/colors.js +11 -17
- package/.agent/scripts/context_broker.js +1 -7
- package/.agent/scripts/dependency_analyzer.js +234 -272
- package/.agent/scripts/graph_builder.js +46 -18
- package/.agent/scripts/graph_visualizer.js +10 -4
- package/.agent/scripts/graph_zoom.js +6 -4
- package/.agent/scripts/inner_loop_validator.js +2 -8
- package/.agent/scripts/lint_runner.js +186 -187
- package/.agent/scripts/schema_validator.js +8 -25
- package/.agent/scripts/security_scan.js +276 -303
- package/.agent/scripts/session_manager.js +1 -7
- package/.agent/scripts/skill_evolution.js +1 -8
- package/.agent/scripts/skill_integrator.js +1 -7
- package/.agent/scripts/test_runner.js +186 -193
- package/.agent/scripts/utils.js +17 -32
- package/.agent/scripts/verify_all.js +248 -257
- package/package.json +1 -1
|
@@ -1,303 +1,276 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* security_scan.js — Deep security scanner for the Tribunal Agent Kit.
|
|
4
|
-
*
|
|
5
|
-
* Checks for OWASP Top 10 patterns in source code:
|
|
6
|
-
* - Hardcoded secrets and credentials
|
|
7
|
-
* - SQL injection patterns (string concatenation in queries)
|
|
8
|
-
* - XSS-prone code (innerHTML, dangerouslySetInnerHTML)
|
|
9
|
-
* - Insecure eval() usage
|
|
10
|
-
* - Missing auth patterns
|
|
11
|
-
* - Insecure crypto usage
|
|
12
|
-
*
|
|
13
|
-
* ⚠️ DISCLAIMER: This is a heuristic regex-based pattern scanner, NOT a
|
|
14
|
-
* full static analysis tool. It may produce false positives (e.g., test
|
|
15
|
-
* fixtures containing 'password') and cannot detect indirect vulnerabilities
|
|
16
|
-
* (e.g., SQL injection via variable indirection). For production security
|
|
17
|
-
* auditing, supplement with dedicated tools like Semgrep, CodeQL, or Snyk.
|
|
18
|
-
*
|
|
19
|
-
* Usage:
|
|
20
|
-
* node .agent/scripts/security_scan.js .
|
|
21
|
-
* node .agent/scripts/security_scan.js . --severity high
|
|
22
|
-
* node .agent/scripts/security_scan.js . --files src/auth.ts src/db.ts
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
'use strict';
|
|
26
|
-
|
|
27
|
-
const fs = require('fs');
|
|
28
|
-
const path = require('path');
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
//
|
|
58
|
-
[/(?:
|
|
59
|
-
[/(?:
|
|
60
|
-
[
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
[/
|
|
65
|
-
[/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
[
|
|
70
|
-
[/
|
|
71
|
-
[/
|
|
72
|
-
|
|
73
|
-
//
|
|
74
|
-
[
|
|
75
|
-
[/
|
|
76
|
-
[/
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
[/
|
|
81
|
-
[/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
[
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
*
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
console.log(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
for (const sev of ['critical', 'high', 'medium', 'low']) {
|
|
278
|
-
const c = bySeverity[sev] || 0;
|
|
279
|
-
if (c > 0) {
|
|
280
|
-
const color = SEVERITY_COLORS[sev] || '';
|
|
281
|
-
console.log(` ${color}${sev.toUpperCase()}: ${c}${RESET}`);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (count === 0) {
|
|
286
|
-
console.log(` ${GREEN}✅ No issues found — scan passed${RESET}`);
|
|
287
|
-
} else {
|
|
288
|
-
const criticalHigh = (bySeverity.critical || 0) + (bySeverity.high || 0);
|
|
289
|
-
if (criticalHigh > 0) {
|
|
290
|
-
console.log(`\n ${RED}${BOLD}⚠️ ${criticalHigh} critical/high issue(s) require immediate attention${RESET}`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
process.exit((bySeverity.critical || 0) > 0 ? 1 : 0);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
// ━━━ Exports for testing & programmatic use ━━━
|
|
299
|
-
module.exports = { scanFile, scanDirectory, printFindings, PATTERNS, SEVERITY_RANK };
|
|
300
|
-
|
|
301
|
-
if (require.main === module) {
|
|
302
|
-
main();
|
|
303
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* security_scan.js — Deep security scanner for the Tribunal Agent Kit.
|
|
4
|
+
*
|
|
5
|
+
* Checks for OWASP Top 10 patterns in source code:
|
|
6
|
+
* - Hardcoded secrets and credentials
|
|
7
|
+
* - SQL injection patterns (string concatenation in queries)
|
|
8
|
+
* - XSS-prone code (innerHTML, dangerouslySetInnerHTML)
|
|
9
|
+
* - Insecure eval() usage
|
|
10
|
+
* - Missing auth patterns
|
|
11
|
+
* - Insecure crypto usage
|
|
12
|
+
*
|
|
13
|
+
* ⚠️ DISCLAIMER: This is a heuristic regex-based pattern scanner, NOT a
|
|
14
|
+
* full static analysis tool. It may produce false positives (e.g., test
|
|
15
|
+
* fixtures containing 'password') and cannot detect indirect vulnerabilities
|
|
16
|
+
* (e.g., SQL injection via variable indirection). For production security
|
|
17
|
+
* auditing, supplement with dedicated tools like Semgrep, CodeQL, or Snyk.
|
|
18
|
+
*
|
|
19
|
+
* Usage:
|
|
20
|
+
* node .agent/scripts/security_scan.js .
|
|
21
|
+
* node .agent/scripts/security_scan.js . --severity high
|
|
22
|
+
* node .agent/scripts/security_scan.js . --files src/auth.ts src/db.ts
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
'use strict';
|
|
26
|
+
|
|
27
|
+
const fs = require('fs');
|
|
28
|
+
const path = require('path');
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
RED, GREEN, YELLOW, BLUE, MAGENTA, BOLD, DIM, CYAN, RESET,
|
|
32
|
+
banner, sectionHeader, timer, formatMs,
|
|
33
|
+
} = require('./_colors');
|
|
34
|
+
|
|
35
|
+
const { walkDir, SOURCE_EXTENSIONS } = require('./_utils');
|
|
36
|
+
|
|
37
|
+
// ── Security-specific source extensions (broader than default) ──────────────
|
|
38
|
+
const SCAN_EXTENSIONS = new Set([...SOURCE_EXTENSIONS, '.py', '.go', '.java', '.rb']);
|
|
39
|
+
|
|
40
|
+
const SEVERITY_COLORS = {
|
|
41
|
+
critical: RED + BOLD,
|
|
42
|
+
high: RED,
|
|
43
|
+
medium: YELLOW,
|
|
44
|
+
low: BLUE,
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
48
|
+
|
|
49
|
+
// Pattern definitions: [regex, severity, category, message]
|
|
50
|
+
const PATTERNS = [
|
|
51
|
+
// Secrets
|
|
52
|
+
[/(?:password|passwd|pwd)\s*=\s*["'][^"']+["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded password detected'],
|
|
53
|
+
[/(?:api_key|apikey|api_secret)\s*=\s*["'][^"']+["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded API key detected'],
|
|
54
|
+
[/(?:secret|token|auth_token)\s*=\s*["'][A-Za-z0-9+/=]{16,}["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded secret/token detected'],
|
|
55
|
+
[/(?:PRIVATE_KEY|private_key)\s*=\s*["']/i, 'critical', 'Hardcoded Secret', 'Hardcoded private key detected'],
|
|
56
|
+
|
|
57
|
+
// SQL Injection
|
|
58
|
+
[/(?:query|execute|raw)\s*\(\s*[`"'].*\$\{/i, 'high', 'SQL Injection', 'String interpolation in SQL query — use parameterized queries'],
|
|
59
|
+
[/(?:query|execute|raw)\s*\(\s*["'].*\+\s*(?:req|input|params|body)/i, 'high', 'SQL Injection', 'String concatenation with user input in SQL'],
|
|
60
|
+
[/\.raw\s*\(\s*`/, 'medium', 'SQL Injection', 'Raw query with template literal — verify inputs are sanitized'],
|
|
61
|
+
|
|
62
|
+
// XSS
|
|
63
|
+
[/\.innerHTML\s*=/, 'high', 'XSS', 'Direct innerHTML assignment — use textContent or a sanitizer'],
|
|
64
|
+
[/dangerouslySetInnerHTML/, 'medium', 'XSS', 'dangerouslySetInnerHTML used — ensure input is sanitized'],
|
|
65
|
+
[/document\.write\s*\(/, 'high', 'XSS', 'document.write() is an XSS vector'],
|
|
66
|
+
|
|
67
|
+
// Insecure Functions
|
|
68
|
+
[/\beval\s*\(/, 'high', 'Code Injection', 'eval() is a code injection vector — avoid entirely'],
|
|
69
|
+
[/new\s+Function\s*\(/, 'high', 'Code Injection', 'new Function() is equivalent to eval()'],
|
|
70
|
+
[/child_process\.exec\s*\(/, 'medium', 'Command Injection', 'exec() with unsanitized input is a command injection vector'],
|
|
71
|
+
[/subprocess\.call\s*\(\s*[^,\]]*\bshell\s*=\s*True/, 'high', 'Command Injection', 'subprocess with shell=True — use shell=False and pass args as list'],
|
|
72
|
+
|
|
73
|
+
// Crypto
|
|
74
|
+
[/createHash\s*\(\s*["']md5["']/, 'medium', 'Weak Crypto', 'MD5 is cryptographically broken — use SHA-256+'],
|
|
75
|
+
[/createHash\s*\(\s*["']sha1["']/, 'medium', 'Weak Crypto', 'SHA-1 is deprecated — use SHA-256+'],
|
|
76
|
+
[/Math\.random\s*\(/, 'low', 'Weak Randomness', 'Math.random() is not cryptographically secure — use crypto.randomBytes()'],
|
|
77
|
+
|
|
78
|
+
// Auth Issues
|
|
79
|
+
[/algorithms\s*:\s*\[\s*["']none["']/, 'critical', 'Auth Bypass', "JWT 'none' algorithm allows auth bypass"],
|
|
80
|
+
[/verify\s*:\s*false/, 'high', 'Auth Bypass', 'SSL/TLS verification disabled'],
|
|
81
|
+
[/rejectUnauthorized\s*:\s*false/, 'high', 'Auth Bypass', 'TLS certificate validation disabled'],
|
|
82
|
+
|
|
83
|
+
// Information Disclosure
|
|
84
|
+
[/console\.log\s*\(.*(?:password|secret|token|key)/i, 'medium', 'Info Disclosure', 'Sensitive data logged to console'],
|
|
85
|
+
[/\.env(?:\.local|\.production)/, 'low', 'Info Disclosure', 'Env file reference — ensure not committed to git'],
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Scan a single file for security patterns.
|
|
91
|
+
* @param {string} filepath - Absolute path to the file.
|
|
92
|
+
* @param {string} projectRoot - Project root for relative path computation.
|
|
93
|
+
* @returns {Array<{severity:string, category:string, file:string, line:number, message:string, snippet:string}>}
|
|
94
|
+
*/
|
|
95
|
+
function scanFile(filepath, projectRoot) {
|
|
96
|
+
const findings = [];
|
|
97
|
+
const relPath = path.relative(projectRoot, filepath);
|
|
98
|
+
|
|
99
|
+
let content;
|
|
100
|
+
try {
|
|
101
|
+
content = fs.readFileSync(filepath, 'utf8');
|
|
102
|
+
} catch {
|
|
103
|
+
return findings;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const lines = content.split('\n');
|
|
107
|
+
for (let i = 0; i < lines.length; i++) {
|
|
108
|
+
const stripped = lines[i].trim();
|
|
109
|
+
// Skip comments
|
|
110
|
+
if (stripped.startsWith('//') || stripped.startsWith('#') || stripped.startsWith('*')) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
for (const [pattern, severity, category, message] of PATTERNS) {
|
|
115
|
+
if (pattern.test(stripped)) {
|
|
116
|
+
findings.push({
|
|
117
|
+
severity,
|
|
118
|
+
category,
|
|
119
|
+
file: relPath,
|
|
120
|
+
line: i + 1,
|
|
121
|
+
message,
|
|
122
|
+
snippet: stripped.slice(0, 120),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return findings;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Scan all source files in a directory.
|
|
134
|
+
* PERFORMANCE FIX: Uses shared walkDir from _utils.js and pushes findings
|
|
135
|
+
* individually instead of using spread operator (eliminates O(n²) array growth).
|
|
136
|
+
*
|
|
137
|
+
* @param {string} projectRoot - Root directory to scan.
|
|
138
|
+
* @param {string[]|null} targetFiles - Specific files to scan, or null for full scan.
|
|
139
|
+
* @returns {Array} Array of finding objects.
|
|
140
|
+
*/
|
|
141
|
+
function scanDirectory(projectRoot, targetFiles) {
|
|
142
|
+
const allFindings = [];
|
|
143
|
+
|
|
144
|
+
if (targetFiles && targetFiles.length > 0) {
|
|
145
|
+
for (const fpath of targetFiles) {
|
|
146
|
+
const absPath = path.isAbsolute(fpath) ? fpath : path.join(projectRoot, fpath);
|
|
147
|
+
if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) {
|
|
148
|
+
// FIX: Push individually instead of spread to avoid O(n²)
|
|
149
|
+
const fileFindings = scanFile(absPath, projectRoot);
|
|
150
|
+
for (const f of fileFindings) allFindings.push(f);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return allFindings;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const files = walkDir(projectRoot, { extensions: SCAN_EXTENSIONS });
|
|
157
|
+
|
|
158
|
+
for (const filepath of files) {
|
|
159
|
+
// FIX: Push individually instead of spread to avoid O(n²)
|
|
160
|
+
const fileFindings = scanFile(filepath, projectRoot);
|
|
161
|
+
for (const f of fileFindings) allFindings.push(f);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return allFindings;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Print findings filtered by minimum severity. Returns count of displayed findings.
|
|
170
|
+
*/
|
|
171
|
+
function printFindings(findings, minSeverity) {
|
|
172
|
+
const minRank = SEVERITY_RANK[minSeverity] ?? 3;
|
|
173
|
+
const filtered = findings
|
|
174
|
+
.filter(f => (SEVERITY_RANK[f.severity] ?? 3) <= minRank)
|
|
175
|
+
.sort((a, b) => (SEVERITY_RANK[a.severity] ?? 3) - (SEVERITY_RANK[b.severity] ?? 3));
|
|
176
|
+
|
|
177
|
+
if (filtered.length === 0) {
|
|
178
|
+
console.log(`\n ${GREEN}✅ No security issues found at severity '${minSeverity}' or above${RESET}`);
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
let currentCategory = '';
|
|
183
|
+
for (const finding of filtered) {
|
|
184
|
+
if (finding.category !== currentCategory) {
|
|
185
|
+
currentCategory = finding.category;
|
|
186
|
+
console.log(`\n ${BOLD}${currentCategory}${RESET}`);
|
|
187
|
+
}
|
|
188
|
+
const color = SEVERITY_COLORS[finding.severity] || '';
|
|
189
|
+
console.log(` ${color}[${finding.severity.toUpperCase()}]${RESET} ${finding.file}:${finding.line}`);
|
|
190
|
+
console.log(` ${finding.message}`);
|
|
191
|
+
console.log(` ${MAGENTA}→ ${finding.snippet}${RESET}`);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return filtered.length;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
function main() {
|
|
199
|
+
const args = { path: null, severity: 'low', files: null };
|
|
200
|
+
const raw = process.argv.slice(2);
|
|
201
|
+
|
|
202
|
+
for (let i = 0; i < raw.length; i++) {
|
|
203
|
+
if (raw[i] === '--severity' && raw[i + 1]) {
|
|
204
|
+
args.severity = raw[++i];
|
|
205
|
+
} else if (raw[i] === '--files') {
|
|
206
|
+
args.files = [];
|
|
207
|
+
while (i + 1 < raw.length && !raw[i + 1].startsWith('--')) {
|
|
208
|
+
args.files.push(raw[++i]);
|
|
209
|
+
}
|
|
210
|
+
} else if (!raw[i].startsWith('--') && !args.path) {
|
|
211
|
+
args.path = raw[i];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!args.path) {
|
|
216
|
+
console.error(`Usage: node security_scan.js <path> [--severity critical|high|medium|low] [--files ...]`);
|
|
217
|
+
process.exit(1);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const projectRoot = path.resolve(args.path);
|
|
221
|
+
if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
|
|
222
|
+
console.error(` ${RED}❌ Directory not found: ${projectRoot}${RESET}`);
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
console.log(banner('security_scan.js', {
|
|
227
|
+
Project: projectRoot,
|
|
228
|
+
Severity: `${args.severity}+`,
|
|
229
|
+
}));
|
|
230
|
+
|
|
231
|
+
const elapsed = timer();
|
|
232
|
+
const findings = scanDirectory(projectRoot, args.files);
|
|
233
|
+
const scanMs = elapsed();
|
|
234
|
+
|
|
235
|
+
const count = printFindings(findings, args.severity);
|
|
236
|
+
|
|
237
|
+
// ━━━ Summary ━━━
|
|
238
|
+
console.log(`\n${BOLD}${CYAN}━━━ Security Scan Summary ━━━${RESET}`);
|
|
239
|
+
|
|
240
|
+
const bySeverity = {};
|
|
241
|
+
for (const f of findings) {
|
|
242
|
+
bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const uniqueFiles = new Set(findings.map(f => f.file)).size;
|
|
246
|
+
|
|
247
|
+
for (const sev of ['critical', 'high', 'medium', 'low']) {
|
|
248
|
+
const c = bySeverity[sev] || 0;
|
|
249
|
+
if (c > 0) {
|
|
250
|
+
const color = SEVERITY_COLORS[sev] || '';
|
|
251
|
+
console.log(` ${color}${sev.toUpperCase()}: ${c}${RESET}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
console.log(`\n ${DIM}Scanned in ${formatMs(scanMs)} — ${findings.length} findings across ${uniqueFiles} file(s)${RESET}`);
|
|
256
|
+
|
|
257
|
+
if (count === 0) {
|
|
258
|
+
console.log(` ${GREEN}✅ No issues found — scan passed${RESET}`);
|
|
259
|
+
} else {
|
|
260
|
+
const criticalHigh = (bySeverity.critical || 0) + (bySeverity.high || 0);
|
|
261
|
+
if (criticalHigh > 0) {
|
|
262
|
+
console.log(`\n ${RED}${BOLD}⚠️ ${criticalHigh} critical/high issue(s) require immediate attention${RESET}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
console.log();
|
|
266
|
+
|
|
267
|
+
process.exit((bySeverity.critical || 0) > 0 ? 1 : 0);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
// ━━━ Exports for testing & programmatic use ━━━
|
|
272
|
+
module.exports = { scanFile, scanDirectory, printFindings, PATTERNS, SEVERITY_RANK };
|
|
273
|
+
|
|
274
|
+
if (require.main === module) {
|
|
275
|
+
main();
|
|
276
|
+
}
|
|
@@ -20,13 +20,7 @@ const path = require('path');
|
|
|
20
20
|
|
|
21
21
|
const STATE_FILE = ".agent_session.json";
|
|
22
22
|
|
|
23
|
-
const GREEN
|
|
24
|
-
const YELLOW = "\x1b[93m";
|
|
25
|
-
const BLUE = "\x1b[94m";
|
|
26
|
-
const CYAN = "\x1b[96m";
|
|
27
|
-
const RED = "\x1b[91m";
|
|
28
|
-
const BOLD = "\x1b[1m";
|
|
29
|
-
const RESET = "\x1b[0m";
|
|
23
|
+
const { GREEN, YELLOW, BLUE, CYAN, RED, BOLD, RESET } = require('./_colors');
|
|
30
24
|
|
|
31
25
|
const VALID_COMMANDS = new Set(["save", "load", "show", "clear", "status", "tag", "list", "export"]);
|
|
32
26
|
const LIST_PAGE_SIZE = 10;
|
|
@@ -31,14 +31,7 @@ const { execSync } = require('child_process');
|
|
|
31
31
|
const readline = require('readline');
|
|
32
32
|
|
|
33
33
|
// ── Colours ──────────────────────────────────────────────────────────────────
|
|
34
|
-
const GREEN
|
|
35
|
-
const YELLOW = '\x1b[93m';
|
|
36
|
-
const CYAN = '\x1b[96m';
|
|
37
|
-
const RED = '\x1b[91m';
|
|
38
|
-
const BLUE = '\x1b[94m';
|
|
39
|
-
const BOLD = '\x1b[1m';
|
|
40
|
-
const DIM = '\x1b[2m';
|
|
41
|
-
const RESET = '\x1b[0m';
|
|
34
|
+
const { GREEN, YELLOW, CYAN, RED, BLUE, BOLD, DIM, RESET } = require('./_colors');
|
|
42
35
|
|
|
43
36
|
// ── Find .agent directory ─────────────────────────────────────────────────────
|
|
44
37
|
function findAgentDir() {
|
|
@@ -20,13 +20,7 @@ const fs = require('fs');
|
|
|
20
20
|
const path = require('path');
|
|
21
21
|
const { execFileSync } = require('child_process');
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
const CYAN = '\x1b[96m';
|
|
25
|
-
const GREEN = '\x1b[92m';
|
|
26
|
-
const YELLOW = '\x1b[93m';
|
|
27
|
-
const RED = '\x1b[91m';
|
|
28
|
-
const BOLD = '\x1b[1m';
|
|
29
|
-
const RESET = '\x1b[0m';
|
|
23
|
+
const { CYAN, GREEN, YELLOW, RED, BOLD, RESET } = require('./_colors');
|
|
30
24
|
|
|
31
25
|
const REPORT_FILE = 'skill-integration-report.md';
|
|
32
26
|
|