@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.
- package/bin/registry.js +214 -237
- package/bin/runners/cli-utils.js +33 -2
- package/bin/runners/context/analyzer.js +52 -1
- package/bin/runners/context/generators/cursor.js +2 -49
- package/bin/runners/context/git-context.js +3 -1
- package/bin/runners/context/team-conventions.js +33 -7
- package/bin/runners/lib/analysis-core.js +25 -5
- package/bin/runners/lib/analyzers.js +431 -481
- package/bin/runners/lib/default-config.js +127 -0
- package/bin/runners/lib/doctor/modules/security.js +3 -1
- package/bin/runners/lib/engine/ast-cache.js +210 -0
- package/bin/runners/lib/engine/auth-extractor.js +211 -0
- package/bin/runners/lib/engine/billing-extractor.js +112 -0
- package/bin/runners/lib/engine/enforcement-extractor.js +100 -0
- package/bin/runners/lib/engine/env-extractor.js +207 -0
- package/bin/runners/lib/engine/express-extractor.js +208 -0
- package/bin/runners/lib/engine/extractors.js +849 -0
- package/bin/runners/lib/engine/index.js +207 -0
- package/bin/runners/lib/engine/repo-index.js +514 -0
- package/bin/runners/lib/engine/types.js +124 -0
- package/bin/runners/lib/engines/accessibility-engine.js +18 -218
- package/bin/runners/lib/engines/api-consistency-engine.js +30 -335
- package/bin/runners/lib/engines/cross-file-analysis-engine.js +27 -292
- package/bin/runners/lib/engines/empty-catch-engine.js +17 -127
- package/bin/runners/lib/engines/mock-data-engine.js +10 -53
- package/bin/runners/lib/engines/performance-issues-engine.js +36 -176
- package/bin/runners/lib/engines/security-vulnerabilities-engine.js +54 -382
- package/bin/runners/lib/engines/type-aware-engine.js +39 -263
- package/bin/runners/lib/engines/vibecheck-engines/index.js +13 -122
- package/bin/runners/lib/engines/vibecheck-engines/lib/ast-cache.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/code-quality-engine.js +291 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/console-logs-engine.js +83 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/dead-code-engine.js +198 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/deprecated-api-engine.js +275 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/empty-catch-engine.js +167 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/file-filter.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/hardcoded-secrets-engine.js +73 -373
- package/bin/runners/lib/engines/vibecheck-engines/lib/mock-data-engine.js +140 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/parallel-processor.js +164 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/performance-issues-engine.js +234 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/type-aware-engine.js +217 -0
- package/bin/runners/lib/engines/vibecheck-engines/lib/unsafe-regex-engine.js +78 -0
- package/bin/runners/lib/entitlements-v2.js +73 -97
- package/bin/runners/lib/error-handler.js +44 -3
- package/bin/runners/lib/error-messages.js +289 -0
- package/bin/runners/lib/evidence-pack.js +7 -1
- package/bin/runners/lib/finding-id.js +69 -0
- package/bin/runners/lib/finding-sorter.js +89 -0
- package/bin/runners/lib/html-proof-report.js +700 -350
- package/bin/runners/lib/missions/plan.js +6 -46
- package/bin/runners/lib/missions/templates.js +0 -232
- package/bin/runners/lib/next-action.js +560 -0
- package/bin/runners/lib/prerequisites.js +149 -0
- package/bin/runners/lib/route-detection.js +137 -68
- package/bin/runners/lib/scan-output.js +91 -76
- package/bin/runners/lib/scan-runner.js +135 -0
- package/bin/runners/lib/schemas/ajv-validator.js +464 -0
- package/bin/runners/lib/schemas/error-envelope.schema.json +105 -0
- package/bin/runners/lib/schemas/finding-v3.schema.json +151 -0
- package/bin/runners/lib/schemas/report-artifact.schema.json +120 -0
- package/bin/runners/lib/schemas/run-request.schema.json +108 -0
- package/bin/runners/lib/schemas/validator.js +27 -0
- package/bin/runners/lib/schemas/verdict.schema.json +140 -0
- package/bin/runners/lib/ship-output-enterprise.js +23 -23
- package/bin/runners/lib/ship-output.js +75 -31
- package/bin/runners/lib/terminal-ui.js +6 -113
- package/bin/runners/lib/truth.js +351 -10
- package/bin/runners/lib/unified-cli-output.js +430 -603
- package/bin/runners/lib/unified-output.js +13 -9
- package/bin/runners/runAIAgent.js +10 -5
- package/bin/runners/runAgent.js +0 -3
- package/bin/runners/runAllowlist.js +389 -0
- package/bin/runners/runApprove.js +0 -33
- package/bin/runners/runAuth.js +73 -45
- package/bin/runners/runCheckpoint.js +51 -11
- package/bin/runners/runClassify.js +85 -21
- package/bin/runners/runContext.js +0 -3
- package/bin/runners/runDoctor.js +41 -28
- package/bin/runners/runEvidencePack.js +362 -0
- package/bin/runners/runFirewall.js +0 -3
- package/bin/runners/runFirewallHook.js +0 -3
- package/bin/runners/runFix.js +66 -76
- package/bin/runners/runGuard.js +18 -411
- package/bin/runners/runInit.js +113 -30
- package/bin/runners/runLabs.js +424 -0
- package/bin/runners/runMcp.js +19 -25
- package/bin/runners/runPolish.js +64 -240
- package/bin/runners/runPromptFirewall.js +12 -5
- package/bin/runners/runProve.js +57 -22
- package/bin/runners/runQuickstart.js +531 -0
- package/bin/runners/runReality.js +59 -68
- package/bin/runners/runReport.js +38 -33
- package/bin/runners/runRuntime.js +8 -5
- package/bin/runners/runScan.js +1413 -190
- package/bin/runners/runShip.js +113 -719
- package/bin/runners/runTruth.js +0 -3
- package/bin/runners/runValidate.js +13 -9
- package/bin/runners/runWatch.js +23 -14
- package/bin/scan.js +6 -1
- package/bin/vibecheck.js +204 -185
- package/mcp-server/deprecation-middleware.js +282 -0
- package/mcp-server/handlers/index.ts +15 -0
- package/mcp-server/handlers/tool-handler.ts +554 -0
- package/mcp-server/index-v1.js +698 -0
- package/mcp-server/index.js +210 -238
- package/mcp-server/lib/cache-wrapper.cjs +383 -0
- package/mcp-server/lib/error-envelope.js +138 -0
- package/mcp-server/lib/executor.ts +499 -0
- package/mcp-server/lib/index.ts +19 -0
- package/mcp-server/lib/rate-limiter.js +166 -0
- package/mcp-server/lib/sandbox.test.ts +519 -0
- package/mcp-server/lib/sandbox.ts +395 -0
- package/mcp-server/lib/types.ts +267 -0
- package/mcp-server/package.json +12 -3
- package/mcp-server/registry/tool-registry.js +794 -0
- package/mcp-server/registry/tools.json +605 -0
- package/mcp-server/registry.test.ts +334 -0
- package/mcp-server/tests/tier-gating.test.js +297 -0
- package/mcp-server/tier-auth.js +378 -45
- package/mcp-server/tools-v3.js +353 -442
- package/mcp-server/tsconfig.json +37 -0
- package/mcp-server/vibecheck-2.0-tools.js +14 -1
- package/package.json +1 -1
- package/bin/runners/lib/agent-firewall/learning/learning-engine.js +0 -849
- package/bin/runners/lib/audit-logger.js +0 -532
- package/bin/runners/lib/authority/authorities/architecture.js +0 -364
- package/bin/runners/lib/authority/authorities/compliance.js +0 -341
- package/bin/runners/lib/authority/authorities/human.js +0 -343
- package/bin/runners/lib/authority/authorities/quality.js +0 -420
- package/bin/runners/lib/authority/authorities/security.js +0 -228
- package/bin/runners/lib/authority/index.js +0 -293
- package/bin/runners/lib/bundle/bundle-intelligence.js +0 -846
- package/bin/runners/lib/cli-charts.js +0 -368
- package/bin/runners/lib/cli-config-display.js +0 -405
- package/bin/runners/lib/cli-demo.js +0 -275
- package/bin/runners/lib/cli-errors.js +0 -438
- package/bin/runners/lib/cli-help-formatter.js +0 -439
- package/bin/runners/lib/cli-interactive-menu.js +0 -509
- package/bin/runners/lib/cli-prompts.js +0 -441
- package/bin/runners/lib/cli-scan-cards.js +0 -362
- package/bin/runners/lib/compliance-reporter.js +0 -710
- package/bin/runners/lib/conductor/index.js +0 -671
- package/bin/runners/lib/easy/README.md +0 -123
- package/bin/runners/lib/easy/index.js +0 -140
- package/bin/runners/lib/easy/interactive-wizard.js +0 -788
- package/bin/runners/lib/easy/one-click-firewall.js +0 -564
- package/bin/runners/lib/easy/zero-config-reality.js +0 -714
- package/bin/runners/lib/engines/async-patterns-engine.js +0 -444
- package/bin/runners/lib/engines/bundle-size-engine.js +0 -433
- package/bin/runners/lib/engines/confidence-scoring.js +0 -276
- package/bin/runners/lib/engines/context-detection.js +0 -264
- package/bin/runners/lib/engines/database-patterns-engine.js +0 -429
- package/bin/runners/lib/engines/duplicate-code-engine.js +0 -354
- package/bin/runners/lib/engines/env-variables-engine.js +0 -458
- package/bin/runners/lib/engines/error-handling-engine.js +0 -437
- package/bin/runners/lib/engines/false-positive-prevention.js +0 -630
- package/bin/runners/lib/engines/framework-adapters/index.js +0 -607
- package/bin/runners/lib/engines/framework-detection.js +0 -508
- package/bin/runners/lib/engines/import-order-engine.js +0 -429
- package/bin/runners/lib/engines/naming-conventions-engine.js +0 -544
- package/bin/runners/lib/engines/noise-reduction-engine.js +0 -452
- package/bin/runners/lib/engines/orchestrator.js +0 -334
- package/bin/runners/lib/engines/react-patterns-engine.js +0 -457
- package/bin/runners/lib/engines/vibecheck-engines/lib/ai-hallucination-engine.js +0 -806
- package/bin/runners/lib/engines/vibecheck-engines/lib/smart-fix-engine.js +0 -577
- package/bin/runners/lib/engines/vibecheck-engines/lib/vibe-score-engine.js +0 -543
- package/bin/runners/lib/engines/vibecheck-engines.js +0 -514
- package/bin/runners/lib/enhanced-features/index.js +0 -305
- package/bin/runners/lib/enhanced-output.js +0 -631
- package/bin/runners/lib/enterprise.js +0 -300
- package/bin/runners/lib/firewall/command-validator.js +0 -351
- package/bin/runners/lib/firewall/config.js +0 -341
- package/bin/runners/lib/firewall/content-validator.js +0 -519
- package/bin/runners/lib/firewall/index.js +0 -101
- package/bin/runners/lib/firewall/path-validator.js +0 -256
- package/bin/runners/lib/intelligence/cross-repo-intelligence.js +0 -817
- package/bin/runners/lib/mcp-utils.js +0 -425
- package/bin/runners/lib/output/index.js +0 -1022
- package/bin/runners/lib/policy-engine.js +0 -652
- package/bin/runners/lib/polish/autofix/accessibility-fixes.js +0 -333
- package/bin/runners/lib/polish/autofix/async-handlers.js +0 -273
- package/bin/runners/lib/polish/autofix/dead-code.js +0 -280
- package/bin/runners/lib/polish/autofix/imports-optimizer.js +0 -344
- package/bin/runners/lib/polish/autofix/index.js +0 -200
- package/bin/runners/lib/polish/autofix/remove-consoles.js +0 -209
- package/bin/runners/lib/polish/autofix/strengthen-types.js +0 -245
- package/bin/runners/lib/polish/backend-checks.js +0 -148
- package/bin/runners/lib/polish/documentation-checks.js +0 -111
- package/bin/runners/lib/polish/frontend-checks.js +0 -168
- package/bin/runners/lib/polish/index.js +0 -71
- package/bin/runners/lib/polish/infrastructure-checks.js +0 -131
- package/bin/runners/lib/polish/library-detection.js +0 -175
- package/bin/runners/lib/polish/performance-checks.js +0 -100
- package/bin/runners/lib/polish/security-checks.js +0 -148
- package/bin/runners/lib/polish/utils.js +0 -203
- package/bin/runners/lib/prompt-builder.js +0 -540
- package/bin/runners/lib/proof-certificate.js +0 -634
- package/bin/runners/lib/reality/accessibility-audit.js +0 -946
- package/bin/runners/lib/reality/api-contract-validator.js +0 -1012
- package/bin/runners/lib/reality/chaos-engineering.js +0 -1084
- package/bin/runners/lib/reality/performance-tracker.js +0 -1077
- package/bin/runners/lib/reality/scenario-generator.js +0 -1404
- package/bin/runners/lib/reality/visual-regression.js +0 -852
- package/bin/runners/lib/reality-profiler.js +0 -717
- package/bin/runners/lib/replay/flight-recorder-viewer.js +0 -1160
- package/bin/runners/lib/review/ai-code-review.js +0 -832
- package/bin/runners/lib/rules/custom-rule-engine.js +0 -985
- package/bin/runners/lib/sbom-generator.js +0 -641
- package/bin/runners/lib/scan-output-enhanced.js +0 -512
- package/bin/runners/lib/security/owasp-scanner.js +0 -939
- package/bin/runners/lib/validators/contract-validator.js +0 -283
- package/bin/runners/lib/validators/dead-export-detector.js +0 -279
- package/bin/runners/lib/validators/dep-audit.js +0 -245
- package/bin/runners/lib/validators/env-validator.js +0 -319
- package/bin/runners/lib/validators/index.js +0 -120
- package/bin/runners/lib/validators/license-checker.js +0 -252
- package/bin/runners/lib/validators/route-validator.js +0 -290
- package/bin/runners/runAuthority.js +0 -528
- package/bin/runners/runConductor.js +0 -772
- package/bin/runners/runContainer.js +0 -366
- package/bin/runners/runEasy.js +0 -410
- package/bin/runners/runIaC.js +0 -372
- package/bin/runners/runVibe.js +0 -791
- package/mcp-server/tools.js +0 -495
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hardcoded Secrets Engine
|
|
3
|
-
*
|
|
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
|
-
|
|
67
|
-
{ name: "AWS
|
|
68
|
-
{ name: "
|
|
69
|
-
{ name: "
|
|
70
|
-
{ name: "
|
|
71
|
-
{ name: "
|
|
72
|
-
{ name: "
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
{ name: "
|
|
76
|
-
{ name: "
|
|
77
|
-
{ name: "
|
|
78
|
-
{ name: "
|
|
79
|
-
{ name: "
|
|
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
|
-
|
|
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
|
-
|
|
337
|
-
|
|
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
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
+
};
|