@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
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parallel Processor
|
|
3
|
+
* Utility to process a list of files concurrently with bounded parallelism.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: The caller provides `processor(filePath)` which may return any value.
|
|
6
|
+
* We collect both results and errors without crashing the whole run.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const os = require("os");
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Run a promise with an optional timeout.
|
|
13
|
+
*/
|
|
14
|
+
async function withTimeout(promise, timeoutMs, label = "operation") {
|
|
15
|
+
if (!timeoutMs || timeoutMs <= 0) return promise;
|
|
16
|
+
|
|
17
|
+
let timer = null;
|
|
18
|
+
const timeout = new Promise((_, reject) => {
|
|
19
|
+
timer = setTimeout(() => {
|
|
20
|
+
const err = new Error(`${label} timed out after ${timeoutMs}ms`);
|
|
21
|
+
err.code = "ETIMEDOUT";
|
|
22
|
+
reject(err);
|
|
23
|
+
}, timeoutMs);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
return await Promise.race([promise, timeout]);
|
|
28
|
+
} finally {
|
|
29
|
+
if (timer) clearTimeout(timer);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Process files in parallel with bounded concurrency.
|
|
35
|
+
*
|
|
36
|
+
* @param {string[]} files
|
|
37
|
+
* @param {(filePath: string) => Promise<any>} processor
|
|
38
|
+
* @param {object} options
|
|
39
|
+
* @returns {Promise<{results: Array<{file: string, result: any}>, errors: Array<{file: string, error: Error}>, stats: object}>}
|
|
40
|
+
*/
|
|
41
|
+
async function processFilesInParallel(files, processor, options = {}) {
|
|
42
|
+
const concurrency =
|
|
43
|
+
Number.isFinite(options.concurrency) && options.concurrency > 0
|
|
44
|
+
? Math.floor(options.concurrency)
|
|
45
|
+
: Math.max(1, Math.min(os.cpus().length, 8));
|
|
46
|
+
|
|
47
|
+
const timeoutMs = Number.isFinite(options.timeoutMs) ? options.timeoutMs : 0;
|
|
48
|
+
const stopOnError = Boolean(options.stopOnError);
|
|
49
|
+
const onProgress = typeof options.onProgress === "function" ? options.onProgress : null;
|
|
50
|
+
const signal = options.signal;
|
|
51
|
+
|
|
52
|
+
const results = [];
|
|
53
|
+
const errors = [];
|
|
54
|
+
|
|
55
|
+
let cursor = 0;
|
|
56
|
+
let completed = 0;
|
|
57
|
+
const startedAt = Date.now();
|
|
58
|
+
|
|
59
|
+
function reportProgress(file, kind) {
|
|
60
|
+
if (!onProgress) return;
|
|
61
|
+
try {
|
|
62
|
+
onProgress({
|
|
63
|
+
kind,
|
|
64
|
+
file,
|
|
65
|
+
completed,
|
|
66
|
+
total: files.length,
|
|
67
|
+
errors: errors.length,
|
|
68
|
+
elapsedMs: Date.now() - startedAt,
|
|
69
|
+
});
|
|
70
|
+
} catch {
|
|
71
|
+
// ignore progress handler failures
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function runFile(filePath) {
|
|
76
|
+
if (signal?.aborted) {
|
|
77
|
+
const err = new Error("Aborted");
|
|
78
|
+
err.code = "ABORTED";
|
|
79
|
+
throw err;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const label = `process(${filePath})`;
|
|
83
|
+
const result = await withTimeout(Promise.resolve().then(() => processor(filePath)), timeoutMs, label);
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function worker(workerId) {
|
|
88
|
+
// eslint-disable-next-line no-constant-condition
|
|
89
|
+
while (true) {
|
|
90
|
+
if (signal?.aborted) break;
|
|
91
|
+
if (stopOnError && errors.length) break;
|
|
92
|
+
|
|
93
|
+
const i = cursor++;
|
|
94
|
+
if (i >= files.length) break;
|
|
95
|
+
|
|
96
|
+
const filePath = files[i];
|
|
97
|
+
reportProgress(filePath, "start");
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
const result = await runFile(filePath);
|
|
101
|
+
results.push({ file: filePath, result });
|
|
102
|
+
} catch (error) {
|
|
103
|
+
errors.push({ file: filePath, error });
|
|
104
|
+
reportProgress(filePath, "error");
|
|
105
|
+
} finally {
|
|
106
|
+
completed++;
|
|
107
|
+
reportProgress(filePath, "done");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const workers = Array.from({ length: Math.min(concurrency, files.length) }, (_, i) => worker(i));
|
|
113
|
+
await Promise.all(workers);
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
results,
|
|
117
|
+
errors,
|
|
118
|
+
stats: {
|
|
119
|
+
totalFiles: files.length,
|
|
120
|
+
processed: completed,
|
|
121
|
+
results: results.length,
|
|
122
|
+
errors: errors.length,
|
|
123
|
+
concurrency,
|
|
124
|
+
timeoutMs,
|
|
125
|
+
elapsedMs: Date.now() - startedAt,
|
|
126
|
+
aborted: Boolean(signal?.aborted),
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Process in sequential batches (useful when you want deterministic ordering).
|
|
133
|
+
*
|
|
134
|
+
* @param {string[]} files
|
|
135
|
+
* @param {(filePath: string) => Promise<any>} processor
|
|
136
|
+
* @param {number} batchSize
|
|
137
|
+
*/
|
|
138
|
+
async function processFilesInBatches(files, processor, batchSize = 10) {
|
|
139
|
+
const results = [];
|
|
140
|
+
const errors = [];
|
|
141
|
+
const size = Math.max(1, Number(batchSize) || 10);
|
|
142
|
+
|
|
143
|
+
for (let i = 0; i < files.length; i += size) {
|
|
144
|
+
const batch = files.slice(i, i + size);
|
|
145
|
+
const batchResults = await Promise.allSettled(batch.map((f) => Promise.resolve().then(() => processor(f))));
|
|
146
|
+
|
|
147
|
+
for (let j = 0; j < batchResults.length; j++) {
|
|
148
|
+
const file = batch[j];
|
|
149
|
+
const r = batchResults[j];
|
|
150
|
+
if (r.status === "fulfilled") {
|
|
151
|
+
results.push({ file, result: r.value });
|
|
152
|
+
} else {
|
|
153
|
+
errors.push({ file, error: r.reason });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return { results, errors };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = {
|
|
162
|
+
processFilesInParallel,
|
|
163
|
+
processFilesInBatches,
|
|
164
|
+
};
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance Issues Engine
|
|
3
|
+
* Detects potential performance problems:
|
|
4
|
+
* - Nested loops
|
|
5
|
+
* - Potential memory leaks (event listeners without cleanup)
|
|
6
|
+
* - Expensive operations in render-like contexts (heuristic)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { getAST, parseCode } = require("./ast-cache");
|
|
10
|
+
const traverse = require("@babel/traverse").default;
|
|
11
|
+
const t = require("@babel/types");
|
|
12
|
+
const { shouldExcludeFile, isTestContext, hasIgnoreDirective } = require("./file-filter");
|
|
13
|
+
|
|
14
|
+
function snippetForLine(lines, line) {
|
|
15
|
+
return lines[line - 1] ? lines[line - 1].trim() : "";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isLoopStatement(node) {
|
|
19
|
+
return (
|
|
20
|
+
t.isForStatement(node) ||
|
|
21
|
+
t.isForInStatement(node) ||
|
|
22
|
+
t.isForOfStatement(node) ||
|
|
23
|
+
t.isWhileStatement(node) ||
|
|
24
|
+
t.isDoWhileStatement(node)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getEventName(callNode) {
|
|
29
|
+
const arg0 = callNode.arguments?.[0];
|
|
30
|
+
if (t.isStringLiteral(arg0)) return arg0.value;
|
|
31
|
+
if (t.isIdentifier(arg0)) return arg0.name;
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function calleePropertyName(callNode) {
|
|
36
|
+
const callee = callNode.callee;
|
|
37
|
+
if (t.isMemberExpression(callee) && t.isIdentifier(callee.property) && !callee.computed) return callee.property.name;
|
|
38
|
+
if (t.isIdentifier(callee)) return callee.name;
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function hasMatchingRemoveEventListener(fnPath, eventName) {
|
|
43
|
+
let found = false;
|
|
44
|
+
|
|
45
|
+
fnPath.traverse({
|
|
46
|
+
Function(inner) {
|
|
47
|
+
if (inner !== fnPath) inner.skip();
|
|
48
|
+
},
|
|
49
|
+
CallExpression(p) {
|
|
50
|
+
const name = calleePropertyName(p.node);
|
|
51
|
+
if (name !== "removeEventListener") return;
|
|
52
|
+
const ev = getEventName(p.node);
|
|
53
|
+
if (!eventName || !ev) {
|
|
54
|
+
// no event info: still counts as cleanup
|
|
55
|
+
found = true;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (ev === eventName) found = true;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return found;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isLikelyRenderContext(path) {
|
|
66
|
+
// Heuristic: inside a function named render, or a React component (PascalCase) returning JSX
|
|
67
|
+
const fn = path.getFunctionParent();
|
|
68
|
+
if (!fn) return false;
|
|
69
|
+
|
|
70
|
+
const node = fn.node;
|
|
71
|
+
let name = null;
|
|
72
|
+
|
|
73
|
+
if (t.isFunctionDeclaration(node) && node.id?.name) name = node.id.name;
|
|
74
|
+
if ((t.isFunctionExpression(node) || t.isArrowFunctionExpression(node)) && t.isVariableDeclarator(fn.parent) && t.isIdentifier(fn.parent.id)) {
|
|
75
|
+
name = fn.parent.id.name;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (name === "render") return true;
|
|
79
|
+
if (name && /^[A-Z]/.test(name)) return true; // component-ish
|
|
80
|
+
|
|
81
|
+
// If function returns JSX somewhere
|
|
82
|
+
let returnsJSX = false;
|
|
83
|
+
fn.traverse({
|
|
84
|
+
Function(inner) {
|
|
85
|
+
if (inner !== fn) inner.skip();
|
|
86
|
+
},
|
|
87
|
+
ReturnStatement(r) {
|
|
88
|
+
if (t.isJSXElement(r.node.argument) || t.isJSXFragment(r.node.argument)) returnsJSX = true;
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
return returnsJSX;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function analyzePerformanceIssues(code, filePath) {
|
|
96
|
+
const findings = [];
|
|
97
|
+
|
|
98
|
+
if (shouldExcludeFile(filePath)) return findings;
|
|
99
|
+
if (isTestContext(code, filePath)) return findings;
|
|
100
|
+
if (hasIgnoreDirective(code, "performance")) return findings;
|
|
101
|
+
|
|
102
|
+
const ast = getAST(code, filePath);
|
|
103
|
+
if (!ast) return findings;
|
|
104
|
+
|
|
105
|
+
const lines = code.split("\n");
|
|
106
|
+
|
|
107
|
+
traverse(ast, {
|
|
108
|
+
// Nested loops - only flag 3+ levels deep
|
|
109
|
+
enter(path) {
|
|
110
|
+
if (!isLoopStatement(path.node)) return;
|
|
111
|
+
|
|
112
|
+
// Count nesting depth
|
|
113
|
+
let depth = 0;
|
|
114
|
+
let current = path;
|
|
115
|
+
while (current) {
|
|
116
|
+
if (isLoopStatement(current.node)) {
|
|
117
|
+
depth++;
|
|
118
|
+
}
|
|
119
|
+
current = current.parentPath;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Only flag if 3 or more levels deep
|
|
123
|
+
if (depth < 3) return;
|
|
124
|
+
|
|
125
|
+
const loc = path.node.loc?.start;
|
|
126
|
+
if (!loc) return;
|
|
127
|
+
|
|
128
|
+
findings.push({
|
|
129
|
+
type: "nested_loop",
|
|
130
|
+
severity: "WARN",
|
|
131
|
+
category: "Performance",
|
|
132
|
+
file: filePath,
|
|
133
|
+
line: loc.line,
|
|
134
|
+
column: loc.column,
|
|
135
|
+
title: `Deeply nested loop (${depth} levels)`,
|
|
136
|
+
message: "Deeply nested loops can be expensive. Consider optimizing or using better data structures.",
|
|
137
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
138
|
+
confidence: "med",
|
|
139
|
+
});
|
|
140
|
+
path.skip(); // avoid multiple nested loop reports in same subtree
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
// Event listeners without cleanup - only flag in component-like contexts
|
|
144
|
+
CallExpression(path) {
|
|
145
|
+
const callee = path.node.callee;
|
|
146
|
+
if (!t.isMemberExpression(callee)) return;
|
|
147
|
+
if (callee.computed) return;
|
|
148
|
+
if (!t.isIdentifier(callee.property, { name: "addEventListener" })) return;
|
|
149
|
+
|
|
150
|
+
const loc = path.node.loc?.start;
|
|
151
|
+
if (!loc) return;
|
|
152
|
+
|
|
153
|
+
// Skip if not in a component-like context (React, Vue, etc.)
|
|
154
|
+
const fn = path.getFunctionParent();
|
|
155
|
+
if (!fn) return;
|
|
156
|
+
|
|
157
|
+
// Only flag in component-like functions or useEffect-like hooks
|
|
158
|
+
const fnName = fn.node.id?.name || (fn.parent?.id?.name);
|
|
159
|
+
const isComponent = fnName && /^[A-Z]/.test(fnName);
|
|
160
|
+
const isEffectHook = fnName && /useEffect|useLayoutEffect|componentDidMount|componentWillUnmount/i.test(fnName);
|
|
161
|
+
|
|
162
|
+
if (!isComponent && !isEffectHook) return;
|
|
163
|
+
|
|
164
|
+
const evName = getEventName(path.node);
|
|
165
|
+
const hasCleanup = hasMatchingRemoveEventListener(fn, evName);
|
|
166
|
+
|
|
167
|
+
if (hasCleanup) return;
|
|
168
|
+
|
|
169
|
+
findings.push({
|
|
170
|
+
type: "potential_memory_leak",
|
|
171
|
+
severity: "WARN",
|
|
172
|
+
category: "Performance",
|
|
173
|
+
file: filePath,
|
|
174
|
+
line: loc.line,
|
|
175
|
+
column: loc.column,
|
|
176
|
+
title: "Event listener without cleanup",
|
|
177
|
+
message: "addEventListener() found without a matching removeEventListener() in the same function scope.",
|
|
178
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
179
|
+
confidence: "low",
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
|
|
183
|
+
// Expensive operations in render-like contexts
|
|
184
|
+
CallExpression(path) {
|
|
185
|
+
const callee = path.node.callee;
|
|
186
|
+
const loc = path.node.loc?.start;
|
|
187
|
+
if (!loc) return;
|
|
188
|
+
|
|
189
|
+
if (!isLikelyRenderContext(path)) return;
|
|
190
|
+
|
|
191
|
+
// JSON.parse / stringify in render
|
|
192
|
+
if (t.isMemberExpression(callee) && t.isIdentifier(callee.object, { name: "JSON" }) && t.isIdentifier(callee.property)) {
|
|
193
|
+
const m = callee.property.name;
|
|
194
|
+
if (m === "parse" || m === "stringify") {
|
|
195
|
+
findings.push({
|
|
196
|
+
type: "expensive_render_op",
|
|
197
|
+
severity: "INFO",
|
|
198
|
+
category: "Performance",
|
|
199
|
+
file: filePath,
|
|
200
|
+
line: loc.line,
|
|
201
|
+
column: loc.column,
|
|
202
|
+
title: `JSON.${m} in render context`,
|
|
203
|
+
message: "Consider moving JSON parsing/serialization out of render to avoid repeated work.",
|
|
204
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
205
|
+
confidence: "low",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Array.sort in render (mutates + expensive)
|
|
211
|
+
if (t.isMemberExpression(callee) && t.isIdentifier(callee.property, { name: "sort" })) {
|
|
212
|
+
findings.push({
|
|
213
|
+
type: "expensive_render_op",
|
|
214
|
+
severity: "INFO",
|
|
215
|
+
category: "Performance",
|
|
216
|
+
file: filePath,
|
|
217
|
+
line: loc.line,
|
|
218
|
+
column: loc.column,
|
|
219
|
+
title: "Array.sort in render context",
|
|
220
|
+
message: "Sorting during render can be expensive and mutates arrays. Consider sorting in memoized/selectors.",
|
|
221
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
222
|
+
confidence: "low",
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
return findings;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
module.exports = {
|
|
232
|
+
analyzePerformanceIssues,
|
|
233
|
+
parseCode,
|
|
234
|
+
};
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-Aware Engine (TypeScript focused)
|
|
3
|
+
* Detects risky TypeScript patterns: any, non-null assertions, ts-ignore, unsafe casts, missing return types on exported APIs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const { getAST, parseCode } = require("./ast-cache");
|
|
7
|
+
const traverse = require("@babel/traverse").default;
|
|
8
|
+
const t = require("@babel/types");
|
|
9
|
+
const { shouldExcludeFile, isTestContext, hasIgnoreDirective } = require("./file-filter");
|
|
10
|
+
|
|
11
|
+
function isTSFile(filePath) {
|
|
12
|
+
return filePath.endsWith(".ts") || filePath.endsWith(".tsx");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function snippetForLine(lines, line) {
|
|
16
|
+
return lines[line - 1] ? lines[line - 1].trim() : "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isExportedFunctionPath(path) {
|
|
20
|
+
// export function foo() {}
|
|
21
|
+
if (path.parentPath?.isExportNamedDeclaration?.() || path.parentPath?.isExportDefaultDeclaration?.()) return true;
|
|
22
|
+
|
|
23
|
+
// export const foo = () => {}
|
|
24
|
+
const exportDecl = path.findParent((p) => p.isExportNamedDeclaration?.());
|
|
25
|
+
if (exportDecl) return true;
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function analyzeTypeAware(code, filePath) {
|
|
31
|
+
const findings = [];
|
|
32
|
+
|
|
33
|
+
if (!isTSFile(filePath)) return findings;
|
|
34
|
+
if (shouldExcludeFile(filePath)) return findings;
|
|
35
|
+
if (isTestContext(code, filePath)) return findings;
|
|
36
|
+
if (hasIgnoreDirective(code, "type-aware")) return findings;
|
|
37
|
+
|
|
38
|
+
const ast = getAST(code, filePath);
|
|
39
|
+
if (!ast) return findings;
|
|
40
|
+
|
|
41
|
+
const lines = code.split("\n");
|
|
42
|
+
|
|
43
|
+
// Scan header comments for ts-ignore
|
|
44
|
+
const comments = ast.comments || [];
|
|
45
|
+
for (const c of comments) {
|
|
46
|
+
const v = (c.value || "").trim();
|
|
47
|
+
if (/^@ts-ignore\b/.test(v) || /^@ts-expect-error\b/.test(v)) {
|
|
48
|
+
const line = c.loc?.start?.line || 1;
|
|
49
|
+
findings.push({
|
|
50
|
+
type: "ts_ignore",
|
|
51
|
+
severity: "WARN",
|
|
52
|
+
category: "TypeSafety",
|
|
53
|
+
file: filePath,
|
|
54
|
+
line,
|
|
55
|
+
column: c.loc?.start?.column || 0,
|
|
56
|
+
title: "TypeScript ignore directive used",
|
|
57
|
+
message: `Found ${v.split(/\s+/)[0]} - this bypasses type safety.`,
|
|
58
|
+
codeSnippet: snippetForLine(lines, line),
|
|
59
|
+
confidence: "high",
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// General TS AST checks
|
|
65
|
+
traverse(ast, {
|
|
66
|
+
TSAnyKeyword(path) {
|
|
67
|
+
const loc = path.node.loc?.start;
|
|
68
|
+
if (!loc) return;
|
|
69
|
+
|
|
70
|
+
findings.push({
|
|
71
|
+
type: "any_type",
|
|
72
|
+
severity: "WARN",
|
|
73
|
+
category: "TypeSafety",
|
|
74
|
+
file: filePath,
|
|
75
|
+
line: loc.line,
|
|
76
|
+
column: loc.column,
|
|
77
|
+
title: "Usage of 'any' type",
|
|
78
|
+
message: "Avoid 'any' where possible. Prefer unknown + narrowing or a specific type.",
|
|
79
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
80
|
+
confidence: "high",
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
TSNonNullExpression(path) {
|
|
85
|
+
const loc = path.node.loc?.start;
|
|
86
|
+
if (!loc) return;
|
|
87
|
+
|
|
88
|
+
findings.push({
|
|
89
|
+
type: "non_null_assertion",
|
|
90
|
+
severity: "WARN",
|
|
91
|
+
category: "TypeSafety",
|
|
92
|
+
file: filePath,
|
|
93
|
+
line: loc.line,
|
|
94
|
+
column: loc.column,
|
|
95
|
+
title: "Non-null assertion used (!)",
|
|
96
|
+
message: "Non-null assertions can hide real null/undefined bugs. Consider proper checks.",
|
|
97
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
98
|
+
confidence: "med",
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
TSAsExpression(path) {
|
|
103
|
+
const loc = path.node.loc?.start;
|
|
104
|
+
if (!loc) return;
|
|
105
|
+
|
|
106
|
+
const typeAnn = path.node.typeAnnotation;
|
|
107
|
+
if (t.isTSAnyKeyword(typeAnn)) {
|
|
108
|
+
findings.push({
|
|
109
|
+
type: "unsafe_type_cast",
|
|
110
|
+
severity: "WARN",
|
|
111
|
+
category: "TypeSafety",
|
|
112
|
+
file: filePath,
|
|
113
|
+
line: loc.line,
|
|
114
|
+
column: loc.column,
|
|
115
|
+
title: "Unsafe type cast to 'any'",
|
|
116
|
+
message: "Casting to 'any' disables type checking. Prefer unknown + validation.",
|
|
117
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
118
|
+
confidence: "high",
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
FunctionDeclaration(path) {
|
|
124
|
+
if (!path.node.loc) return;
|
|
125
|
+
if (!isExportedFunctionPath(path)) return;
|
|
126
|
+
|
|
127
|
+
// only flag when return type is missing AND the body has at least one return
|
|
128
|
+
const hasReturnType = Boolean(path.node.returnType);
|
|
129
|
+
if (hasReturnType) return;
|
|
130
|
+
|
|
131
|
+
let returnsValue = false;
|
|
132
|
+
path.traverse({
|
|
133
|
+
Function(inner) {
|
|
134
|
+
if (inner !== path) inner.skip();
|
|
135
|
+
},
|
|
136
|
+
ReturnStatement(r) {
|
|
137
|
+
if (r.node.argument) returnsValue = true;
|
|
138
|
+
},
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (!returnsValue) return;
|
|
142
|
+
|
|
143
|
+
const line = path.node.loc.start.line;
|
|
144
|
+
findings.push({
|
|
145
|
+
type: "missing_return_type",
|
|
146
|
+
severity: "INFO",
|
|
147
|
+
category: "TypeSafety",
|
|
148
|
+
file: filePath,
|
|
149
|
+
line,
|
|
150
|
+
column: path.node.loc.start.column,
|
|
151
|
+
title: "Exported function missing explicit return type",
|
|
152
|
+
message: "Public/ exported APIs should specify return types for stability and clarity.",
|
|
153
|
+
codeSnippet: snippetForLine(lines, line),
|
|
154
|
+
confidence: "low",
|
|
155
|
+
});
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
ExportNamedDeclaration(path) {
|
|
159
|
+
// export const foo = () => {}
|
|
160
|
+
const decl = path.node.declaration;
|
|
161
|
+
if (!t.isVariableDeclaration(decl)) return;
|
|
162
|
+
|
|
163
|
+
for (const d of decl.declarations) {
|
|
164
|
+
if (!t.isVariableDeclarator(d)) continue;
|
|
165
|
+
if (!t.isIdentifier(d.id) || !d.init) continue;
|
|
166
|
+
if (!t.isArrowFunctionExpression(d.init) && !t.isFunctionExpression(d.init)) continue;
|
|
167
|
+
|
|
168
|
+
const fnNode = d.init;
|
|
169
|
+
const hasReturnType = Boolean(fnNode.returnType);
|
|
170
|
+
if (hasReturnType) continue;
|
|
171
|
+
|
|
172
|
+
// Only if it returns a value
|
|
173
|
+
let returnsValue = false;
|
|
174
|
+
traverse(
|
|
175
|
+
t.file(t.program([t.expressionStatement(fnNode)])),
|
|
176
|
+
{
|
|
177
|
+
ReturnStatement(r) {
|
|
178
|
+
if (r.node.argument) returnsValue = true;
|
|
179
|
+
},
|
|
180
|
+
Function(inner) {
|
|
181
|
+
// skip nested
|
|
182
|
+
inner.skip();
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
undefined,
|
|
186
|
+
undefined,
|
|
187
|
+
undefined
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
if (!returnsValue) continue;
|
|
191
|
+
|
|
192
|
+
const loc = fnNode.loc?.start;
|
|
193
|
+
if (!loc) continue;
|
|
194
|
+
|
|
195
|
+
findings.push({
|
|
196
|
+
type: "missing_return_type",
|
|
197
|
+
severity: "INFO",
|
|
198
|
+
category: "TypeSafety",
|
|
199
|
+
file: filePath,
|
|
200
|
+
line: loc.line,
|
|
201
|
+
column: loc.column,
|
|
202
|
+
title: "Exported function missing explicit return type",
|
|
203
|
+
message: `Exported '${d.id.name}' should specify a return type.`,
|
|
204
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
205
|
+
confidence: "low",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
return findings;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
module.exports = {
|
|
215
|
+
analyzeTypeAware,
|
|
216
|
+
parseCode,
|
|
217
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unsafe Regex Engine
|
|
3
|
+
* Detects potentially catastrophic backtracking patterns.
|
|
4
|
+
*
|
|
5
|
+
* This is heuristic-based. It aims to flag the riskiest regexes:
|
|
6
|
+
* - Nested quantifiers like (.+)+, (.*)*, (a|aa)+, ([\s\S]*)+
|
|
7
|
+
* - Ambiguous repetitions inside groups: (a|a?)+ etc
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { getAST, parseCode } = require("./ast-cache");
|
|
11
|
+
const traverse = require("@babel/traverse").default;
|
|
12
|
+
const t = require("@babel/types");
|
|
13
|
+
const { shouldExcludeFile, isTestContext, hasIgnoreDirective } = require("./file-filter");
|
|
14
|
+
|
|
15
|
+
function snippetForLine(lines, line) {
|
|
16
|
+
return lines[line - 1] ? lines[line - 1].trim() : "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function isRiskyPattern(pattern) {
|
|
20
|
+
if (!pattern || typeof pattern !== "string") return false;
|
|
21
|
+
|
|
22
|
+
// Nested quantifiers: (.*)+, (.+)+, (.*)*, (.+)*
|
|
23
|
+
if (/\((?:[^()\\]|\\.)*([+*])\)\s*[+*]/.test(pattern)) return true;
|
|
24
|
+
|
|
25
|
+
// Very broad character classes repeated aggressively
|
|
26
|
+
if (/\[(?:\\s\\S|\\S\\s|\\w\\W|\\W\\w|\\d\\D|\\D\\d)\]\s*[+*]\s*[+*]/.test(pattern)) return true;
|
|
27
|
+
|
|
28
|
+
// Alternation inside repetition: (a|aa)+ or (.*|.+)+
|
|
29
|
+
if (/\((?:[^()\\]|\\.)*\|(?:[^()\\]|\\.)*\)\s*[+*]/.test(pattern)) return true;
|
|
30
|
+
|
|
31
|
+
// Repetition of ambiguous wildcard with backreferences (commonly risky)
|
|
32
|
+
if (/(\.\*|\.\+).*\1/.test(pattern)) return true;
|
|
33
|
+
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function analyzeUnsafeRegex(code, filePath) {
|
|
38
|
+
const findings = [];
|
|
39
|
+
|
|
40
|
+
if (shouldExcludeFile(filePath)) return findings;
|
|
41
|
+
if (isTestContext(code, filePath)) return findings;
|
|
42
|
+
if (hasIgnoreDirective(code, "unsafe-regex")) return findings;
|
|
43
|
+
|
|
44
|
+
const ast = getAST(code, filePath);
|
|
45
|
+
if (!ast) return findings;
|
|
46
|
+
|
|
47
|
+
const lines = code.split("\n");
|
|
48
|
+
|
|
49
|
+
traverse(ast, {
|
|
50
|
+
RegExpLiteral(path) {
|
|
51
|
+
const pattern = path.node.pattern;
|
|
52
|
+
if (!isRiskyPattern(pattern)) return;
|
|
53
|
+
|
|
54
|
+
const loc = path.node.loc?.start;
|
|
55
|
+
if (!loc) return;
|
|
56
|
+
|
|
57
|
+
findings.push({
|
|
58
|
+
type: "unsafe_regex",
|
|
59
|
+
severity: "WARN",
|
|
60
|
+
category: "Security",
|
|
61
|
+
file: filePath,
|
|
62
|
+
line: loc.line,
|
|
63
|
+
column: loc.column,
|
|
64
|
+
title: "Potential ReDoS risk in regex",
|
|
65
|
+
message: `Regex pattern "${pattern}" may cause catastrophic backtracking.`,
|
|
66
|
+
codeSnippet: snippetForLine(lines, loc.line),
|
|
67
|
+
confidence: "med",
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
return findings;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = {
|
|
76
|
+
analyzeUnsafeRegex,
|
|
77
|
+
parseCode,
|
|
78
|
+
};
|