@vibecheckai/cli 3.5.0 → 3.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 (224) hide show
  1. package/bin/registry.js +214 -237
  2. package/bin/runners/cli-utils.js +33 -2
  3. package/bin/runners/context/analyzer.js +52 -1
  4. package/bin/runners/context/generators/cursor.js +2 -49
  5. package/bin/runners/context/git-context.js +3 -1
  6. package/bin/runners/context/team-conventions.js +33 -7
  7. package/bin/runners/lib/analysis-core.js +25 -5
  8. package/bin/runners/lib/analyzers.js +431 -481
  9. package/bin/runners/lib/default-config.js +127 -0
  10. package/bin/runners/lib/doctor/modules/security.js +3 -1
  11. package/bin/runners/lib/engine/ast-cache.js +210 -0
  12. package/bin/runners/lib/engine/auth-extractor.js +211 -0
  13. package/bin/runners/lib/engine/billing-extractor.js +112 -0
  14. package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
  15. package/bin/runners/lib/engine/env-extractor.js +207 -0
  16. package/bin/runners/lib/engine/express-extractor.js +208 -0
  17. package/bin/runners/lib/engine/extractors.js +849 -0
  18. package/bin/runners/lib/engine/index.js +207 -0
  19. package/bin/runners/lib/engine/repo-index.js +514 -0
  20. package/bin/runners/lib/engine/types.js +124 -0
  21. package/bin/runners/lib/engines/accessibility-engine.js +18 -218
  22. package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
  23. package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
  24. package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
  25. package/bin/runners/lib/engines/mock-data-engine.js +10 -53
  26. package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
  27. package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
  28. package/bin/runners/lib/engines/type-aware-engine.js +39 -263
  29. package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
  30. package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
  31. package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
  32. package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
  33. package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
  34. package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
  35. package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
  36. package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
  37. package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
  38. package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
  39. package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
  40. package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
  41. package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
  42. package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
  43. package/bin/runners/lib/entitlements-v2.js +73 -97
  44. package/bin/runners/lib/error-handler.js +44 -3
  45. package/bin/runners/lib/error-messages.js +289 -0
  46. package/bin/runners/lib/evidence-pack.js +7 -1
  47. package/bin/runners/lib/finding-id.js +69 -0
  48. package/bin/runners/lib/finding-sorter.js +89 -0
  49. package/bin/runners/lib/html-proof-report.js +700 -350
  50. package/bin/runners/lib/missions/plan.js +6 -46
  51. package/bin/runners/lib/missions/templates.js +0 -232
  52. package/bin/runners/lib/next-action.js +560 -0
  53. package/bin/runners/lib/prerequisites.js +149 -0
  54. package/bin/runners/lib/route-detection.js +137 -68
  55. package/bin/runners/lib/scan-output.js +91 -76
  56. package/bin/runners/lib/scan-runner.js +135 -0
  57. package/bin/runners/lib/schemas/ajv-validator.js +464 -0
  58. package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
  59. package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
  60. package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
  61. package/bin/runners/lib/schemas/run-request.schema.json +108 -0
  62. package/bin/runners/lib/schemas/validator.js +27 -0
  63. package/bin/runners/lib/schemas/verdict.schema.json +140 -0
  64. package/bin/runners/lib/ship-output-enterprise.js +23 -23
  65. package/bin/runners/lib/ship-output.js +75 -31
  66. package/bin/runners/lib/terminal-ui.js +6 -113
  67. package/bin/runners/lib/truth.js +351 -10
  68. package/bin/runners/lib/unified-cli-output.js +430 -603
  69. package/bin/runners/lib/unified-output.js +13 -9
  70. package/bin/runners/runAIAgent.js +10 -5
  71. package/bin/runners/runAgent.js +0 -3
  72. package/bin/runners/runAllowlist.js +389 -0
  73. package/bin/runners/runApprove.js +0 -33
  74. package/bin/runners/runAuth.js +73 -45
  75. package/bin/runners/runCheckpoint.js +51 -11
  76. package/bin/runners/runClassify.js +85 -21
  77. package/bin/runners/runContext.js +0 -3
  78. package/bin/runners/runDoctor.js +41 -28
  79. package/bin/runners/runEvidencePack.js +362 -0
  80. package/bin/runners/runFirewall.js +0 -3
  81. package/bin/runners/runFirewallHook.js +0 -3
  82. package/bin/runners/runFix.js +66 -76
  83. package/bin/runners/runGuard.js +18 -411
  84. package/bin/runners/runInit.js +113 -30
  85. package/bin/runners/runLabs.js +424 -0
  86. package/bin/runners/runMcp.js +19 -25
  87. package/bin/runners/runPolish.js +64 -240
  88. package/bin/runners/runPromptFirewall.js +12 -5
  89. package/bin/runners/runProve.js +57 -22
  90. package/bin/runners/runQuickstart.js +531 -0
  91. package/bin/runners/runReality.js +59 -68
  92. package/bin/runners/runReport.js +38 -33
  93. package/bin/runners/runRuntime.js +8 -5
  94. package/bin/runners/runScan.js +1413 -190
  95. package/bin/runners/runShip.js +113 -719
  96. package/bin/runners/runTruth.js +0 -3
  97. package/bin/runners/runValidate.js +13 -9
  98. package/bin/runners/runWatch.js +23 -14
  99. package/bin/scan.js +6 -1
  100. package/bin/vibecheck.js +204 -185
  101. package/mcp-server/deprecation-middleware.js +282 -0
  102. package/mcp-server/handlers/index.ts +15 -0
  103. package/mcp-server/handlers/tool-handler.ts +554 -0
  104. package/mcp-server/index-v1.js +698 -0
  105. package/mcp-server/index.js +210 -238
  106. package/mcp-server/lib/cache-wrapper.cjs +383 -0
  107. package/mcp-server/lib/error-envelope.js +138 -0
  108. package/mcp-server/lib/executor.ts +499 -0
  109. package/mcp-server/lib/index.ts +19 -0
  110. package/mcp-server/lib/rate-limiter.js +166 -0
  111. package/mcp-server/lib/sandbox.test.ts +519 -0
  112. package/mcp-server/lib/sandbox.ts +395 -0
  113. package/mcp-server/lib/types.ts +267 -0
  114. package/mcp-server/package.json +12 -3
  115. package/mcp-server/registry/tool-registry.js +794 -0
  116. package/mcp-server/registry/tools.json +605 -0
  117. package/mcp-server/registry.test.ts +334 -0
  118. package/mcp-server/tests/tier-gating.test.js +297 -0
  119. package/mcp-server/tier-auth.js +378 -45
  120. package/mcp-server/tools-v3.js +353 -442
  121. package/mcp-server/tsconfig.json +37 -0
  122. package/mcp-server/vibecheck-2.0-tools.js +14 -1
  123. package/package.json +1 -1
  124. package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
  125. package/bin/runners/lib/audit-logger.js +0 -532
  126. package/bin/runners/lib/authority/authorities/architecture.js +0 -364
  127. package/bin/runners/lib/authority/authorities/compliance.js +0 -341
  128. package/bin/runners/lib/authority/authorities/human.js +0 -343
  129. package/bin/runners/lib/authority/authorities/quality.js +0 -420
  130. package/bin/runners/lib/authority/authorities/security.js +0 -228
  131. package/bin/runners/lib/authority/index.js +0 -293
  132. package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
  133. package/bin/runners/lib/cli-charts.js +0 -368
  134. package/bin/runners/lib/cli-config-display.js +0 -405
  135. package/bin/runners/lib/cli-demo.js +0 -275
  136. package/bin/runners/lib/cli-errors.js +0 -438
  137. package/bin/runners/lib/cli-help-formatter.js +0 -439
  138. package/bin/runners/lib/cli-interactive-menu.js +0 -509
  139. package/bin/runners/lib/cli-prompts.js +0 -441
  140. package/bin/runners/lib/cli-scan-cards.js +0 -362
  141. package/bin/runners/lib/compliance-reporter.js +0 -710
  142. package/bin/runners/lib/conductor/index.js +0 -671
  143. package/bin/runners/lib/easy/README.md +0 -123
  144. package/bin/runners/lib/easy/index.js +0 -140
  145. package/bin/runners/lib/easy/interactive-wizard.js +0 -788
  146. package/bin/runners/lib/easy/one-click-firewall.js +0 -564
  147. package/bin/runners/lib/easy/zero-config-reality.js +0 -714
  148. package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
  149. package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
  150. package/bin/runners/lib/engines/confidence-scoring.js +0 -276
  151. package/bin/runners/lib/engines/context-detection.js +0 -264
  152. package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
  153. package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
  154. package/bin/runners/lib/engines/env-variables-engine.js +0 -458
  155. package/bin/runners/lib/engines/error-handling-engine.js +0 -437
  156. package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
  157. package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
  158. package/bin/runners/lib/engines/framework-detection.js +0 -508
  159. package/bin/runners/lib/engines/import-order-engine.js +0 -429
  160. package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
  161. package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
  162. package/bin/runners/lib/engines/orchestrator.js +0 -334
  163. package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
  164. package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
  165. package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
  166. package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
  167. package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
  168. package/bin/runners/lib/enhanced-features/index.js +0 -305
  169. package/bin/runners/lib/enhanced-output.js +0 -631
  170. package/bin/runners/lib/enterprise.js +0 -300
  171. package/bin/runners/lib/firewall/command-validator.js +0 -351
  172. package/bin/runners/lib/firewall/config.js +0 -341
  173. package/bin/runners/lib/firewall/content-validator.js +0 -519
  174. package/bin/runners/lib/firewall/index.js +0 -101
  175. package/bin/runners/lib/firewall/path-validator.js +0 -256
  176. package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
  177. package/bin/runners/lib/mcp-utils.js +0 -425
  178. package/bin/runners/lib/output/index.js +0 -1022
  179. package/bin/runners/lib/policy-engine.js +0 -652
  180. package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
  181. package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
  182. package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
  183. package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
  184. package/bin/runners/lib/polish/autofix/index.js +0 -200
  185. package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
  186. package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
  187. package/bin/runners/lib/polish/backend-checks.js +0 -148
  188. package/bin/runners/lib/polish/documentation-checks.js +0 -111
  189. package/bin/runners/lib/polish/frontend-checks.js +0 -168
  190. package/bin/runners/lib/polish/index.js +0 -71
  191. package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
  192. package/bin/runners/lib/polish/library-detection.js +0 -175
  193. package/bin/runners/lib/polish/performance-checks.js +0 -100
  194. package/bin/runners/lib/polish/security-checks.js +0 -148
  195. package/bin/runners/lib/polish/utils.js +0 -203
  196. package/bin/runners/lib/prompt-builder.js +0 -540
  197. package/bin/runners/lib/proof-certificate.js +0 -634
  198. package/bin/runners/lib/reality/accessibility-audit.js +0 -946
  199. package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
  200. package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
  201. package/bin/runners/lib/reality/performance-tracker.js +0 -1077
  202. package/bin/runners/lib/reality/scenario-generator.js +0 -1404
  203. package/bin/runners/lib/reality/visual-regression.js +0 -852
  204. package/bin/runners/lib/reality-profiler.js +0 -717
  205. package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
  206. package/bin/runners/lib/review/ai-code-review.js +0 -832
  207. package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
  208. package/bin/runners/lib/sbom-generator.js +0 -641
  209. package/bin/runners/lib/scan-output-enhanced.js +0 -512
  210. package/bin/runners/lib/security/owasp-scanner.js +0 -939
  211. package/bin/runners/lib/validators/contract-validator.js +0 -283
  212. package/bin/runners/lib/validators/dead-export-detector.js +0 -279
  213. package/bin/runners/lib/validators/dep-audit.js +0 -245
  214. package/bin/runners/lib/validators/env-validator.js +0 -319
  215. package/bin/runners/lib/validators/index.js +0 -120
  216. package/bin/runners/lib/validators/license-checker.js +0 -252
  217. package/bin/runners/lib/validators/route-validator.js +0 -290
  218. package/bin/runners/runAuthority.js +0 -528
  219. package/bin/runners/runConductor.js +0 -772
  220. package/bin/runners/runContainer.js +0 -366
  221. package/bin/runners/runEasy.js +0 -410
  222. package/bin/runners/runIaC.js +0 -372
  223. package/bin/runners/runVibe.js +0 -791
  224. package/mcp-server/tools.js +0 -495
