@cencori/scan 0.1.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/dist/cli.mjs ADDED
@@ -0,0 +1,656 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import { program } from "commander";
5
+ import chalk from "chalk";
6
+ import ora from "ora";
7
+
8
+ // src/scanner/index.ts
9
+ import * as fs from "fs";
10
+ import * as path from "path";
11
+ import { glob } from "glob";
12
+
13
+ // src/scanner/patterns.ts
14
+ var SECRET_PATTERNS = [
15
+ // OpenAI
16
+ {
17
+ name: "OpenAI API Key",
18
+ provider: "OpenAI",
19
+ pattern: /sk-[a-zA-Z0-9]{20}T3BlbkFJ[a-zA-Z0-9]{20}/g,
20
+ severity: "critical"
21
+ },
22
+ {
23
+ name: "OpenAI Project Key",
24
+ provider: "OpenAI",
25
+ pattern: /sk-proj-[a-zA-Z0-9_-]{80,}/g,
26
+ severity: "critical"
27
+ },
28
+ // Anthropic
29
+ {
30
+ name: "Anthropic API Key",
31
+ provider: "Anthropic",
32
+ pattern: /sk-ant-[a-zA-Z0-9-]{90,}/g,
33
+ severity: "critical"
34
+ },
35
+ // Google
36
+ {
37
+ name: "Google API Key",
38
+ provider: "Google",
39
+ pattern: /AIza[0-9A-Za-z_-]{35}/g,
40
+ severity: "critical"
41
+ },
42
+ // Supabase
43
+ {
44
+ name: "Supabase Service Role Key",
45
+ provider: "Supabase",
46
+ pattern: /eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9\.[a-zA-Z0-9_-]+\.[a-zA-Z0-9_-]+/g,
47
+ severity: "critical"
48
+ },
49
+ {
50
+ name: "Supabase Anon Key (if hardcoded)",
51
+ provider: "Supabase",
52
+ pattern: /SUPABASE_ANON_KEY\s*[:=]\s*["']eyJ[^"']+["']/g,
53
+ severity: "medium"
54
+ },
55
+ // Stripe
56
+ {
57
+ name: "Stripe Secret Key",
58
+ provider: "Stripe",
59
+ pattern: /sk_live_[0-9a-zA-Z]{24,}/g,
60
+ severity: "critical"
61
+ },
62
+ {
63
+ name: "Stripe Test Key",
64
+ provider: "Stripe",
65
+ pattern: /sk_test_[0-9a-zA-Z]{24,}/g,
66
+ severity: "medium"
67
+ },
68
+ // AWS
69
+ {
70
+ name: "AWS Access Key ID",
71
+ provider: "AWS",
72
+ pattern: /AKIA[0-9A-Z]{16}/g,
73
+ severity: "critical"
74
+ },
75
+ {
76
+ name: "AWS Secret Access Key",
77
+ provider: "AWS",
78
+ pattern: /aws_secret_access_key\s*[:=]\s*["'][A-Za-z0-9/+=]{40}["']/gi,
79
+ severity: "critical"
80
+ },
81
+ // GitHub
82
+ {
83
+ name: "GitHub Personal Access Token",
84
+ provider: "GitHub",
85
+ pattern: /ghp_[a-zA-Z0-9]{36}/g,
86
+ severity: "critical"
87
+ },
88
+ {
89
+ name: "GitHub OAuth Token",
90
+ provider: "GitHub",
91
+ pattern: /gho_[a-zA-Z0-9]{36}/g,
92
+ severity: "critical"
93
+ },
94
+ // Telegram
95
+ {
96
+ name: "Telegram Bot Token",
97
+ provider: "Telegram",
98
+ pattern: /[0-9]{9,10}:[a-zA-Z0-9_-]{35}/g,
99
+ severity: "high"
100
+ },
101
+ // Discord
102
+ {
103
+ name: "Discord Bot Token",
104
+ provider: "Discord",
105
+ pattern: /[MN][A-Za-z\d]{23,}\.[\w-]{6}\.[\w-]{27}/g,
106
+ severity: "high"
107
+ },
108
+ // Slack
109
+ {
110
+ name: "Slack Bot Token",
111
+ provider: "Slack",
112
+ pattern: /xoxb-[0-9]{11}-[0-9]{11}-[a-zA-Z0-9]{24}/g,
113
+ severity: "high"
114
+ },
115
+ // SendGrid
116
+ {
117
+ name: "SendGrid API Key",
118
+ provider: "SendGrid",
119
+ pattern: /SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43}/g,
120
+ severity: "high"
121
+ },
122
+ // Twilio
123
+ {
124
+ name: "Twilio API Key",
125
+ provider: "Twilio",
126
+ pattern: /SK[a-fA-F0-9]{32}/g,
127
+ severity: "high"
128
+ },
129
+ // Mailgun
130
+ {
131
+ name: "Mailgun API Key",
132
+ provider: "Mailgun",
133
+ pattern: /key-[a-zA-Z0-9]{32}/g,
134
+ severity: "high"
135
+ },
136
+ // Firebase
137
+ {
138
+ name: "Firebase Database URL",
139
+ provider: "Firebase",
140
+ pattern: /https:\/\/[a-z0-9-]+\.firebaseio\.com/g,
141
+ severity: "medium"
142
+ },
143
+ // Generic patterns
144
+ {
145
+ name: "Private Key",
146
+ provider: "Generic",
147
+ pattern: /-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----/g,
148
+ severity: "critical"
149
+ },
150
+ {
151
+ name: "Generic API Key Assignment",
152
+ provider: "Generic",
153
+ pattern: /(api_key|apikey|api_secret|secret_key)\s*[:=]\s*["'][a-zA-Z0-9_-]{20,}["']/gi,
154
+ severity: "high"
155
+ },
156
+ {
157
+ name: "Password Assignment",
158
+ provider: "Generic",
159
+ pattern: /(password|passwd|pwd)\s*[:=]\s*["'][^"']{8,}["']/gi,
160
+ severity: "high"
161
+ },
162
+ // Replicate
163
+ {
164
+ name: "Replicate API Token",
165
+ provider: "Replicate",
166
+ pattern: /r8_[a-zA-Z0-9]{38}/g,
167
+ severity: "critical"
168
+ },
169
+ // Hugging Face
170
+ {
171
+ name: "Hugging Face Token",
172
+ provider: "Hugging Face",
173
+ pattern: /hf_[a-zA-Z0-9]{34}/g,
174
+ severity: "critical"
175
+ },
176
+ // Cohere
177
+ {
178
+ name: "Cohere API Key",
179
+ provider: "Cohere",
180
+ pattern: /[a-zA-Z0-9]{40}/g,
181
+ // Less specific, check context
182
+ severity: "medium"
183
+ }
184
+ ];
185
+ var PII_PATTERNS = [
186
+ {
187
+ name: "Email Address",
188
+ pattern: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g,
189
+ severity: "medium"
190
+ },
191
+ {
192
+ name: "Phone Number (US)",
193
+ pattern: /(\+1[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/g,
194
+ severity: "medium"
195
+ },
196
+ {
197
+ name: "Phone Number (International)",
198
+ pattern: /\+[1-9]\d{1,14}/g,
199
+ severity: "medium"
200
+ },
201
+ {
202
+ name: "Social Security Number",
203
+ pattern: /\b\d{3}-\d{2}-\d{4}\b/g,
204
+ severity: "high"
205
+ },
206
+ {
207
+ name: "Credit Card Number",
208
+ pattern: /\b(?:\d{4}[-\s]?){3}\d{4}\b/g,
209
+ severity: "high"
210
+ },
211
+ {
212
+ name: "IP Address",
213
+ pattern: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g,
214
+ severity: "low"
215
+ }
216
+ ];
217
+ var ROUTE_PATTERNS = [
218
+ // Next.js API routes without auth
219
+ {
220
+ name: "Next.js API Route (check for auth)",
221
+ framework: "Next.js",
222
+ pattern: /export\s+(async\s+)?function\s+(GET|POST|PUT|DELETE|PATCH)\s*\(/g,
223
+ severity: "medium",
224
+ description: "API route handler - verify authentication is implemented"
225
+ },
226
+ // Express routes
227
+ {
228
+ name: "Express Route without Auth Middleware",
229
+ framework: "Express",
230
+ pattern: /app\.(get|post|put|delete|patch)\s*\(\s*["'`][^"'`]+["'`]\s*,\s*(?!.*auth)/gi,
231
+ severity: "medium",
232
+ description: "Express route - check if auth middleware is applied"
233
+ }
234
+ ];
235
+ var IGNORE_PATTERNS = [
236
+ "node_modules",
237
+ ".git",
238
+ "dist",
239
+ "build",
240
+ ".next",
241
+ ".venv",
242
+ "__pycache__",
243
+ "*.min.js",
244
+ "*.min.css",
245
+ "*.map",
246
+ "package-lock.json",
247
+ "yarn.lock",
248
+ "pnpm-lock.yaml"
249
+ ];
250
+ var SCANNABLE_EXTENSIONS = [
251
+ ".js",
252
+ ".jsx",
253
+ ".ts",
254
+ ".tsx",
255
+ ".mjs",
256
+ ".cjs",
257
+ ".py",
258
+ ".rb",
259
+ ".go",
260
+ ".java",
261
+ ".php",
262
+ ".env",
263
+ ".json",
264
+ ".yaml",
265
+ ".yml",
266
+ ".toml",
267
+ ".xml",
268
+ ".md",
269
+ ".txt",
270
+ ".sql",
271
+ ".sh",
272
+ ".bash",
273
+ ".zsh"
274
+ ];
275
+
276
+ // src/scanner/index.ts
277
+ function redact(match, showChars = 4) {
278
+ if (match.length <= showChars * 2) {
279
+ return "*".repeat(match.length);
280
+ }
281
+ return match.slice(0, showChars) + "****" + match.slice(-showChars);
282
+ }
283
+ function getPosition(content, index) {
284
+ const lines = content.slice(0, index).split("\n");
285
+ return {
286
+ line: lines.length,
287
+ column: lines[lines.length - 1].length + 1
288
+ };
289
+ }
290
+ function shouldIgnore(filePath) {
291
+ const normalized = filePath.replace(/\\/g, "/");
292
+ return IGNORE_PATTERNS.some((pattern) => {
293
+ if (pattern.startsWith("*")) {
294
+ return normalized.endsWith(pattern.slice(1));
295
+ }
296
+ return normalized.includes(pattern);
297
+ });
298
+ }
299
+ function isScannable(filePath) {
300
+ const ext = path.extname(filePath).toLowerCase();
301
+ return SCANNABLE_EXTENSIONS.includes(ext);
302
+ }
303
+ function scanFile(filePath, content) {
304
+ const issues = [];
305
+ const relativePath = filePath;
306
+ for (const pattern of SECRET_PATTERNS) {
307
+ pattern.pattern.lastIndex = 0;
308
+ let match;
309
+ while ((match = pattern.pattern.exec(content)) !== null) {
310
+ const pos = getPosition(content, match.index);
311
+ issues.push({
312
+ type: "secret",
313
+ severity: pattern.severity,
314
+ name: pattern.name,
315
+ provider: pattern.provider,
316
+ file: relativePath,
317
+ line: pos.line,
318
+ column: pos.column,
319
+ match: redact(match[0])
320
+ });
321
+ }
322
+ }
323
+ for (const pattern of PII_PATTERNS) {
324
+ pattern.pattern.lastIndex = 0;
325
+ let match;
326
+ while ((match = pattern.pattern.exec(content)) !== null) {
327
+ const matchStr = match[0];
328
+ if (isLikelyFalsePositive(matchStr, pattern.name)) {
329
+ continue;
330
+ }
331
+ const pos = getPosition(content, match.index);
332
+ issues.push({
333
+ type: "pii",
334
+ severity: pattern.severity,
335
+ name: pattern.name,
336
+ file: relativePath,
337
+ line: pos.line,
338
+ column: pos.column,
339
+ match: redact(matchStr, 3)
340
+ });
341
+ }
342
+ }
343
+ for (const pattern of ROUTE_PATTERNS) {
344
+ pattern.pattern.lastIndex = 0;
345
+ let match;
346
+ while ((match = pattern.pattern.exec(content)) !== null) {
347
+ const pos = getPosition(content, match.index);
348
+ issues.push({
349
+ type: "route",
350
+ severity: pattern.severity,
351
+ name: pattern.name,
352
+ file: relativePath,
353
+ line: pos.line,
354
+ column: pos.column,
355
+ match: match[0],
356
+ description: pattern.description
357
+ });
358
+ }
359
+ }
360
+ const fileName = path.basename(filePath);
361
+ if (fileName.startsWith(".env") && !fileName.includes(".example")) {
362
+ const gitignorePath = path.join(path.dirname(filePath), ".gitignore");
363
+ const gitignoreExists = fs.existsSync(gitignorePath);
364
+ issues.push({
365
+ type: "config",
366
+ severity: "high",
367
+ name: "Environment file in repository",
368
+ file: relativePath,
369
+ line: 1,
370
+ column: 1,
371
+ match: fileName,
372
+ description: gitignoreExists ? "Verify this file is in .gitignore" : "Add .env* to .gitignore"
373
+ });
374
+ }
375
+ return issues;
376
+ }
377
+ function isLikelyFalsePositive(match, patternName) {
378
+ if (patternName === "Email Address") {
379
+ const falseDomains = [
380
+ "example.com",
381
+ "example.org",
382
+ "test.com",
383
+ "localhost",
384
+ "placeholder.com"
385
+ ];
386
+ if (falseDomains.some((d) => match.includes(d))) {
387
+ return true;
388
+ }
389
+ const publicPrefixes = [
390
+ "support@",
391
+ "help@",
392
+ "info@",
393
+ "contact@",
394
+ "sales@",
395
+ "admin@",
396
+ "noreply@",
397
+ "no-reply@",
398
+ "hello@",
399
+ "team@",
400
+ "partners@",
401
+ "enterprise@",
402
+ "security@",
403
+ "privacy@",
404
+ "legal@"
405
+ ];
406
+ if (publicPrefixes.some((p) => match.toLowerCase().startsWith(p))) {
407
+ return true;
408
+ }
409
+ }
410
+ if (patternName === "IP Address") {
411
+ const falseIPs = ["0.0.0.0", "127.0.0.1", "192.168.", "10.0.", "172.16."];
412
+ if (falseIPs.some((ip) => match.startsWith(ip))) {
413
+ return true;
414
+ }
415
+ }
416
+ if (patternName.includes("Phone Number")) {
417
+ if (match.includes("555") || match.includes("123-456") || match.includes("000-000")) {
418
+ return true;
419
+ }
420
+ }
421
+ return false;
422
+ }
423
+ function calculateScore(issues) {
424
+ const critical = issues.filter((i) => i.severity === "critical").length;
425
+ const high = issues.filter((i) => i.severity === "high").length;
426
+ const medium = issues.filter((i) => i.severity === "medium").length;
427
+ const total = issues.length;
428
+ if (critical > 0) return "F";
429
+ if (high >= 3) return "F";
430
+ if (high >= 2) return "D";
431
+ if (high >= 1 || medium >= 5) return "C";
432
+ if (medium >= 2) return "B";
433
+ if (total === 0) return "A";
434
+ return "B";
435
+ }
436
+ function getTierDescription(score) {
437
+ switch (score) {
438
+ case "A":
439
+ return "Excellent! No security issues detected.";
440
+ case "B":
441
+ return "Good, but minor improvements recommended.";
442
+ case "C":
443
+ return "Fair. Some security concerns need attention.";
444
+ case "D":
445
+ return "Poor. Significant security issues detected.";
446
+ case "F":
447
+ return "Critical! Your app is leaking secrets.";
448
+ default:
449
+ return "";
450
+ }
451
+ }
452
+ async function scan(targetPath) {
453
+ const startTime = Date.now();
454
+ const absolutePath = path.resolve(targetPath);
455
+ const files = await glob("**/*", {
456
+ cwd: absolutePath,
457
+ nodir: true,
458
+ ignore: IGNORE_PATTERNS,
459
+ absolute: true
460
+ });
461
+ const issues = [];
462
+ let filesScanned = 0;
463
+ for (const file of files) {
464
+ if (!isScannable(file) || shouldIgnore(file)) {
465
+ continue;
466
+ }
467
+ try {
468
+ const content = fs.readFileSync(file, "utf-8");
469
+ const relativePath = path.relative(absolutePath, file);
470
+ const fileIssues = scanFile(relativePath, content);
471
+ issues.push(...fileIssues);
472
+ filesScanned++;
473
+ } catch {
474
+ continue;
475
+ }
476
+ }
477
+ const score = calculateScore(issues);
478
+ const scanDuration = Date.now() - startTime;
479
+ return {
480
+ score,
481
+ tierDescription: getTierDescription(score),
482
+ issues,
483
+ filesScanned,
484
+ scanDuration,
485
+ summary: {
486
+ secrets: issues.filter((i) => i.type === "secret").length,
487
+ pii: issues.filter((i) => i.type === "pii").length,
488
+ routes: issues.filter((i) => i.type === "route").length,
489
+ config: issues.filter((i) => i.type === "config").length,
490
+ critical: issues.filter((i) => i.severity === "critical").length,
491
+ high: issues.filter((i) => i.severity === "high").length,
492
+ medium: issues.filter((i) => i.severity === "medium").length,
493
+ low: issues.filter((i) => i.severity === "low").length
494
+ }
495
+ };
496
+ }
497
+
498
+ // src/cli.ts
499
+ var VERSION = "0.1.0";
500
+ var scoreStyles = {
501
+ A: { color: chalk.green },
502
+ B: { color: chalk.blue },
503
+ C: { color: chalk.yellow },
504
+ D: { color: chalk.red },
505
+ F: { color: chalk.bgRed.white }
506
+ };
507
+ var severityColors = {
508
+ critical: chalk.bgRed.white,
509
+ high: chalk.red,
510
+ medium: chalk.yellow,
511
+ low: chalk.blue
512
+ };
513
+ var typeLabels = {
514
+ secret: "SECRETS",
515
+ pii: "PII",
516
+ route: "ROUTES",
517
+ config: "CONFIG"
518
+ };
519
+ function printBanner() {
520
+ console.log();
521
+ console.log(chalk.cyan.bold(" Cencori Scan"));
522
+ console.log(chalk.gray(` v${VERSION}`));
523
+ console.log();
524
+ }
525
+ function printScore(result) {
526
+ const style = scoreStyles[result.score];
527
+ const scoreText = `${result.score}-Tier`;
528
+ const content = ` Security Score: ${scoreText}`;
529
+ console.log();
530
+ console.log(chalk.gray(" \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510"));
531
+ console.log(chalk.gray(" \u2502") + style.color.bold(content.padEnd(45)) + chalk.gray("\u2502"));
532
+ console.log(chalk.gray(" \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518"));
533
+ console.log();
534
+ console.log(chalk.gray(` ${result.tierDescription}`));
535
+ console.log();
536
+ }
537
+ function printIssues(issues) {
538
+ if (issues.length === 0) {
539
+ console.log(chalk.green(" No security issues found."));
540
+ console.log();
541
+ return;
542
+ }
543
+ const grouped = {};
544
+ for (const issue of issues) {
545
+ if (!grouped[issue.type]) {
546
+ grouped[issue.type] = [];
547
+ }
548
+ grouped[issue.type].push(issue);
549
+ }
550
+ for (const [type, typeIssues] of Object.entries(grouped)) {
551
+ const label = typeLabels[type] || type.toUpperCase();
552
+ console.log(` ${chalk.bold(label)} (${typeIssues.length})`);
553
+ for (let i = 0; i < typeIssues.length; i++) {
554
+ const issue = typeIssues[i];
555
+ const isLast = i === typeIssues.length - 1;
556
+ const prefix = isLast ? " \u2514\u2500" : " \u251C\u2500";
557
+ const severityColor = severityColors[issue.severity];
558
+ console.log(
559
+ chalk.gray(prefix) + " " + chalk.gray(`${issue.file}:${issue.line}`) + " " + severityColor(issue.match)
560
+ );
561
+ if (issue.description) {
562
+ const descPrefix = isLast ? " " : " \u2502 ";
563
+ console.log(chalk.gray(descPrefix) + chalk.dim(issue.description));
564
+ }
565
+ }
566
+ console.log();
567
+ }
568
+ }
569
+ function printSummary(result) {
570
+ const { summary } = result;
571
+ console.log(chalk.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
572
+ console.log();
573
+ console.log(` ${chalk.bold("Summary")}`);
574
+ console.log(` Files scanned: ${chalk.cyan(result.filesScanned)}`);
575
+ console.log(` Scan time: ${chalk.cyan(result.scanDuration + "ms")}`);
576
+ console.log();
577
+ if (summary.critical > 0) {
578
+ console.log(` ${chalk.bgRed.white(" CRITICAL ")} ${summary.critical} issues`);
579
+ }
580
+ if (summary.high > 0) {
581
+ console.log(` ${chalk.red(" HIGH ")} ${summary.high} issues`);
582
+ }
583
+ if (summary.medium > 0) {
584
+ console.log(` ${chalk.yellow(" MEDIUM ")} ${summary.medium} issues`);
585
+ }
586
+ if (summary.low > 0) {
587
+ console.log(` ${chalk.blue(" LOW ")} ${summary.low} issues`);
588
+ }
589
+ console.log();
590
+ }
591
+ function printFixes(issues) {
592
+ if (issues.length === 0) return;
593
+ console.log(` ${chalk.bold("Recommendations:")}`);
594
+ const hasSecrets = issues.some((i) => i.type === "secret");
595
+ const hasPII = issues.some((i) => i.type === "pii");
596
+ const hasConfig = issues.some((i) => i.type === "config");
597
+ if (hasSecrets) {
598
+ console.log(chalk.gray(" - Use environment variables for secrets"));
599
+ console.log(chalk.gray(" - Never commit API keys to version control"));
600
+ }
601
+ if (hasConfig) {
602
+ console.log(chalk.gray(" - Add .env* to .gitignore"));
603
+ }
604
+ if (hasPII) {
605
+ console.log(chalk.gray(" - Remove personal data from source code"));
606
+ }
607
+ console.log();
608
+ }
609
+ function printFooter() {
610
+ console.log(chalk.gray(" \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"));
611
+ console.log();
612
+ console.log(` Share: ${chalk.cyan("https://scan.cencori.com")}`);
613
+ console.log(` Docs: ${chalk.cyan("https://cencori.com/docs")}`);
614
+ console.log();
615
+ }
616
+ async function main() {
617
+ program.name("cencori-scan").description("Security scanner for AI apps. Detect secrets, PII, and exposed routes.").version(VERSION).argument("[path]", "Path to scan", ".").option("-j, --json", "Output results as JSON").option("-q, --quiet", "Only output the score").option("--no-color", "Disable colored output").action(async (targetPath, options) => {
618
+ if (options.json) {
619
+ const result = await scan(targetPath);
620
+ console.log(JSON.stringify(result, null, 2));
621
+ process.exit(result.score === "A" || result.score === "B" ? 0 : 1);
622
+ return;
623
+ }
624
+ printBanner();
625
+ const spinner = ora({
626
+ text: "Scanning for security issues...",
627
+ color: "cyan"
628
+ }).start();
629
+ try {
630
+ const result = await scan(targetPath);
631
+ spinner.succeed(`Scanned ${result.filesScanned} files`);
632
+ if (options.quiet) {
633
+ const style = scoreStyles[result.score];
634
+ console.log(`
635
+ Score: ${style.color.bold(result.score + "-Tier")}
636
+ `);
637
+ process.exit(result.score === "A" || result.score === "B" ? 0 : 1);
638
+ return;
639
+ }
640
+ printScore(result);
641
+ printIssues(result.issues);
642
+ printSummary(result);
643
+ printFixes(result.issues);
644
+ printFooter();
645
+ process.exit(result.score === "A" || result.score === "B" ? 0 : 1);
646
+ } catch (error) {
647
+ spinner.fail("Scan failed");
648
+ console.error(chalk.red(`
649
+ Error: ${error instanceof Error ? error.message : "Unknown error"}`));
650
+ process.exit(1);
651
+ }
652
+ });
653
+ program.parse();
654
+ }
655
+ main();
656
+ //# sourceMappingURL=cli.mjs.map