@vibecheckai/cli 3.4.0 → 3.5.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.
Files changed (166) hide show
  1. package/bin/registry.js +243 -152
  2. package/bin/runners/cli-utils.js +2 -33
  3. package/bin/runners/context/generators/cursor.js +49 -2
  4. package/bin/runners/lib/agent-firewall/learning/learning-engine.js +849 -0
  5. package/bin/runners/lib/analyzers.js +544 -19
  6. package/bin/runners/lib/audit-logger.js +532 -0
  7. package/bin/runners/lib/authority/authorities/architecture.js +364 -0
  8. package/bin/runners/lib/authority/authorities/compliance.js +341 -0
  9. package/bin/runners/lib/authority/authorities/human.js +343 -0
  10. package/bin/runners/lib/authority/authorities/quality.js +420 -0
  11. package/bin/runners/lib/authority/authorities/security.js +228 -0
  12. package/bin/runners/lib/authority/index.js +293 -0
  13. package/bin/runners/lib/authority-badge.js +425 -425
  14. package/bin/runners/lib/bundle/bundle-intelligence.js +846 -0
  15. package/bin/runners/lib/cli-charts.js +368 -0
  16. package/bin/runners/lib/cli-config-display.js +405 -0
  17. package/bin/runners/lib/cli-demo.js +275 -0
  18. package/bin/runners/lib/cli-errors.js +438 -0
  19. package/bin/runners/lib/cli-help-formatter.js +439 -0
  20. package/bin/runners/lib/cli-interactive-menu.js +509 -0
  21. package/bin/runners/lib/cli-prompts.js +441 -0
  22. package/bin/runners/lib/cli-scan-cards.js +362 -0
  23. package/bin/runners/lib/compliance-reporter.js +710 -0
  24. package/bin/runners/lib/conductor/index.js +671 -0
  25. package/bin/runners/lib/easy/README.md +123 -0
  26. package/bin/runners/lib/easy/index.js +140 -0
  27. package/bin/runners/lib/easy/interactive-wizard.js +788 -0
  28. package/bin/runners/lib/easy/one-click-firewall.js +564 -0
  29. package/bin/runners/lib/easy/zero-config-reality.js +714 -0
  30. package/bin/runners/lib/engines/accessibility-engine.js +218 -18
  31. package/bin/runners/lib/engines/api-consistency-engine.js +335 -30
  32. package/bin/runners/lib/engines/async-patterns-engine.js +444 -0
  33. package/bin/runners/lib/engines/bundle-size-engine.js +433 -0
  34. package/bin/runners/lib/engines/confidence-scoring.js +276 -0
  35. package/bin/runners/lib/engines/context-detection.js +264 -0
  36. package/bin/runners/lib/engines/cross-file-analysis-engine.js +292 -27
  37. package/bin/runners/lib/engines/database-patterns-engine.js +429 -0
  38. package/bin/runners/lib/engines/duplicate-code-engine.js +354 -0
  39. package/bin/runners/lib/engines/empty-catch-engine.js +127 -17
  40. package/bin/runners/lib/engines/env-variables-engine.js +458 -0
  41. package/bin/runners/lib/engines/error-handling-engine.js +437 -0
  42. package/bin/runners/lib/engines/false-positive-prevention.js +630 -0
  43. package/bin/runners/lib/engines/framework-adapters/index.js +607 -0
  44. package/bin/runners/lib/engines/framework-detection.js +508 -0
  45. package/bin/runners/lib/engines/import-order-engine.js +429 -0
  46. package/bin/runners/lib/engines/mock-data-engine.js +53 -10
  47. package/bin/runners/lib/engines/naming-conventions-engine.js +544 -0
  48. package/bin/runners/lib/engines/noise-reduction-engine.js +452 -0
  49. package/bin/runners/lib/engines/orchestrator.js +334 -0
  50. package/bin/runners/lib/engines/performance-issues-engine.js +176 -36
  51. package/bin/runners/lib/engines/react-patterns-engine.js +457 -0
  52. package/bin/runners/lib/engines/security-vulnerabilities-engine.js +382 -54
  53. package/bin/runners/lib/engines/type-aware-engine.js +263 -39
  54. package/bin/runners/lib/engines/vibecheck-engines/index.js +122 -13
  55. package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +806 -0
  56. package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +373 -73
  57. package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +577 -0
  58. package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +543 -0
  59. package/bin/runners/lib/engines/vibecheck-engines.js +514 -0
  60. package/bin/runners/lib/enhanced-features/index.js +305 -0
  61. package/bin/runners/lib/enhanced-output.js +631 -0
  62. package/bin/runners/lib/enterprise.js +300 -0
  63. package/bin/runners/lib/entitlements-v2.js +103 -11
  64. package/bin/runners/lib/firewall/command-validator.js +351 -0
  65. package/bin/runners/lib/firewall/config.js +341 -0
  66. package/bin/runners/lib/firewall/content-validator.js +519 -0
  67. package/bin/runners/lib/firewall/index.js +101 -0
  68. package/bin/runners/lib/firewall/path-validator.js +256 -0
  69. package/bin/runners/lib/html-proof-report.js +350 -700
  70. package/bin/runners/lib/intelligence/cross-repo-intelligence.js +817 -0
  71. package/bin/runners/lib/mcp-utils.js +425 -0
  72. package/bin/runners/lib/missions/plan.js +46 -6
  73. package/bin/runners/lib/missions/templates.js +232 -0
  74. package/bin/runners/lib/output/index.js +1022 -0
  75. package/bin/runners/lib/policy-engine.js +652 -0
  76. package/bin/runners/lib/polish/autofix/accessibility-fixes.js +333 -0
  77. package/bin/runners/lib/polish/autofix/async-handlers.js +273 -0
  78. package/bin/runners/lib/polish/autofix/dead-code.js +280 -0
  79. package/bin/runners/lib/polish/autofix/imports-optimizer.js +344 -0
  80. package/bin/runners/lib/polish/autofix/index.js +200 -0
  81. package/bin/runners/lib/polish/autofix/remove-consoles.js +209 -0
  82. package/bin/runners/lib/polish/autofix/strengthen-types.js +245 -0
  83. package/bin/runners/lib/polish/backend-checks.js +148 -0
  84. package/bin/runners/lib/polish/documentation-checks.js +111 -0
  85. package/bin/runners/lib/polish/frontend-checks.js +168 -0
  86. package/bin/runners/lib/polish/index.js +71 -0
  87. package/bin/runners/lib/polish/infrastructure-checks.js +131 -0
  88. package/bin/runners/lib/polish/library-detection.js +175 -0
  89. package/bin/runners/lib/polish/performance-checks.js +100 -0
  90. package/bin/runners/lib/polish/security-checks.js +148 -0
  91. package/bin/runners/lib/polish/utils.js +203 -0
  92. package/bin/runners/lib/prompt-builder.js +540 -0
  93. package/bin/runners/lib/proof-certificate.js +634 -0
  94. package/bin/runners/lib/reality/accessibility-audit.js +946 -0
  95. package/bin/runners/lib/reality/api-contract-validator.js +1012 -0
  96. package/bin/runners/lib/reality/chaos-engineering.js +1084 -0
  97. package/bin/runners/lib/reality/performance-tracker.js +1077 -0
  98. package/bin/runners/lib/reality/scenario-generator.js +1404 -0
  99. package/bin/runners/lib/reality/visual-regression.js +852 -0
  100. package/bin/runners/lib/reality-profiler.js +717 -0
  101. package/bin/runners/lib/replay/flight-recorder-viewer.js +1160 -0
  102. package/bin/runners/lib/review/ai-code-review.js +832 -0
  103. package/bin/runners/lib/rules/custom-rule-engine.js +985 -0
  104. package/bin/runners/lib/sbom-generator.js +641 -0
  105. package/bin/runners/lib/scan-output-enhanced.js +512 -0
  106. package/bin/runners/lib/scan-output.js +47 -0
  107. package/bin/runners/lib/security/owasp-scanner.js +939 -0
  108. package/bin/runners/lib/terminal-ui.js +113 -1
  109. package/bin/runners/lib/unified-cli-output.js +603 -430
  110. package/bin/runners/lib/validators/contract-validator.js +283 -0
  111. package/bin/runners/lib/validators/dead-export-detector.js +279 -0
  112. package/bin/runners/lib/validators/dep-audit.js +245 -0
  113. package/bin/runners/lib/validators/env-validator.js +319 -0
  114. package/bin/runners/lib/validators/index.js +120 -0
  115. package/bin/runners/lib/validators/license-checker.js +252 -0
  116. package/bin/runners/lib/validators/route-validator.js +290 -0
  117. package/bin/runners/runAIAgent.js +5 -10
  118. package/bin/runners/runAgent.js +3 -0
  119. package/bin/runners/runApprove.js +1233 -1200
  120. package/bin/runners/runAuth.js +22 -1
  121. package/bin/runners/runAuthority.js +528 -0
  122. package/bin/runners/runCheckpoint.js +4 -24
  123. package/bin/runners/runClassify.js +862 -859
  124. package/bin/runners/runConductor.js +772 -0
  125. package/bin/runners/runContainer.js +366 -0
  126. package/bin/runners/runContext.js +3 -0
  127. package/bin/runners/runDoctor.js +28 -41
  128. package/bin/runners/runEasy.js +410 -0
  129. package/bin/runners/runFirewall.js +3 -0
  130. package/bin/runners/runFirewallHook.js +3 -0
  131. package/bin/runners/runFix.js +76 -66
  132. package/bin/runners/runGuard.js +411 -18
  133. package/bin/runners/runIaC.js +372 -0
  134. package/bin/runners/runInit.js +10 -60
  135. package/bin/runners/runMcp.js +11 -12
  136. package/bin/runners/runPolish.js +240 -64
  137. package/bin/runners/runPromptFirewall.js +5 -12
  138. package/bin/runners/runProve.js +20 -55
  139. package/bin/runners/runReality.js +68 -59
  140. package/bin/runners/runReport.js +31 -5
  141. package/bin/runners/runRuntime.js +5 -8
  142. package/bin/runners/runScan.js +194 -1286
  143. package/bin/runners/runShip.js +695 -47
  144. package/bin/runners/runTruth.js +3 -0
  145. package/bin/runners/runValidate.js +7 -11
  146. package/bin/runners/runVibe.js +791 -0
  147. package/bin/runners/runWatch.js +14 -23
  148. package/bin/vibecheck.js +175 -56
  149. package/mcp-server/index.js +190 -14
  150. package/mcp-server/package.json +1 -1
  151. package/mcp-server/tools-v3.js +397 -64
  152. package/mcp-server/tools.js +495 -0
  153. package/package.json +1 -1
  154. package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +0 -164
  155. package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +0 -291
  156. package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +0 -83
  157. package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +0 -198
  158. package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +0 -275
  159. package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +0 -167
  160. package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +0 -217
  161. package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +0 -140
  162. package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +0 -164
  163. package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +0 -234
  164. package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +0 -217
  165. package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +0 -78
  166. package/mcp-server/index-v1.js +0 -698
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * Hardcoded Secrets Engine
3
- * Detects API keys, tokens, passwords, and private keys in code.
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
4
8
  */