@@ -1,10 +1,6 @@
1
1
  /**
2
2
  * Hardcoded Secrets Engine
3
- * Enhanced with:
4
- * - Shannon entropy analysis for high-entropy string detection
5
- * - More comprehensive secret patterns (50+ patterns)
6
- * - Better false positive detection (env vars, comments, placeholders)
7
- * - Context-aware detection
3
+ * Detects API keys, tokens, passwords, and private keys in code.
8
4
  */
9
5
 
10
6
  const { getAST, parseCode } = require("./ast-cache");
@@ -12,118 +8,22 @@ const traverse = require("@babel/traverse").default;
12
8
  const t = require("@babel/types");
13
9
  const { shouldExcludeFile, isTestContext, hasIgnoreDirective } = require("./file-filter");
14
10
 
15
- /**
16
- * Calculate Shannon entropy of a string
17
- * Higher entropy = more random = more likely to be a secret
18
- */
19
- function calculateEntropy(str) {
20
- if (!str || str.length === 0) return 0;
21
-
22
- const len = str.length;
23
- const frequencies = {};
24
-
25
- for (const char of str) {
26
- frequencies[char] = (frequencies[char] || 0) + 1;
27
- }
28
-
29
- let entropy = 0;
30
- for (const count of Object.values(frequencies)) {
31
- const p = count / len;
32
- entropy -= p * Math.log2(p);
33
- }
34
-
35
- return entropy;
36
- }
37
-
38
- /**
39
- * Entropy thresholds for secret detection
40
- * Based on analysis of real secrets vs normal strings
41
- */
42
- const ENTROPY_THRESHOLDS = {
43
- HIGH: 4.5, // Likely a secret (API keys, tokens)
44
- MEDIUM: 3.5, // Possibly a secret, needs context
45
- LOW: 2.5, // Unlikely to be a secret
46
- };
47
-
48
- /**
49
- * Check if a string has high entropy (looks random)
50
- */
51
- function hasHighEntropy(str, minLength = 16) {
52
- if (!str || str.length < minLength) return false;
53
-
54
- const entropy = calculateEntropy(str);
55
- const entropyPerChar = entropy; // Shannon entropy is already normalized
56
-
57
- // Longer strings should have proportionally higher entropy
58
- const lengthFactor = Math.min(str.length / 32, 1.5);
59
- const adjustedThreshold = ENTROPY_THRESHOLDS.HIGH / lengthFactor;
60
-
61
- return entropy >= adjustedThreshold;
62
- }
63
-
64
11
  // Enhanced patterns with more comprehensive detection
