tribunal-kit 5.7.0 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.agent/ARCHITECTURE.md +6 -7
- package/.agent/agents/frontend-reviewer.md +13 -0
- package/.agent/agents/frontend-specialist.md +14 -0
- package/.agent/agents/logic-reviewer.md +11 -0
- package/.agent/agents/orchestrator.md +15 -0
- package/.agent/agents/security-auditor.md +13 -0
- package/.agent/agents/ui-ux-auditor.md +7 -31
- package/.agent/history/memory/.memory.idx +766 -0
- package/.agent/history/memory/MEMORY.md +62 -0
- package/.agent/routing_index.json +694 -714
- package/.agent/rules/GEMINI.md +58 -8
- package/.agent/scripts/_colors.js +131 -89
- package/.agent/scripts/_utils.js +163 -128
- package/.agent/scripts/auto_preview.js +207 -197
- package/.agent/scripts/bundle_analyzer.js +227 -192
- package/.agent/scripts/case_law_manager.js +991 -689
- package/.agent/scripts/checklist.js +233 -190
- package/.agent/scripts/context_broker.js +930 -605
- package/.agent/scripts/dependency_analyzer.js +275 -184
- package/.agent/scripts/graph_builder.js +412 -341
- package/.agent/scripts/graph_visualizer.js +392 -390
- package/.agent/scripts/graph_zoom.js +198 -156
- package/.agent/scripts/inner_loop_validator.js +523 -445
- package/.agent/scripts/lint_runner.js +199 -157
- package/.agent/scripts/marathon_harness.js +819 -661
- package/.agent/scripts/minify_context.js +115 -100
- package/.agent/scripts/mutation_runner.js +321 -280
- package/.agent/scripts/prompt_compiler.js +62 -42
- package/.agent/scripts/schema_validator.js +373 -280
- package/.agent/scripts/security_scan.js +333 -190
- package/.agent/scripts/session_manager.js +306 -270
- package/.agent/scripts/skill_evolution.js +810 -637
- package/.agent/scripts/skill_integrator.js +327 -307
- package/.agent/scripts/strengthen_skills.js +203 -193
- package/.agent/scripts/swarm_dispatcher.js +558 -457
- package/.agent/scripts/test_runner.js +178 -152
- package/.agent/scripts/verify_all.js +200 -168
- package/.agent/skills/fabel-protocol/SKILL.md +235 -0
- package/.agent/skills/thinking-protocol/SKILL.md +27 -0
- package/.agent/workflows/generate.md +1 -1
- package/.agent/workflows/tribunal-speed.md +1 -1
- package/README.md +53 -53
- package/bin/mcp-server.js +460 -175
- package/bin/tribunal-kit.js +1245 -987
- package/bin/wrapper.js +104 -74
- package/dist/cli.js +31 -0
- package/dist/commands/case.js +23 -0
- package/dist/commands/compile.js +84 -0
- package/dist/commands/init.js +42 -0
- package/dist/commands/learn.js +57 -0
- package/dist/commands/memory.js +456 -0
- package/package.json +2 -2
- package/scripts/benchmark.js +162 -125
- package/scripts/changelog.js +196 -168
- package/scripts/sync-version.js +94 -81
- package/scripts/validate-payload.js +85 -78
|
@@ -22,70 +22,190 @@
|
|
|
22
22
|
* node .agent/scripts/security_scan.js . --files src/auth.ts src/db.ts
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
"use strict";
|
|
26
26
|
|
|
27
|
-
const fs
|
|
28
|
-
const path = require(
|
|
27
|
+
const fs = require("fs");
|
|
28
|
+
const path = require("path");
|
|
29
29
|
|
|
30
30
|
const {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
RED,
|
|
32
|
+
GREEN,
|
|
33
|
+
YELLOW,
|
|
34
|
+
BLUE,
|
|
35
|
+
MAGENTA,
|
|
36
|
+
BOLD,
|
|
37
|
+
DIM,
|
|
38
|
+
CYAN,
|
|
39
|
+
RESET,
|
|
40
|
+
banner,
|
|
41
|
+
timer,
|
|
42
|
+
formatMs,
|
|
43
|
+
} = require("./_colors");
|
|
44
|
+
|
|
45
|
+
const { walkDir, SOURCE_EXTENSIONS } = require("./_utils");
|
|
36
46
|
|
|
37
47
|
// ── Security-specific source extensions (broader than default) ──────────────
|
|
38
|
-
const SCAN_EXTENSIONS = new Set([
|
|
48
|
+
const SCAN_EXTENSIONS = new Set([
|
|
49
|
+
...SOURCE_EXTENSIONS,
|
|
50
|
+
".py",
|
|
51
|
+
".go",
|
|
52
|
+
".java",
|
|
53
|
+
".rb",
|
|
54
|
+
]);
|
|
39
55
|
|
|
40
56
|
const SEVERITY_COLORS = {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
57
|
+
critical: RED + BOLD,
|
|
58
|
+
high: RED,
|
|
59
|
+
medium: YELLOW,
|
|
60
|
+
low: BLUE,
|
|
45
61
|
};
|
|
46
62
|
|
|
47
63
|
const SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3 };
|
|
48
64
|
|
|
49
65
|
// Pattern definitions: [regex, severity, category, message]
|
|
50
66
|
const PATTERNS = [
|
|
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
|
-
|
|
67
|
+
// Secrets
|
|
68
|
+
[
|
|
69
|
+
/(?:password|passwd|pwd)\s*=\s*["'][^"']+["']/i,
|
|
70
|
+
"critical",
|
|
71
|
+
"Hardcoded Secret",
|
|
72
|
+
"Hardcoded password detected",
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
/(?:api_key|apikey|api_secret)\s*=\s*["'][^"']+["']/i,
|
|
76
|
+
"critical",
|
|
77
|
+
"Hardcoded Secret",
|
|
78
|
+
"Hardcoded API key detected",
|
|
79
|
+
],
|
|
80
|
+
[
|
|
81
|
+
/(?:secret|token|auth_token)\s*=\s*["'][A-Za-z0-9+/=]{16,}["']/i,
|
|
82
|
+
"critical",
|
|
83
|
+
"Hardcoded Secret",
|
|
84
|
+
"Hardcoded secret/token detected",
|
|
85
|
+
],
|
|
86
|
+
[
|
|
87
|
+
/(?:PRIVATE_KEY|private_key)\s*=\s*["']/i,
|
|
88
|
+
"critical",
|
|
89
|
+
"Hardcoded Secret",
|
|
90
|
+
"Hardcoded private key detected",
|
|
91
|
+
],
|
|
92
|
+
|
|
93
|
+
// SQL Injection
|
|
94
|
+
[
|
|
95
|
+
/(?:query|execute|raw)\s*\(\s*[`"'].*\$\{/i,
|
|
96
|
+
"high",
|
|
97
|
+
"SQL Injection",
|
|
98
|
+
"String interpolation in SQL query — use parameterized queries",
|
|
99
|
+
],
|
|
100
|
+
[
|
|
101
|
+
/(?:query|execute|raw)\s*\(\s*["'].*\+\s*(?:req|input|params|body)/i,
|
|
102
|
+
"high",
|
|
103
|
+
"SQL Injection",
|
|
104
|
+
"String concatenation with user input in SQL",
|
|
105
|
+
],
|
|
106
|
+
[
|
|
107
|
+
/\.raw\s*\(\s*`/,
|
|
108
|
+
"medium",
|
|
109
|
+
"SQL Injection",
|
|
110
|
+
"Raw query with template literal — verify inputs are sanitized",
|
|
111
|
+
],
|
|
112
|
+
|
|
113
|
+
// XSS
|
|
114
|
+
[
|
|
115
|
+
/\.innerHTML\s*=/,
|
|
116
|
+
"high",
|
|
117
|
+
"XSS",
|
|
118
|
+
"Direct innerHTML assignment — use textContent or a sanitizer",
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
/dangerouslySetInnerHTML/,
|
|
122
|
+
"medium",
|
|
123
|
+
"XSS",
|
|
124
|
+
"dangerouslySetInnerHTML used — ensure input is sanitized",
|
|
125
|
+
],
|
|
126
|
+
[/document\.write\s*\(/, "high", "XSS", "document.write() is an XSS vector"],
|
|
127
|
+
|
|
128
|
+
// Insecure Functions
|
|
129
|
+
[
|
|
130
|
+
/\beval\s*\(/,
|
|
131
|
+
"high",
|
|
132
|
+
"Code Injection",
|
|
133
|
+
"eval() is a code injection vector — avoid entirely",
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
/new\s+Function\s*\(/,
|
|
137
|
+
"high",
|
|
138
|
+
"Code Injection",
|
|
139
|
+
"new Function() is equivalent to eval()",
|
|
140
|
+
],
|
|
141
|
+
[
|
|
142
|
+
/child_process\.exec\s*\(/,
|
|
143
|
+
"medium",
|
|
144
|
+
"Command Injection",
|
|
145
|
+
"exec() with unsanitized input is a command injection vector",
|
|
146
|
+
],
|
|
147
|
+
[
|
|
148
|
+
/subprocess\.call\s*\(\s*[^,\]]*\bshell\s*=\s*True/,
|
|
149
|
+
"high",
|
|
150
|
+
"Command Injection",
|
|
151
|
+
"subprocess with shell=True — use shell=False and pass args as list",
|
|
152
|
+
],
|
|
153
|
+
|
|
154
|
+
// Crypto
|
|
155
|
+
[
|
|
156
|
+
/createHash\s*\(\s*["']md5["']/,
|
|
157
|
+
"medium",
|
|
158
|
+
"Weak Crypto",
|
|
159
|
+
"MD5 is cryptographically broken — use SHA-256+",
|
|
160
|
+
],
|
|
161
|
+
[
|
|
162
|
+
/createHash\s*\(\s*["']sha1["']/,
|
|
163
|
+
"medium",
|
|
164
|
+
"Weak Crypto",
|
|
165
|
+
"SHA-1 is deprecated — use SHA-256+",
|
|
166
|
+
],
|
|
167
|
+
[
|
|
168
|
+
/Math\.random\s*\(/,
|
|
169
|
+
"low",
|
|
170
|
+
"Weak Randomness",
|
|
171
|
+
"Math.random() is not cryptographically secure — use crypto.randomBytes()",
|
|
172
|
+
],
|
|
173
|
+
|
|
174
|
+
// Auth Issues
|
|
175
|
+
[
|
|
176
|
+
/algorithms\s*:\s*\[\s*["']none["']/,
|
|
177
|
+
"critical",
|
|
178
|
+
"Auth Bypass",
|
|
179
|
+
"JWT 'none' algorithm allows auth bypass",
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
/verify\s*:\s*false/,
|
|
183
|
+
"high",
|
|
184
|
+
"Auth Bypass",
|
|
185
|
+
"SSL/TLS verification disabled",
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
/rejectUnauthorized\s*:\s*false/,
|
|
189
|
+
"high",
|
|
190
|
+
"Auth Bypass",
|
|
191
|
+
"TLS certificate validation disabled",
|
|
192
|
+
],
|
|
193
|
+
|
|
194
|
+
// Information Disclosure
|
|
195
|
+
[
|
|
196
|
+
/console\.log\s*\(.*(?:password|secret|token|key)/i,
|
|
197
|
+
"medium",
|
|
198
|
+
"Info Disclosure",
|
|
199
|
+
"Sensitive data logged to console",
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
/\.env(?:\.local|\.production)/,
|
|
203
|
+
"low",
|
|
204
|
+
"Info Disclosure",
|
|
205
|
+
"Env file reference — ensure not committed to git",
|
|
206
|
+
],
|
|
86
207
|
];
|
|
87
208
|
|
|
88
|
-
|
|
89
209
|
/**
|
|
90
210
|
* Scan a single file for security patterns.
|
|
91
211
|
* @param {string} filepath - Absolute path to the file.
|
|
@@ -93,42 +213,45 @@ const PATTERNS = [
|
|
|
93
213
|
* @returns {Array<{severity:string, category:string, file:string, line:number, message:string, snippet:string}>}
|
|
94
214
|
*/
|
|
95
215
|
function scanFile(filepath, projectRoot) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
216
|
+
const findings = [];
|
|
217
|
+
const relPath = path.relative(projectRoot, filepath);
|
|
218
|
+
|
|
219
|
+
let content;
|
|
220
|
+
try {
|
|
221
|
+
content = fs.readFileSync(filepath, "utf8");
|
|
222
|
+
} catch {
|
|
223
|
+
return findings;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const lines = content.split("\n");
|
|
227
|
+
for (let i = 0; i < lines.length; i++) {
|
|
228
|
+
const stripped = lines[i].trim();
|
|
229
|
+
// Skip comments
|
|
230
|
+
if (
|
|
231
|
+
stripped.startsWith("//") ||
|
|
232
|
+
stripped.startsWith("#") ||
|
|
233
|
+
stripped.startsWith("*")
|
|
234
|
+
) {
|
|
235
|
+
continue;
|
|
104
236
|
}
|
|
105
237
|
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
severity,
|
|
118
|
-
category,
|
|
119
|
-
file: relPath,
|
|
120
|
-
line: i + 1,
|
|
121
|
-
message,
|
|
122
|
-
snippet: stripped.slice(0, 120),
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
}
|
|
238
|
+
for (const [pattern, severity, category, message] of PATTERNS) {
|
|
239
|
+
if (pattern.test(stripped)) {
|
|
240
|
+
findings.push({
|
|
241
|
+
severity,
|
|
242
|
+
category,
|
|
243
|
+
file: relPath,
|
|
244
|
+
line: i + 1,
|
|
245
|
+
message,
|
|
246
|
+
snippet: stripped.slice(0, 120),
|
|
247
|
+
});
|
|
248
|
+
}
|
|
126
249
|
}
|
|
250
|
+
}
|
|
127
251
|
|
|
128
|
-
|
|
252
|
+
return findings;
|
|
129
253
|
}
|
|
130
254
|
|
|
131
|
-
|
|
132
255
|
/**
|
|
133
256
|
* Scan all source files in a directory.
|
|
134
257
|
* PERFORMANCE FIX: Uses shared walkDir from _utils.js and pushes findings
|
|
@@ -139,138 +262,158 @@ function scanFile(filepath, projectRoot) {
|
|
|
139
262
|
* @returns {Array} Array of finding objects.
|
|
140
263
|
*/
|
|
141
264
|
function scanDirectory(projectRoot, targetFiles) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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) {
|
|
265
|
+
const allFindings = [];
|
|
266
|
+
|
|
267
|
+
if (targetFiles && targetFiles.length > 0) {
|
|
268
|
+
for (const fpath of targetFiles) {
|
|
269
|
+
const absPath = path.isAbsolute(fpath)
|
|
270
|
+
? fpath
|
|
271
|
+
: path.join(projectRoot, fpath);
|
|
272
|
+
if (fs.existsSync(absPath) && fs.statSync(absPath).isFile()) {
|
|
159
273
|
// FIX: Push individually instead of spread to avoid O(n²)
|
|
160
|
-
const fileFindings = scanFile(
|
|
274
|
+
const fileFindings = scanFile(absPath, projectRoot);
|
|
161
275
|
for (const f of fileFindings) allFindings.push(f);
|
|
276
|
+
}
|
|
162
277
|
}
|
|
163
|
-
|
|
164
278
|
return allFindings;
|
|
165
|
-
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const files = walkDir(projectRoot, { extensions: SCAN_EXTENSIONS });
|
|
282
|
+
|
|
283
|
+
for (const filepath of files) {
|
|
284
|
+
// FIX: Push individually instead of spread to avoid O(n²)
|
|
285
|
+
const fileFindings = scanFile(filepath, projectRoot);
|
|
286
|
+
for (const f of fileFindings) allFindings.push(f);
|
|
287
|
+
}
|
|
166
288
|
|
|
289
|
+
return allFindings;
|
|
290
|
+
}
|
|
167
291
|
|
|
168
292
|
/**
|
|
169
293
|
* Print findings filtered by minimum severity. Returns count of displayed findings.
|
|
170
294
|
*/
|
|
171
295
|
function printFindings(findings, minSeverity) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
296
|
+
const minRank = SEVERITY_RANK[minSeverity] ?? 3;
|
|
297
|
+
const filtered = findings
|
|
298
|
+
.filter((f) => (SEVERITY_RANK[f.severity] ?? 3) <= minRank)
|
|
299
|
+
.sort(
|
|
300
|
+
(a, b) =>
|
|
301
|
+
(SEVERITY_RANK[a.severity] ?? 3) - (SEVERITY_RANK[b.severity] ?? 3),
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
if (filtered.length === 0) {
|
|
305
|
+
console.log(
|
|
306
|
+
`\n ${GREEN}✅ No security issues found at severity '${minSeverity}' or above${RESET}`,
|
|
307
|
+
);
|
|
308
|
+
return 0;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
let currentCategory = "";
|
|
312
|
+
for (const finding of filtered) {
|
|
313
|
+
if (finding.category !== currentCategory) {
|
|
314
|
+
currentCategory = finding.category;
|
|
315
|
+
console.log(`\n ${BOLD}${currentCategory}${RESET}`);
|
|
192
316
|
}
|
|
193
|
-
|
|
194
|
-
|
|
317
|
+
const color = SEVERITY_COLORS[finding.severity] || "";
|
|
318
|
+
console.log(
|
|
319
|
+
` ${color}[${finding.severity.toUpperCase()}]${RESET} ${finding.file}:${finding.line}`,
|
|
320
|
+
);
|
|
321
|
+
console.log(` ${finding.message}`);
|
|
322
|
+
console.log(` ${MAGENTA}→ ${finding.snippet}${RESET}`);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return filtered.length;
|
|
195
326
|
}
|
|
196
327
|
|
|
197
|
-
|
|
198
328
|
function main() {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
329
|
+
const args = { path: null, severity: "low", files: null };
|
|
330
|
+
const raw = process.argv.slice(2);
|
|
331
|
+
|
|
332
|
+
for (let i = 0; i < raw.length; i++) {
|
|
333
|
+
if (raw[i] === "--severity" && raw[i + 1]) {
|
|
334
|
+
args.severity = raw[++i];
|
|
335
|
+
} else if (raw[i] === "--files") {
|
|
336
|
+
args.files = [];
|
|
337
|
+
while (i + 1 < raw.length && !raw[i + 1].startsWith("--")) {
|
|
338
|
+
args.files.push(raw[++i]);
|
|
339
|
+
}
|
|
340
|
+
} else if (!raw[i].startsWith("--") && !args.path) {
|
|
341
|
+
args.path = raw[i];
|
|
213
342
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (!args.path) {
|
|
346
|
+
console.error(
|
|
347
|
+
`Usage: node security_scan.js <path> [--severity critical|high|medium|low] [--files ...]`,
|
|
348
|
+
);
|
|
349
|
+
process.exit(1);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
const projectRoot = path.resolve(args.path);
|
|
353
|
+
if (!fs.existsSync(projectRoot) || !fs.statSync(projectRoot).isDirectory()) {
|
|
354
|
+
console.error(` ${RED}❌ Directory not found: ${projectRoot}${RESET}`);
|
|
355
|
+
process.exit(1);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
console.log(
|
|
359
|
+
banner("security_scan.js", {
|
|
360
|
+
Project: projectRoot,
|
|
361
|
+
Severity: `${args.severity}+`,
|
|
362
|
+
}),
|
|
363
|
+
);
|
|
364
|
+
|
|
365
|
+
const elapsed = timer();
|
|
366
|
+
const findings = scanDirectory(projectRoot, args.files);
|
|
367
|
+
const scanMs = elapsed();
|
|
368
|
+
|
|
369
|
+
const count = printFindings(findings, args.severity);
|
|
370
|
+
|
|
371
|
+
// ━━━ Summary ━━━
|
|
372
|
+
console.log(`\n${BOLD}${CYAN}━━━ Security Scan Summary ━━━${RESET}`);
|
|
373
|
+
|
|
374
|
+
const bySeverity = {};
|
|
375
|
+
for (const f of findings) {
|
|
376
|
+
bySeverity[f.severity] = (bySeverity[f.severity] || 0) + 1;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const uniqueFiles = new Set(findings.map((f) => f.file)).size;
|
|
380
|
+
|
|
381
|
+
for (const sev of ["critical", "high", "medium", "low"]) {
|
|
382
|
+
const c = bySeverity[sev] || 0;
|
|
383
|
+
if (c > 0) {
|
|
384
|
+
const color = SEVERITY_COLORS[sev] || "";
|
|
385
|
+
console.log(` ${color}${sev.toUpperCase()}: ${c}${RESET}`);
|
|
218
386
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
console.log(
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
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;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
console.log(
|
|
390
|
+
`\n ${DIM}Scanned in ${formatMs(scanMs)} — ${findings.length} findings across ${uniqueFiles} file(s)${RESET}`,
|
|
391
|
+
);
|
|
392
|
+
|
|
393
|
+
if (count === 0) {
|
|
394
|
+
console.log(` ${GREEN}✅ No issues found — scan passed${RESET}`);
|
|
395
|
+
} else {
|
|
396
|
+
const criticalHigh = (bySeverity.critical || 0) + (bySeverity.high || 0);
|
|
397
|
+
if (criticalHigh > 0) {
|
|
398
|
+
console.log(
|
|
399
|
+
`\n ${RED}${BOLD}⚠️ ${criticalHigh} critical/high issue(s) require immediate attention${RESET}`,
|
|
400
|
+
);
|
|
243
401
|
}
|
|
402
|
+
}
|
|
403
|
+
console.log();
|
|
244
404
|
|
|
245
|
-
|
|
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);
|
|
405
|
+
process.exit((bySeverity.critical || 0) > 0 ? 1 : 0);
|
|
268
406
|
}
|
|
269
407
|
|
|
270
|
-
|
|
271
408
|
// ━━━ Exports for testing & programmatic use ━━━
|
|
272
|
-
module.exports = {
|
|
409
|
+
module.exports = {
|
|
410
|
+
scanFile,
|
|
411
|
+
scanDirectory,
|
|
412
|
+
printFindings,
|
|
413
|
+
PATTERNS,
|
|
414
|
+
SEVERITY_RANK,
|
|
415
|
+
};
|
|
273
416
|
|
|
274
417
|
if (require.main === module) {
|
|
275
|
-
|
|
418
|
+
main();
|
|
276
419
|
}
|