5
9
 
6
10
  const { getAST, parseCode } = require("./ast-cache");
@@ -8,22 +12,118 @@ const traverse = require("@babel/traverse").default;
8
12
  const t = require("@babel/types");
9
13
  const { shouldExcludeFile, isTestContext, hasIgnoreDirective } = require("./file-filter");
10
14
 
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
+
11
64
  // Enhanced patterns with more comprehensive detection
12
65
  const SECRET_PATTERNS = [
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}/ },
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 },
27
127
  ];
28
128
 
29
129
  function getContext(code, start, length = 80) {
@@ -32,10 +132,14 @@ function getContext(code, start, length = 80) {
32
132
  return code.slice(contextStart, contextEnd).replace(/\n/g, " ").trim();
33
133
  }
34
134
 
35
- function isLikelyFalsePositive(value) {
36
- // Exclude obvious placeholders
135
+ /**
136
+ * Check if value matches common placeholder patterns
137
+ */
138
+ function isPlaceholder(value) {
37
139
  const placeholders = [
38
140
  "YOUR_API_KEY",
141
+ "YOUR_SECRET",
142
+ "YOUR_TOKEN",
39
143
  "API_KEY_HERE",
40
144
  "REPLACE_ME",
41
145
  "CHANGE_ME",
@@ -43,15 +147,122 @@ function isLikelyFalsePositive(value) {
43
147
  "TODO",
44
148
  "EXAMPLE",
45
149
  "SAMPLE",
46
- "TEST",
47
150
  "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",
48
162
  ];
49
163
  const upper = String(value).toUpperCase();
50
- return placeholders.some((p) => upper.includes(p));
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
+ }
51
261
  }
52
262
 
53
263
  function analyzeHardcodedSecrets(code, filePath) {
54
264
  const findings = [];
265
+ const foundSecrets = new Set(); // Avoid duplicate reports
55
266
 
56
267
  if (shouldExcludeFile(filePath)) return findings;
57
268
  if (isTestContext(code, filePath)) return findings;
@@ -62,69 +273,121 @@ function analyzeHardcodedSecrets(code, filePath) {
62
273
 
63
274
  const lines = code.split("\n");
64
275
 
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
+
65
332
  // Check string literals for secrets
66
333
  traverse(ast, {
67
334
  StringLiteral(path) {
68
335
  const value = path.node.value;
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
- }
336
+ const position = path.node.start || 0;
337
+ checkValue(value, path, position);
96
338
  },
97
339
 
98
340
  TemplateLiteral(path) {
99
- // Template literals may contain secrets in raw strings (rare), but catch if a quasi looks like a token.
341
+ // Template literals may contain secrets in raw strings
100
342
  for (const quasi of path.node.quasis || []) {
101
343
  const value = quasi.value?.cooked || "";
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
- });
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
+ }
128
391
  }
129
392
  }
130
393
  },
@@ -133,7 +396,44 @@ function analyzeHardcodedSecrets(code, filePath) {
133
396
  return findings;
134
397
  }
135
398
 
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
+
136
434
  module.exports = {
137
435
  analyzeHardcodedSecrets,
436
+ calculateEntropy,
437
+ hasHighEntropy,
138
438
  parseCode,
139
439
  };