65
12
  const SECRET_PATTERNS = [
66
- // Cloud Provider Keys
67
- { name: "AWS Access Key ID", pattern: /AKIA[0-9A-Z]{16}/, severity: "BLOCK", confidence: "high" },
68
- { name: "AWS Secret Access Key", pattern: /(?<![A-Za-z0-9/+])[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])/, severity: "BLOCK", confidence: "med", requiresEntropy: true },
69
- { name: "AWS Session Token", pattern: /FwoGZXIvYXdzE/, severity: "BLOCK", confidence: "high" },
70
- { name: "Google API Key", pattern: /AIza[0-9A-Za-z\-_]{35}/, severity: "BLOCK", confidence: "high" },
71
- { name: "Google OAuth Token", pattern: /ya29\.[0-9A-Za-z\-_]+/, severity: "BLOCK", confidence: "high" },
72
- { name: "Azure Storage Key", pattern: /(?:[A-Za-z0-9+/]{86}==)/, severity: "BLOCK", confidence: "med", requiresEntropy: true },
73
-
74
- // Version Control
75
- { name: "GitHub Personal Access Token", pattern: /ghp_[0-9a-zA-Z]{36}/, severity: "BLOCK", confidence: "high" },
76
- { name: "GitHub OAuth Token", pattern: /gho_[0-9a-zA-Z]{36}/, severity: "BLOCK", confidence: "high" },
77
- { name: "GitHub App Token", pattern: /ghu_[0-9a-zA-Z]{36}/, severity: "BLOCK", confidence: "high" },
78
- { name: "GitHub Refresh Token", pattern: /ghr_[0-9a-zA-Z]{36}/, severity: "BLOCK", confidence: "high" },
79
- { name: "GitLab Token", pattern: /glpat-[0-9a-zA-Z\-_]{20,}/, severity: "BLOCK", confidence: "high" },
80
- { name: "Bitbucket Token", pattern: /ATBB[0-9a-zA-Z]{32}/, severity: "BLOCK", confidence: "high" },
81
-
82
- // Payment Processors
83
- { name: "Stripe Live Key", pattern: /sk_live_[0-9a-zA-Z]{24,}/, severity: "BLOCK", confidence: "high" },
84
- { name: "Stripe Test Key", pattern: /sk_test_[0-9a-zA-Z]{24,}/, severity: "WARN", confidence: "high" },
85
- { name: "Stripe Publishable Key", pattern: /pk_(live|test)_[0-9a-zA-Z]{24,}/, severity: "INFO", confidence: "high" },
86
- { name: "PayPal Access Token", pattern: /access_token\$[a-zA-Z0-9]{16}\$[a-zA-Z0-9]{64}/, severity: "BLOCK", confidence: "high" },
87
- { name: "Square Access Token", pattern: /sq0atp-[0-9A-Za-z\-_]{22}/, severity: "BLOCK", confidence: "high" },
88
-
89
- // Communication Services
90
- { name: "Slack Bot Token", pattern: /xoxb-[0-9]{10,13}-[0-9]{10,13}-[a-zA-Z0-9]{24}/, severity: "BLOCK", confidence: "high" },
91
- { name: "Slack User Token", pattern: /xoxp-[0-9]{10,13}-[0-9]{10,13}-[a-zA-Z0-9]{24,}/, severity: "BLOCK", confidence: "high" },
92
- { name: "Slack Webhook URL", pattern: /hooks\.slack\.com\/services\/T[a-zA-Z0-9_]+\/B[a-zA-Z0-9_]+\/[a-zA-Z0-9_]+/, severity: "BLOCK", confidence: "high" },
93
- { name: "Twilio API Key", pattern: /SK[0-9a-fA-F]{32}/, severity: "BLOCK", confidence: "high" },
94
- { name: "Twilio Auth Token", pattern: /(?<![a-zA-Z0-9])[a-f0-9]{32}(?![a-zA-Z0-9])/, severity: "WARN", confidence: "low", requiresContext: true },
95
- { name: "SendGrid API Key", pattern: /SG\.[a-zA-Z0-9_-]{22}\.[a-zA-Z0-9_-]{43}/, severity: "BLOCK", confidence: "high" },
96
- { name: "Mailchimp API Key", pattern: /[a-f0-9]{32}-us[0-9]{1,2}/, severity: "BLOCK", confidence: "high" },
97
-
98
- // Database Connection Strings
99
- { name: "MongoDB Connection String", pattern: /mongodb(\+srv)?:\/\/[^\s'"]+/, severity: "BLOCK", confidence: "high" },
100
- { name: "PostgreSQL Connection String", pattern: /postgres(ql)?:\/\/[^\s'"]+/, severity: "BLOCK", confidence: "high" },
101
- { name: "MySQL Connection String", pattern: /mysql:\/\/[^\s'"]+/, severity: "BLOCK", confidence: "high" },
102
- { name: "Redis Connection String", pattern: /redis(s)?:\/\/[^\s'"]+/, severity: "BLOCK", confidence: "high" },
103
-
104
- // Auth Tokens
105
- { name: "JWT Token", pattern: /eyJ[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+/, severity: "WARN", confidence: "high" },
106
- { name: "Bearer Token", pattern: /Bearer\s+[a-zA-Z0-9\-_\.]{20,}/i, severity: "WARN", confidence: "med" },
107
-
108
- // Private Keys
109
- { name: "RSA Private Key", pattern: /-----BEGIN RSA PRIVATE KEY-----/, severity: "BLOCK", confidence: "high" },
110
- { name: "EC Private Key", pattern: /-----BEGIN EC PRIVATE KEY-----/, severity: "BLOCK", confidence: "high" },
111
- { name: "Private Key", pattern: /-----BEGIN PRIVATE KEY-----/, severity: "BLOCK", confidence: "high" },
112
- { name: "OpenSSH Private Key", pattern: /-----BEGIN OPENSSH PRIVATE KEY-----/, severity: "BLOCK", confidence: "high" },
113
- { name: "PGP Private Key", pattern: /-----BEGIN PGP PRIVATE KEY BLOCK-----/, severity: "BLOCK", confidence: "high" },
114
-
115
- // API Keys (Generic but with prefixes)
116
- { name: "Heroku API Key", pattern: /[h|H]eroku.*[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/, severity: "BLOCK", confidence: "high" },
117
- { name: "NPM Token", pattern: /npm_[a-zA-Z0-9]{36}/, severity: "BLOCK", confidence: "high" },
118
- { name: "PyPI Token", pattern: /pypi-[a-zA-Z0-9]{38,}/, severity: "BLOCK", confidence: "high" },
119
- { name: "Docker Hub Token", pattern: /dckr_pat_[a-zA-Z0-9_-]{42,}/, severity: "BLOCK", confidence: "high" },
120
-
121
- // Credentials
122
- { name: "Password Assignment", pattern: /(?:password|passwd|pwd|secret|credential)\s*[:=]\s*['"][^'"]{8,}['"]/i, severity: "WARN", confidence: "med", requiresContext: true },
123
- { name: "Basic Auth", pattern: /Basic\s+[a-zA-Z0-9+/=]{20,}/, severity: "WARN", confidence: "med" },
124
-
125
- // High Entropy Generic (last resort)
126
- { name: "High Entropy String", pattern: /[a-zA-Z0-9]{32,}/, severity: "INFO", confidence: "low", requiresEntropy: true },
13
+ { name: "AWS Access Key", pattern: /AKIA[0-9A-Z]{16}/ },
14
+ { name: "AWS Secret Key", pattern: /[0-9a-zA-Z/+]{40}/ },
15
+ { name: "GitHub Token", pattern: /ghp_[0-9a-zA-Z]{36}/ },
16
+ { name: "GitLab Token", pattern: /glpat-[0-9a-zA-Z\-_]{20,}/ },
17
+ { name: "Slack Token", pattern: /xox[baprs]-[0-9a-zA-Z]{10,48}/ },
18
+ { name: "Stripe Key", pattern: /sk_(live|test)_[0-9a-zA-Z]{24,}/ },
19
+ { name: "Generic API Key", pattern: /[a-zA-Z0-9]{32,}/ },
20
+ { name: "JWT Token", pattern: /eyJ[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+/ },
21
+ { name: "Private Key", pattern: /-----BEGIN (RSA |EC )?PRIVATE KEY-----/ },
22
+ { name: "Database URL", pattern: /(mongodb|postgresql|mysql):\/\/[^\\s]+/ },
23
+ { name: "Password", pattern: /(password|passwd|pwd)\s*[:=]\s*['"][^'"]+['"]/i },
24
+ { name: "Bearer Token", pattern: /Bearer\s+[a-zA-Z0-9\-_\.]+/i },
25
+ { name: "OAuth Token", pattern: /ya29\.[0-9A-Za-z\-_]+/ },
26
+ { name: "Twilio Key", pattern: /SK[0-9a-fA-F]{32}/ },
127
27
  ];
128
28
 
129
29
  function getContext(code, start, length = 80) {
@@ -132,14 +32,10 @@ function getContext(code, start, length = 80) {
132
32
  return code.slice(contextStart, contextEnd).replace(/\n/g, " ").trim();
133
33
  }
134
34
 
135
- /**
136
- * Check if value matches common placeholder patterns
137
- */
138
- function isPlaceholder(value) {
35
+ function isLikelyFalsePositive(value) {
36
+ // Exclude obvious placeholders
139
37
  const placeholders = [
140
38
  "YOUR_API_KEY",
141
- "YOUR_SECRET",
142
- "YOUR_TOKEN",
143
39
  "API_KEY_HERE",
144
40
  "REPLACE_ME",
145
41
  "CHANGE_ME",
@@ -147,122 +43,15 @@ function isPlaceholder(value) {
147
43
  "TODO",
148
44
  "EXAMPLE",
149
45
  "SAMPLE",
46
+ "TEST",
150
47
  "DUMMY",
151
- "FAKE",
152
- "MOCK",
153
- "TEST_KEY",
154
- "DEV_KEY",
155
- "PLACEHOLDER",
156
- "XXX",
157
- "XXXXXXXX",
158
- "12345",
159
- "123456789",
160
- "abcdef",
161
- "0000000",
162
48
  ];
163
49
  const upper = String(value).toUpperCase();
164
- return placeholders.some((p) => upper.includes(p)) ||
165
- /^[0-9]+$/.test(value) || // All numbers
166
- /^[a-z]+$/.test(value) || // All lowercase letters
167
- /^[A-Z]+$/.test(value) || // All uppercase letters
168
- /^(.)\1+$/.test(value); // Repeated characters
169
- }
170
-
171
- /**
172
- * Check if value is an environment variable reference
173
- */
174
- function isEnvVarReference(value, code, position) {
175
- // Direct env reference
176
- if (/process\.env\./i.test(value)) return true;
177
- if (/import\.meta\.env\./i.test(value)) return true;
178
-
179
- // Check surrounding code for env reference
180
- const start = Math.max(0, position - 50);
181
- const end = Math.min(code.length, position + value.length + 50);
182
- const context = code.slice(start, end);
183
-
184
- return /process\.env\s*\[?\s*['"]/i.test(context) ||
185
- /import\.meta\.env/i.test(context) ||
186
- /getenv\s*\(/i.test(context);
187
- }
188
-
189
- /**
190
- * Check if value is in a safe context
191
- */
192
- function isInSafeContext(path, code) {
193
- // Check if in a type annotation
194
- const parent = path.parentPath;
195
- if (parent?.isTypeAnnotation?.() || parent?.isTSTypeAnnotation?.()) {
196
- return true;
197
- }
198
-
199
- // Check if it's a key name (object property key)
200
- if (parent?.isObjectProperty?.() && parent.node.key === path.node) {
201
- return true;
202
- }
203
-
204
- // Check if it's importing from a config/env file
205
- const importParent = path.findParent(p => p.isImportDeclaration());
206
- if (importParent) return true;
207
-
208
- // Check variable name for env/config indicators
209
- if (parent?.isVariableDeclarator?.()) {
210
- const varName = parent.node.id?.name || "";
211
- if (/env|config|settings|options/i.test(varName)) {
212
- return true;
213
- }
214
- }
215
-
216
- return false;
217
- }
218
-
219
- function isLikelyFalsePositive(value, path, code, position) {
220
- // Basic placeholder check
221
- if (isPlaceholder(value)) return true;
222
-
223
- // Environment variable reference
224
- if (isEnvVarReference(value, code, position)) return true;
225
-
226
- // Check for common non-secret patterns
227
- // URLs without credentials
228
- if (/^https?:\/\/(?!.*:.*@)[^\s]+$/.test(value)) return true;
229
-
230
- // Common hash algorithms output
231
- if (/^[a-f0-9]{32}$/.test(value) && /md5|hash/i.test(code.slice(Math.max(0, position - 100), position))) {
232
- return true;
233
- }
234
-
235
- // File paths
236
- if (/^[./]|^[a-zA-Z]:\\/.test(value)) return true;
237
-
238
- // Base64 encoded common strings
239
- const decoded = tryBase64Decode(value);
240
- if (decoded && (isPlaceholder(decoded) || decoded.length < 8)) return true;
241
-
242
- // Skip if it's a safe context
243
- if (path && isInSafeContext(path, code)) return true;
244
-
245
- return false;
246
- }
247
-
248
- /**
249
- * Try to decode base64
250
- */
251
- function tryBase64Decode(str) {
252
- try {
253
- if (!/^[A-Za-z0-9+/]+=*$/.test(str)) return null;
254
- const decoded = Buffer.from(str, "base64").toString("utf8");
255
- // Check if decoded is printable ASCII
256
- if (/^[\x20-\x7E]+$/.test(decoded)) return decoded;
257
- return null;
258
- } catch {
259
- return null;
260
- }
50
+ return placeholders.some((p) => upper.includes(p));
261
51
  }
262
52
 
263
53
  function analyzeHardcodedSecrets(code, filePath) {
264
54
  const findings = [];
265
- const foundSecrets = new Set(); // Avoid duplicate reports
266
55
 
267
56
  if (shouldExcludeFile(filePath)) return findings;
268
57
  if (isTestContext(code, filePath)) return findings;
@@ -273,121 +62,69 @@ function analyzeHardcodedSecrets(code, filePath) {
273
62
 
274
63
  const lines = code.split("\n");
275
64
 
276
- function checkValue(value, path, position) {
277
- if (!value || value.length < 12) return;
278
- if (isLikelyFalsePositive(value, path, code, position)) return;
279
-
280
- // Create a unique key to avoid duplicates
281
- const valueKey = `${position}:${value.substring(0, 20)}`;
282
- if (foundSecrets.has(valueKey)) return;
283
-
284
- for (const secretPattern of SECRET_PATTERNS) {
285
- const match = value.match(secretPattern.pattern);
286
- if (!match) continue;
287
-
288
- // For patterns that require high entropy, verify
289
- if (secretPattern.requiresEntropy) {
290
- const matchedValue = match[0];
291
- if (!hasHighEntropy(matchedValue)) continue;
292
- }
293
-
294
- // For patterns requiring context, check variable names
295
- if (secretPattern.requiresContext) {
296
- const context = getContext(code, position, 100);
297
- const hasSecretContext = /(?:api_?key|secret|token|password|credential|auth)/i.test(context);
298
- if (!hasSecretContext) continue;
299
- }
300
-
301
- const loc = path.node.loc?.start;
302
- if (!loc) continue;
303
-
304
- const line = loc.line;
305
- const contextStr = getContext(code, position);
306
-
307
- // Mask the actual secret value in output
308
- const maskedValue = maskSecret(match[0]);
309
-
310
- foundSecrets.add(valueKey);
311
-
312
- findings.push({
313
- type: "hardcoded_secret",
314
- severity: secretPattern.severity || "BLOCK",
315
- category: "Security",
316
- file: filePath,
317
- line,
318
- column: loc.column,
319
- title: `Hardcoded ${secretPattern.name} detected`,
320
- message: `Found potential ${secretPattern.name} in code. Move to environment variables or secret manager.`,
321
- codeSnippet: lines[line - 1]?.trim(),
322
- evidence: `Detected pattern: ${maskedValue}`,
323
- confidence: secretPattern.confidence || "high",
324
- fixHint: `Replace with process.env.${suggestEnvVarName(secretPattern.name)}`,
325
- });
326
-
327
- // Only report the first matching pattern per value
328
- break;
329
- }
330
- }
331
-
332
65
  // Check string literals for secrets
333
66
  traverse(ast, {
334
67
  StringLiteral(path) {
335
68
  const value = path.node.value;
336
- const position = path.node.start || 0;
337
- checkValue(value, path, position);
69
+ if (!value || value.length < 12) return;
70
+ if (isLikelyFalsePositive(value)) return;
71
+
72
+ for (const secretPattern of SECRET_PATTERNS) {
73
+ const match = value.match(secretPattern.pattern);
74
+ if (!match) continue;
75
+
76
+ const loc = path.node.loc?.start;
77
+ if (!loc) continue;
78
+
79
+ const line = loc.line;
80
+ const context = getContext(code, path.node.start || 0);
81
+
82
+ findings.push({
83
+ type: "hardcoded_secret",
84
+ severity: "BLOCK",
85
+ category: "Security",
86
+ file: filePath,
87
+ line,
88
+ column: loc.column,
89
+ title: `Hardcoded ${secretPattern.name} detected`,
90
+ message: `Found potential ${secretPattern.name} in string literal. Move to environment variables or secret manager.`,
91
+ codeSnippet: lines[line - 1]?.trim(),
92
+ evidence: context,
93
+ confidence: secretPattern.name === "Generic API Key" ? "low" : "high",
94
+ });
95
+ }
338
96
  },
339
97
 
340
98
  TemplateLiteral(path) {
341
- // Template literals may contain secrets in raw strings
99
+ // Template literals may contain secrets in raw strings (rare), but catch if a quasi looks like a token.
342
100
  for (const quasi of path.node.quasis || []) {
343
101
  const value = quasi.value?.cooked || "";
344
- const position = quasi.start || path.node.start || 0;
345
- checkValue(value, { node: quasi, parentPath: path }, position);
346
- }
347
- },
348
-
349
- // Also check object property values with secret-looking keys
350
- ObjectProperty(path) {
351
- const key = path.node.key;
352
- const value = path.node.value;
353
-
354
- // Check if key suggests a secret
355
- let keyName = "";
356
- if (t.isIdentifier(key)) {
357
- keyName = key.name;
358
- } else if (t.isStringLiteral(key)) {
359
- keyName = key.value;
360
- }
361
-
362
- const isSecretKey = /(?:api_?key|secret|token|password|credential|auth_?token|private_?key)/i.test(keyName);
363
-
364
- if (isSecretKey && t.isStringLiteral(value)) {
365
- const strValue = value.value;
366
- if (strValue && strValue.length >= 8 && !isPlaceholder(strValue)) {
367
- const position = value.start || 0;
368
-
369
- // Check entropy for generic values
370
- if (hasHighEntropy(strValue, 8)) {
371
- const loc = value.loc?.start;
372
- if (loc && !foundSecrets.has(`${position}:${strValue.substring(0, 20)}`)) {
373
- foundSecrets.add(`${position}:${strValue.substring(0, 20)}`);
374
-
375
- findings.push({
376
- type: "hardcoded_secret",
377
- severity: "WARN",
378
- category: "Security",
379
- file: filePath,
380
- line: loc.line,
381
- column: loc.column,
382
- title: `Potential secret in '${keyName}' property`,
383
- message: `High-entropy value in secret-looking property '${keyName}'. Consider using environment variables.`,
384
- codeSnippet: lines[loc.line - 1]?.trim(),
385
- evidence: `Property: ${keyName} = ${maskSecret(strValue)}`,
386
- confidence: "med",
387
- fixHint: `Replace with process.env.${keyName.toUpperCase()}`,
388
- });
389
- }
390
- }
102
+ if (!value || value.length < 12) continue;
103
+ if (isLikelyFalsePositive(value)) continue;
104
+
105
+ for (const secretPattern of SECRET_PATTERNS) {
106
+ const match = value.match(secretPattern.pattern);
107
+ if (!match) continue;
108
+
109
+ const loc = quasi.loc?.start || path.node.loc?.start;
110
+ if (!loc) continue;
111
+
112
+ const line = loc.line;
113
+ const context = getContext(code, quasi.start || path.node.start || 0);
114
+
115
+ findings.push({
116
+ type: "hardcoded_secret",
117
+ severity: "BLOCK",
118
+ category: "Security",
119
+ file: filePath,
120
+ line,
121
+ column: loc.column,
122
+ title: `Hardcoded ${secretPattern.name} detected`,
123
+ message: `Found potential ${secretPattern.name} in template literal. Move to environment variables or secret manager.`,
124
+ codeSnippet: lines[line - 1]?.trim(),
125
+ evidence: context,
126
+ confidence: secretPattern.name === "Generic API Key" ? "low" : "high",
127
+ });
391
128
  }
392
129
  }
393
130
  },
@@ -396,44 +133,7 @@ function analyzeHardcodedSecrets(code, filePath) {
396
133
  return findings;
397
134
  }
398
135
 
399
- /**
400
- * Mask a secret value for safe display
401
- */
402
- function maskSecret(value) {
403
- if (!value || value.length < 8) return "***";
404
-
405
- const visibleStart = Math.min(4, Math.floor(value.length / 4));
406
- const visibleEnd = Math.min(4, Math.floor(value.length / 4));
407
-
408
- return value.substring(0, visibleStart) +
409
- "*".repeat(Math.max(4, value.length - visibleStart - visibleEnd)) +
410
- value.substring(value.length - visibleEnd);
411
- }
412
-
413
- /**
414
- * Suggest an environment variable name
415
- */
416
- function suggestEnvVarName(secretType) {
417
- const mapping = {
418
- "AWS Access Key ID": "AWS_ACCESS_KEY_ID",
419
- "AWS Secret Access Key": "AWS_SECRET_ACCESS_KEY",
420
- "GitHub Personal Access Token": "GITHUB_TOKEN",
421
- "Stripe Live Key": "STRIPE_SECRET_KEY",
422
- "Stripe Test Key": "STRIPE_TEST_KEY",
423
- "Database URL": "DATABASE_URL",
424
- "MongoDB Connection String": "MONGODB_URI",
425
- "PostgreSQL Connection String": "DATABASE_URL",
426
- "JWT Token": "JWT_SECRET",
427
- "Slack Bot Token": "SLACK_BOT_TOKEN",
428
- "SendGrid API Key": "SENDGRID_API_KEY",
429
- };
430
-
431
- return mapping[secretType] || secretType.toUpperCase().replace(/\s+/g, "_");
432
- }
433
-
434
136
  module.exports = {
435
137
  analyzeHardcodedSecrets,
436
- calculateEntropy,
437
- hasHighEntropy,
438
138
  parseCode,
439
139
  };
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Mock Data Engine
3
+ * Detects mock, fake, or placeholder data in production code.
4
+ */
5
+
6
+ const { getAST, parseCode } = require("./ast-cache");
7
+ const traverse = require("@babel/traverse").default;
8
+ const { shouldExcludeFile, isTestContext, hasIgnoreDirective } = require("./file-filter");
9
+
10
+ // Enhanced mock data patterns
11
+ const MOCK_PATTERNS = [
12
+ { pattern: /mock/i, type: "mock_reference", message: "Mock reference found" },
13
+ { pattern: /fake/i, type: "fake_data", message: "Fake data reference found" },
14
+ { pattern: /dummy/i, type: "dummy_data", message: "Dummy data reference found" },
15
+ { pattern: /test.*data/i, type: "test_data", message: "Test data reference found" },
16
+ { pattern: /lorem ipsum/i, type: "lorem_ipsum", message: "Lorem ipsum placeholder found" },
17
+ { pattern: /todo|fixme/i, type: "todo_fixme", message: "TODO/FIXME found in code" },
18
+ { pattern: /placeholder/i, type: "placeholder", message: "Placeholder reference found" },
19
+ { pattern: /example/i, type: "example_data", message: "Example reference found" },
20
+ { pattern: /sample/i, type: "sample_data", message: "Sample data reference found" },
21
+ { pattern: /hardcode/i, type: "hardcoded", message: "Hardcoded data reference found" },
22
+ ];
23
+
24
+ // Common mock data values
25
+ const MOCK_VALUES = [
26
+ "test",
27
+ "demo",
28
+ "example",
29
+ "sample",
30
+ "placeholder",
31
+ "lorem",
32
+ "ipsum",
33
+ "foo",
34
+ "bar",
35
+ "baz",
36
+ "mock",
37
+ "fake",
38
+ "dummy",
39
+ "12345",
40
+ "password",
41
+ "admin",
42
+ "user",
43
+ ];
44
+
45
+ function analyzeMockData(code, filePath) {
46
+ const findings = [];
47
+
48
+ if (shouldExcludeFile(filePath)) return findings;
49
+ if (isTestContext(code, filePath)) return findings;
50
+ if (hasIgnoreDirective(code, "mock-data")) return findings;
51
+
52
+ const ast = getAST(code, filePath);
53
+ if (!ast) return findings;
54
+
55
+ const lines = code.split("\n");
56
+
57
+ // Check string literals for mock data
58
+ traverse(ast, {
59
+ StringLiteral(path) {
60
+ const value = path.node.value;
61
+ if (!value || value.length < 2) return;
62
+
63
+ // Check for common mock values (case-insensitive)
64
+ const lower = value.toLowerCase();
65
+ if (MOCK_VALUES.includes(lower)) {
66
+ const loc = path.node.loc?.start;
67
+ if (!loc) return;
68
+
69
+ findings.push({
70
+ type: "mock_value",
71
+ severity: "INFO",
72
+ category: "CodeQuality",
73
+ file: filePath,
74
+ line: loc.line,
75
+ column: loc.column,
76
+ title: "Potential mock value in string literal",
77
+ message: `String literal "${value}" looks like mock/placeholder data.`,
78
+ codeSnippet: lines[loc.line - 1]?.trim(),
79
+ confidence: "low",
80
+ });
81
+ }
82
+
83
+ // Check for mock patterns
84
+ for (const mockPattern of MOCK_PATTERNS) {
85
+ if (mockPattern.pattern.test(value)) {
86
+ const loc = path.node.loc?.start;
87
+ if (!loc) continue;
88
+
89
+ findings.push({
90
+ type: mockPattern.type,
91
+ severity: mockPattern.type === "todo_fixme" ? "WARN" : "INFO",
92
+ category: "CodeQuality",
93
+ file: filePath,
94
+ line: loc.line,
95
+ column: loc.column,
96
+ title: mockPattern.message,
97
+ message: `Found "${mockPattern.pattern}" in string literal: "${value}"`,
98
+ codeSnippet: lines[loc.line - 1]?.trim(),
99
+ confidence: "low",
100
+ });
101
+ }
102
+ }
103
+ },
104
+
105
+ Identifier(path) {
106
+ const name = path.node.name;
107
+ if (!name) return;
108
+
109
+ // Check for mock patterns in variable names (avoid huge noise: only longer names)
110
+ if (name.length < 5) return;
111
+
112
+ for (const mockPattern of MOCK_PATTERNS) {
113
+ if (mockPattern.pattern.test(name)) {
114
+ const loc = path.node.loc?.start;
115
+ if (!loc) continue;
116
+
117
+ findings.push({
118
+ type: mockPattern.type,
119
+ severity: mockPattern.type === "todo_fixme" ? "WARN" : "INFO",
120
+ category: "CodeQuality",
121
+ file: filePath,
122
+ line: loc.line,
123
+ column: loc.column,
124
+ title: `Mock-like identifier: ${name}`,
125
+ message: `Identifier name suggests mock/placeholder data: "${name}"`,
126
+ codeSnippet: lines[loc.line - 1]?.trim(),
127
+ confidence: "low",
128
+ });
129
+ }
130
+ }
131
+ },
132
+ });
133
+
134
+ return findings;
135
+ }
136
+
137
+ module.exports = {
138
+ analyzeMockData,
139
+ parseCode,
140
+ };