@neuralaxis/vibedoctor 0.1.3 → 0.2.1
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/README.md +298 -115
- package/dist/adapters/biome.js +135 -21
- package/dist/adapters/dpdp.d.ts +6 -0
- package/dist/adapters/dpdp.js +34 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js +3 -1
- package/dist/adapters/osvScanner.js +136 -17
- package/dist/adapters/presidio.js +6 -2
- package/dist/adapters/privacyDetector.d.ts +24 -1
- package/dist/adapters/privacyDetector.js +86 -2
- package/dist/adapters/shared.d.ts +6 -0
- package/dist/agentPack/templates/skills.js +159 -53
- package/dist/cli/commands/dpdp.d.ts +35 -0
- package/dist/cli/commands/dpdp.js +103 -0
- package/dist/cli/commands/init.js +105 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/scan.js +4 -1
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/cli/index.js +84 -0
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +57 -0
- package/dist/core/config.js +194 -7
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +21 -0
- package/dist/core/engine.js +484 -84
- package/dist/core/executable.d.ts +18 -0
- package/dist/core/executable.js +137 -0
- package/dist/core/fileRole.d.ts +24 -0
- package/dist/core/fileRole.js +125 -0
- package/dist/core/finding.d.ts +125 -1
- package/dist/core/finding.js +63 -5
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +171 -0
- package/dist/core/projectDetector.d.ts +13 -0
- package/dist/core/projectDetector.js +100 -15
- package/dist/core/relevance.d.ts +87 -0
- package/dist/core/relevance.js +367 -0
- package/dist/core/scanPlanner.d.ts +12 -0
- package/dist/core/scanPlanner.js +61 -29
- package/dist/core/semverLite.d.ts +27 -0
- package/dist/core/semverLite.js +163 -0
- package/dist/core/suppressions.d.ts +96 -0
- package/dist/core/suppressions.js +302 -0
- package/dist/core/toolRegistry.d.ts +58 -0
- package/dist/core/toolRegistry.js +247 -0
- package/dist/core/toolRunner.d.ts +23 -2
- package/dist/core/toolRunner.js +61 -93
- package/dist/core/toolVerification.d.ts +87 -0
- package/dist/core/toolVerification.js +370 -0
- package/dist/dpdp/artifacts.d.ts +11 -0
- package/dist/dpdp/artifacts.js +120 -0
- package/dist/dpdp/catalogue.d.ts +14 -0
- package/dist/dpdp/catalogue.js +661 -0
- package/dist/dpdp/collectors/confidence.d.ts +9 -0
- package/dist/dpdp/collectors/confidence.js +25 -0
- package/dist/dpdp/collectors/dependencies.d.ts +7 -0
- package/dist/dpdp/collectors/dependencies.js +63 -0
- package/dist/dpdp/collectors/index.d.ts +24 -0
- package/dist/dpdp/collectors/index.js +71 -0
- package/dist/dpdp/collectors/lifecycle.d.ts +2 -0
- package/dist/dpdp/collectors/lifecycle.js +202 -0
- package/dist/dpdp/collectors/optionalScanners.d.ts +14 -0
- package/dist/dpdp/collectors/optionalScanners.js +437 -0
- package/dist/dpdp/collectors/privacyBridge.d.ts +13 -0
- package/dist/dpdp/collectors/privacyBridge.js +152 -0
- package/dist/dpdp/collectors/safeguards.d.ts +5 -0
- package/dist/dpdp/collectors/safeguards.js +186 -0
- package/dist/dpdp/collectors/schema.d.ts +6 -0
- package/dist/dpdp/collectors/schema.js +122 -0
- package/dist/dpdp/collectors/shared.d.ts +10 -0
- package/dist/dpdp/collectors/shared.js +43 -0
- package/dist/dpdp/context.d.ts +28 -0
- package/dist/dpdp/context.js +195 -0
- package/dist/dpdp/dataMap.d.ts +7 -0
- package/dist/dpdp/dataMap.js +339 -0
- package/dist/dpdp/evaluators.d.ts +20 -0
- package/dist/dpdp/evaluators.js +522 -0
- package/dist/dpdp/evidence.d.ts +11 -0
- package/dist/dpdp/evidence.js +123 -0
- package/dist/dpdp/findings.d.ts +44 -0
- package/dist/dpdp/findings.js +286 -0
- package/dist/dpdp/gates.d.ts +14 -0
- package/dist/dpdp/gates.js +47 -0
- package/dist/dpdp/index.d.ts +16 -0
- package/dist/dpdp/index.js +32 -0
- package/dist/dpdp/legalSources.d.ts +10 -0
- package/dist/dpdp/legalSources.js +104 -0
- package/dist/dpdp/paths.d.ts +25 -0
- package/dist/dpdp/paths.js +85 -0
- package/dist/dpdp/report.d.ts +6 -0
- package/dist/dpdp/report.js +222 -0
- package/dist/dpdp/reviewQueue.d.ts +3 -0
- package/dist/dpdp/reviewQueue.js +88 -0
- package/dist/dpdp/scan.d.ts +26 -0
- package/dist/dpdp/scan.js +310 -0
- package/dist/dpdp/scoring.d.ts +41 -0
- package/dist/dpdp/scoring.js +237 -0
- package/dist/dpdp/types.d.ts +312 -0
- package/dist/dpdp/types.js +86 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/tools/dpdp.d.ts +11 -0
- package/dist/mcp/tools/dpdp.js +151 -0
- package/dist/mcp/tools/index.js +3 -1
- package/dist/reporters/html.js +57 -13
- package/dist/reporters/json.js +12 -1
- package/dist/reporters/markdown.js +46 -4
- package/dist/reporters/sarif.js +54 -5
- package/package.json +4 -1
package/dist/adapters/biome.js
CHANGED
|
@@ -3,15 +3,68 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.biomeAdapter = void 0;
|
|
4
4
|
const finding_1 = require("../core/finding");
|
|
5
5
|
const shared_1 = require("./shared");
|
|
6
|
+
/**
|
|
7
|
+
* Biome writes Windows paths into JSON strings without escaping the separator,
|
|
8
|
+
* producing output that is not valid JSON (`"src\core\finding.ts"`). Parsing
|
|
9
|
+
* threw, and the engine swallowed the error, so Biome silently contributed
|
|
10
|
+
* nothing on every Windows repository.
|
|
11
|
+
*
|
|
12
|
+
* The repair is confined to the `path` field. A blanket pass over the whole
|
|
13
|
+
* document would corrupt diagnostic text, because `\n` and `\t` are both real
|
|
14
|
+
* escapes there and plausible path segments here (`\node_modules`, `\test`) —
|
|
15
|
+
* only in a path is a backslash unambiguously a separator.
|
|
16
|
+
*/
|
|
17
|
+
function repairPathSeparators(raw) {
|
|
18
|
+
return raw.replace(/("path"\s*:\s*")((?:[^"\\]|\\.)*)(")/g, (_match, open, value, close) => {
|
|
19
|
+
return `${open}${value.replaceAll("\\", "\\\\")}${close}`;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** Last resort: escape any backslash that does not begin a valid JSON escape. */
|
|
23
|
+
function repairInvalidEscapes(raw) {
|
|
24
|
+
return raw.replace(/\\(?!["\\/bfnrtu])/g, "\\\\");
|
|
25
|
+
}
|
|
6
26
|
function parseBiomeOutput(stdout) {
|
|
7
27
|
const trimmed = stdout.trim();
|
|
8
28
|
if (!trimmed) {
|
|
9
29
|
return [];
|
|
10
30
|
}
|
|
11
|
-
|
|
12
|
-
|
|
31
|
+
// Each fallback assumes more than the last, so the least invasive repair that
|
|
32
|
+
// works is the one that gets used.
|
|
33
|
+
for (const candidate of [trimmed, repairPathSeparators(trimmed), repairInvalidEscapes(trimmed)]) {
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(candidate).diagnostics ?? [];
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Let the caller record a parse failure; a tool whose output cannot be read
|
|
42
|
+
// has not checked anything, and must not look like a clean run.
|
|
43
|
+
throw new SyntaxError("Biome output was not valid JSON, even after repairing path separators.");
|
|
44
|
+
}
|
|
45
|
+
function readMessage(item) {
|
|
46
|
+
if (typeof item.message === "string") {
|
|
47
|
+
return item.message;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(item.message)) {
|
|
50
|
+
const text = item.message
|
|
51
|
+
.map((chunk) => (typeof chunk === "string" ? chunk : (chunk.content ?? "")))
|
|
52
|
+
.join("")
|
|
53
|
+
.trim();
|
|
54
|
+
if (text) {
|
|
55
|
+
return text;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return item.description;
|
|
59
|
+
}
|
|
60
|
+
function readFile(item) {
|
|
61
|
+
const path = item.location?.path;
|
|
62
|
+
return typeof path === "string" ? path : path?.file;
|
|
13
63
|
}
|
|
14
64
|
function mapSeverity(level) {
|
|
65
|
+
if (level === "fatal") {
|
|
66
|
+
return "high";
|
|
67
|
+
}
|
|
15
68
|
if (level === "error") {
|
|
16
69
|
return "medium";
|
|
17
70
|
}
|
|
@@ -20,6 +73,49 @@ function mapSeverity(level) {
|
|
|
20
73
|
}
|
|
21
74
|
return "info";
|
|
22
75
|
}
|
|
76
|
+
/** Biome reports zero-based line and column numbers; editors and reports use one-based. */
|
|
77
|
+
function toOneBased(value) {
|
|
78
|
+
return typeof value === "number" ? value + 1 : undefined;
|
|
79
|
+
}
|
|
80
|
+
function readLocation(location) {
|
|
81
|
+
if (!location) {
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
if (location.start) {
|
|
85
|
+
return {
|
|
86
|
+
startLine: toOneBased(location.start.line),
|
|
87
|
+
endLine: toOneBased(location.end?.line ?? location.start.line),
|
|
88
|
+
startColumn: toOneBased(location.start.column)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
const span = location.span;
|
|
92
|
+
if (!span) {
|
|
93
|
+
return {};
|
|
94
|
+
}
|
|
95
|
+
if (Array.isArray(span)) {
|
|
96
|
+
const [start, end] = span;
|
|
97
|
+
return {
|
|
98
|
+
startOffset: typeof start === "number" ? start : undefined,
|
|
99
|
+
endOffset: typeof end === "number" ? end : undefined
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
startLine: toOneBased(span.start?.line),
|
|
104
|
+
endLine: toOneBased(span.end?.line),
|
|
105
|
+
startColumn: toOneBased(span.start?.column)
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Biome's rule categories double as its rule identifiers, and the safe-fix
|
|
110
|
+
* boundary follows the rule group: formatting and simple lint rules are safe to
|
|
111
|
+
* apply unattended, while `suspicious`/`security` rules generally need a human.
|
|
112
|
+
*/
|
|
113
|
+
function isSafeToAutofix(category) {
|
|
114
|
+
if (!category) {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return /^(?:format|lint\/(?:style|complexity|correctness|performance|nursery))/.test(category);
|
|
118
|
+
}
|
|
23
119
|
exports.biomeAdapter = {
|
|
24
120
|
id: "biome",
|
|
25
121
|
category: "correctness",
|
|
@@ -36,25 +132,43 @@ exports.biomeAdapter = {
|
|
|
36
132
|
};
|
|
37
133
|
},
|
|
38
134
|
parseResult(result, ctx) {
|
|
39
|
-
return parseBiomeOutput(result.stdout).map((item, index) =>
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
135
|
+
return parseBiomeOutput(result.stdout).map((item, index) => {
|
|
136
|
+
const rawFile = readFile(item);
|
|
137
|
+
const file = (0, finding_1.normalizeFilePath)(rawFile, ctx.root);
|
|
138
|
+
const location = readLocation(item.location);
|
|
139
|
+
const safeToAutofix = isSafeToAutofix(item.category);
|
|
140
|
+
return {
|
|
141
|
+
id: `biome:${file ?? "unknown"}:${location.startOffset ?? location.startLine ?? index}:${item.category ?? index}`,
|
|
142
|
+
source: "biome",
|
|
143
|
+
category: "correctness",
|
|
144
|
+
severity: mapSeverity(item.severity),
|
|
145
|
+
confidence: "high",
|
|
146
|
+
title: item.category ?? "biome",
|
|
147
|
+
message: readMessage(item) ?? "Biome reported an issue.",
|
|
148
|
+
file,
|
|
149
|
+
startLine: location.startLine,
|
|
150
|
+
endLine: location.endLine,
|
|
151
|
+
startColumn: location.startColumn,
|
|
152
|
+
isNew: true,
|
|
153
|
+
isAutofixable: true,
|
|
154
|
+
safeToAutofix,
|
|
155
|
+
// Point the fix at the file that needs it rather than the whole
|
|
156
|
+
// repository, so applying one finding's fix cannot rewrite unrelated code.
|
|
157
|
+
fixCommand: file ? `biome check ${file} --write` : "biome check . --write",
|
|
158
|
+
agentInstruction: safeToAutofix
|
|
159
|
+
? "Apply Biome's safe write mode for this file."
|
|
160
|
+
: "Review this rule before applying Biome's fix; it can change behaviour.",
|
|
161
|
+
tags: ["javascript", "typescript", ...(item.tags ?? [])],
|
|
162
|
+
evidence: {
|
|
163
|
+
toolRawId: item.category,
|
|
164
|
+
// Offsets are converted to line and column during normalization, which
|
|
165
|
+
// is where every tool's position model is reconciled.
|
|
166
|
+
startOffset: location.startOffset,
|
|
167
|
+
endOffset: location.endOffset
|
|
168
|
+
},
|
|
169
|
+
scoreImpact: 0
|
|
170
|
+
};
|
|
171
|
+
});
|
|
58
172
|
},
|
|
59
173
|
buildFixCommand(ctx) {
|
|
60
174
|
const targets = (0, shared_1.adapterTargets)(ctx, /\.(?:js|jsx|ts|tsx|json|jsonc)$/i);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dpdpAdapter = void 0;
|
|
4
|
+
const scan_1 = require("../dpdp/scan");
|
|
5
|
+
/**
|
|
6
|
+
* DPDP technical readiness adapter.
|
|
7
|
+
* Produces findings from the deterministic DPDP package and writes DPDP artifacts.
|
|
8
|
+
*/
|
|
9
|
+
exports.dpdpAdapter = {
|
|
10
|
+
id: "dpdp",
|
|
11
|
+
category: "privacy",
|
|
12
|
+
async detect(_project, config) {
|
|
13
|
+
return config.checks.dpdp.enabled;
|
|
14
|
+
},
|
|
15
|
+
async runStandalone(ctx) {
|
|
16
|
+
const mode = ctx.scanMode === "changed" ? "changed" : ctx.scanMode === "quick" ? "default" : "full";
|
|
17
|
+
const result = await (0, scan_1.runDpdpScan)(ctx.root, mode, {
|
|
18
|
+
context: ctx,
|
|
19
|
+
optionalScannersEnabled: ctx.scanMode !== "quick"
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
findings: result.findings,
|
|
23
|
+
status: {
|
|
24
|
+
command: "dpdp",
|
|
25
|
+
stdout: `DPDP technical posture ${result.scores.technicalPostureScore}/100`,
|
|
26
|
+
stderr: "",
|
|
27
|
+
exitCode: 0,
|
|
28
|
+
durationMs: 0,
|
|
29
|
+
status: "ok"
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
installHint: "Built-in DPDP technical readiness module. No external install needed."
|
|
34
|
+
};
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -16,4 +16,5 @@ export { tscAdapter } from "./tsc";
|
|
|
16
16
|
export { vitestAdapter } from "./vitest";
|
|
17
17
|
export { vultureAdapter } from "./vulture";
|
|
18
18
|
export { privacyDetectorAdapter } from "./privacyDetector";
|
|
19
|
+
export { dpdpAdapter } from "./dpdp";
|
|
19
20
|
export { telemetryDetectorAdapter } from "./telemetryDetector";
|
package/dist/adapters/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.telemetryDetectorAdapter = exports.privacyDetectorAdapter = exports.vultureAdapter = exports.vitestAdapter = exports.tscAdapter = exports.semgrepAdapter = exports.ruffAdapter = exports.radonAdapter = exports.pyrightAdapter = exports.presidioAdapter = exports.osvScannerAdapter = exports.lizardAdapter = exports.knipAdapter = exports.jscpdAdapter = exports.jestAdapter = exports.gitleaksAdapter = exports.deptryAdapter = exports.coveragePyAdapter = exports.biomeAdapter = void 0;
|
|
3
|
+
exports.telemetryDetectorAdapter = exports.dpdpAdapter = exports.privacyDetectorAdapter = exports.vultureAdapter = exports.vitestAdapter = exports.tscAdapter = exports.semgrepAdapter = exports.ruffAdapter = exports.radonAdapter = exports.pyrightAdapter = exports.presidioAdapter = exports.osvScannerAdapter = exports.lizardAdapter = exports.knipAdapter = exports.jscpdAdapter = exports.jestAdapter = exports.gitleaksAdapter = exports.deptryAdapter = exports.coveragePyAdapter = exports.biomeAdapter = void 0;
|
|
4
4
|
var biome_1 = require("./biome");
|
|
5
5
|
Object.defineProperty(exports, "biomeAdapter", { enumerable: true, get: function () { return biome_1.biomeAdapter; } });
|
|
6
6
|
var coveragePy_1 = require("./coveragePy");
|
|
@@ -37,5 +37,7 @@ var vulture_1 = require("./vulture");
|
|
|
37
37
|
Object.defineProperty(exports, "vultureAdapter", { enumerable: true, get: function () { return vulture_1.vultureAdapter; } });
|
|
38
38
|
var privacyDetector_1 = require("./privacyDetector");
|
|
39
39
|
Object.defineProperty(exports, "privacyDetectorAdapter", { enumerable: true, get: function () { return privacyDetector_1.privacyDetectorAdapter; } });
|
|
40
|
+
var dpdp_1 = require("./dpdp");
|
|
41
|
+
Object.defineProperty(exports, "dpdpAdapter", { enumerable: true, get: function () { return dpdp_1.dpdpAdapter; } });
|
|
40
42
|
var telemetryDetector_1 = require("./telemetryDetector");
|
|
41
43
|
Object.defineProperty(exports, "telemetryDetectorAdapter", { enumerable: true, get: function () { return telemetryDetector_1.telemetryDetectorAdapter; } });
|
|
@@ -13,13 +13,72 @@ function parseOsv(stdout) {
|
|
|
13
13
|
for (const vulnerability of pkg.vulnerabilities ?? []) {
|
|
14
14
|
findings.push({
|
|
15
15
|
...vulnerability,
|
|
16
|
-
package: vulnerability.package ?? pkg.package
|
|
16
|
+
package: vulnerability.package ?? pkg.package,
|
|
17
|
+
sourcePath: result.source?.path,
|
|
18
|
+
dependencyGroups: pkg.dependency_groups
|
|
17
19
|
});
|
|
18
20
|
}
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
return findings;
|
|
22
24
|
}
|
|
25
|
+
/** First version that fixes the advisory, read from the affected-range events. */
|
|
26
|
+
function firstFixedVersion(item) {
|
|
27
|
+
for (const affected of item.affected ?? []) {
|
|
28
|
+
for (const range of affected.ranges ?? []) {
|
|
29
|
+
const fixed = range.events?.find((event) => event.fixed)?.fixed;
|
|
30
|
+
if (fixed) {
|
|
31
|
+
return fixed;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Determines whether the vulnerable package ships to production.
|
|
39
|
+
*
|
|
40
|
+
* A remote-code-execution advisory in a dev server and one in a PDF renderer that
|
|
41
|
+
* runs on user input are not comparable risks, and a report that lists both as
|
|
42
|
+
* "critical dependency vulnerability" makes them look identical. OSV reports
|
|
43
|
+
* dependency groups where the ecosystem supports it; otherwise the project's own
|
|
44
|
+
* manifest is the authority.
|
|
45
|
+
*/
|
|
46
|
+
function resolveScope(item, ctx) {
|
|
47
|
+
const groups = item.dependencyGroups?.map((group) => group.toLowerCase()) ?? [];
|
|
48
|
+
if (groups.includes("dev") || groups.includes("development")) {
|
|
49
|
+
return "dev";
|
|
50
|
+
}
|
|
51
|
+
if (groups.includes("optional")) {
|
|
52
|
+
return "optional";
|
|
53
|
+
}
|
|
54
|
+
if (groups.length > 0) {
|
|
55
|
+
return "runtime";
|
|
56
|
+
}
|
|
57
|
+
const name = item.package?.name;
|
|
58
|
+
if (!name) {
|
|
59
|
+
return "unknown";
|
|
60
|
+
}
|
|
61
|
+
const manifest = ctx.project.declaredDependencies;
|
|
62
|
+
if (!manifest) {
|
|
63
|
+
return "unknown";
|
|
64
|
+
}
|
|
65
|
+
// Ecosystems disagree on case normalization (PyPI names are case-insensitive),
|
|
66
|
+
// so compare case-insensitively rather than missing a match on capitalization.
|
|
67
|
+
const needle = name.toLowerCase();
|
|
68
|
+
const has = (names) => names.some((candidate) => candidate.toLowerCase() === needle);
|
|
69
|
+
if (has(manifest.runtime)) {
|
|
70
|
+
return "runtime";
|
|
71
|
+
}
|
|
72
|
+
if (has(manifest.dev)) {
|
|
73
|
+
return "dev";
|
|
74
|
+
}
|
|
75
|
+
if (has(manifest.optional)) {
|
|
76
|
+
return "optional";
|
|
77
|
+
}
|
|
78
|
+
// Present in the lockfile but in no manifest section: it arrived through
|
|
79
|
+
// another package.
|
|
80
|
+
return "transitive";
|
|
81
|
+
}
|
|
23
82
|
function severityFromCvss(item) {
|
|
24
83
|
const namedSeverity = item.database_specific?.severity?.toLowerCase();
|
|
25
84
|
if (namedSeverity === "critical" || namedSeverity === "high" || namedSeverity === "medium" || namedSeverity === "low") {
|
|
@@ -59,22 +118,82 @@ exports.osvScannerAdapter = {
|
|
|
59
118
|
timeoutMs: 60_000
|
|
60
119
|
};
|
|
61
120
|
},
|
|
62
|
-
parseResult(result) {
|
|
63
|
-
return parseOsv(result.stdout).map((item, index) =>
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
121
|
+
parseResult(result, ctx) {
|
|
122
|
+
return parseOsv(result.stdout).map((item, index) => {
|
|
123
|
+
const name = item.package?.name ?? "unknown";
|
|
124
|
+
const version = item.package?.version;
|
|
125
|
+
const scope = resolveScope(item, ctx);
|
|
126
|
+
const fixedIn = firstFixedVersion(item);
|
|
127
|
+
const baseSeverity = severityFromCvss(item);
|
|
128
|
+
// A dev-only advisory is real but not shipped. Keeping it at the advisory's
|
|
129
|
+
// raw severity is what made a build-tool notice indistinguishable from a
|
|
130
|
+
// vulnerability in code that touches user input.
|
|
131
|
+
const severity = scope === "dev" || scope === "optional"
|
|
132
|
+
? baseSeverity === "critical"
|
|
133
|
+
? "medium"
|
|
134
|
+
: baseSeverity === "high"
|
|
135
|
+
? "medium"
|
|
136
|
+
: "low"
|
|
137
|
+
: baseSeverity;
|
|
138
|
+
const scopeLabel = scope === "dev"
|
|
139
|
+
? "development-only dependency"
|
|
140
|
+
: scope === "optional"
|
|
141
|
+
? "optional dependency"
|
|
142
|
+
: scope === "transitive"
|
|
143
|
+
? "transitive dependency"
|
|
144
|
+
: scope === "runtime"
|
|
145
|
+
? "runtime dependency"
|
|
146
|
+
: "dependency (scope undetermined)";
|
|
147
|
+
return {
|
|
148
|
+
id: `osv:${name}:${version ?? "unknown"}:${item.id ?? index}`,
|
|
149
|
+
source: "osv-scanner",
|
|
150
|
+
category: "dependencies",
|
|
151
|
+
severity,
|
|
152
|
+
confidence: "high",
|
|
153
|
+
title: item.id ?? "Dependency vulnerability",
|
|
154
|
+
message: [
|
|
155
|
+
`${name}${version ? `@${version}` : ""} (${scopeLabel}):`,
|
|
156
|
+
item.summary ?? "Known vulnerability detected.",
|
|
157
|
+
fixedIn ? `Fixed in ${fixedIn}.` : "No fixed version is published yet."
|
|
158
|
+
].join(" "),
|
|
159
|
+
isNew: true,
|
|
160
|
+
isAutofixable: false,
|
|
161
|
+
safeToAutofix: false,
|
|
162
|
+
agentInstruction: fixedIn
|
|
163
|
+
? `Upgrade ${name} to ${fixedIn} or later, then rerun tests.`
|
|
164
|
+
: `No fix is available for ${name}; assess whether the vulnerable code path is reachable, or replace the dependency.`,
|
|
165
|
+
tags: ["dependencies", "security", `scope:${scope}`],
|
|
166
|
+
package: {
|
|
167
|
+
name,
|
|
168
|
+
version,
|
|
169
|
+
ecosystem: item.package?.ecosystem,
|
|
170
|
+
scope,
|
|
171
|
+
fixedIn,
|
|
172
|
+
manifest: item.sourcePath
|
|
173
|
+
},
|
|
174
|
+
remediation: {
|
|
175
|
+
kind: "dependency",
|
|
176
|
+
component: name,
|
|
177
|
+
steps: fixedIn
|
|
178
|
+
? [`Upgrade ${name} from ${version ?? "the installed version"} to ${fixedIn} or later.`, "Run the test suite."]
|
|
179
|
+
: [
|
|
180
|
+
`Check whether the vulnerable code path in ${name} is reachable from this project.`,
|
|
181
|
+
"If it is, pin to a safe version, patch, or replace the dependency."
|
|
182
|
+
],
|
|
183
|
+
requiredEvidence: fixedIn ? `Lockfile showing ${name} at ${fixedIn} or later.` : "Reachability assessment for the advisory."
|
|
184
|
+
},
|
|
185
|
+
evidence: {
|
|
186
|
+
toolRawId: item.id,
|
|
187
|
+
reasons: [
|
|
188
|
+
`Advisory severity: ${baseSeverity}.`,
|
|
189
|
+
severity === baseSeverity
|
|
190
|
+
? `Reported at advisory severity because ${name} is a ${scopeLabel}.`
|
|
191
|
+
: `Reduced from ${baseSeverity} to ${severity} because ${name} is a ${scopeLabel} and does not ship to production.`
|
|
192
|
+
]
|
|
193
|
+
},
|
|
194
|
+
scoreImpact: 0
|
|
195
|
+
};
|
|
196
|
+
});
|
|
78
197
|
},
|
|
79
198
|
installHint: "Install OSV-Scanner from https://google.github.io/osv-scanner/"
|
|
80
199
|
};
|
|
@@ -114,6 +114,8 @@ exports.presidioAdapter = {
|
|
|
114
114
|
id: "presidio",
|
|
115
115
|
category: "privacy",
|
|
116
116
|
async detect(_project, config) {
|
|
117
|
+
// This adapter belongs to the normal privacy scan. DPDP has an independent
|
|
118
|
+
// opt-out switch and invokes/reuses this adapter through its collector.
|
|
117
119
|
return config.checks.privacy.enabled && config.checks.privacy.presidio.enabled;
|
|
118
120
|
},
|
|
119
121
|
async runStandalone(ctx) {
|
|
@@ -124,7 +126,9 @@ exports.presidioAdapter = {
|
|
|
124
126
|
cmd: "python",
|
|
125
127
|
args: ["-c", PRESIDIO_SCRIPT, ctx.root],
|
|
126
128
|
cwd: ctx.root,
|
|
127
|
-
|
|
129
|
+
// Respect the configured budget rather than a fixed ceiling, so
|
|
130
|
+
// runtime.tool_timeouts governs every tool uniformly.
|
|
131
|
+
timeoutMs: Math.max(1, ctx.config.runtime.toolTimeouts.presidio ?? ctx.config.runtime.defaultTimeoutSeconds) * 1000,
|
|
128
132
|
env: {
|
|
129
133
|
VIBEDOCTOR_PRESIDIO_FILES: JSON.stringify(files),
|
|
130
134
|
VIBEDOCTOR_PRESIDIO_MAX_FILE_BYTES: String(ctx.config.checks.privacy.maxFileBytes)
|
|
@@ -154,5 +158,5 @@ exports.presidioAdapter = {
|
|
|
154
158
|
status
|
|
155
159
|
};
|
|
156
160
|
},
|
|
157
|
-
installHint: "Optional privacy scanner.
|
|
161
|
+
installHint: "Optional privacy scanner (on by default). Install: python -m pip install presidio-analyzer. Opt out of normal privacy scans with checks.privacy.presidio.enabled: false."
|
|
158
162
|
};
|
|
@@ -5,6 +5,29 @@ export declare function confidenceFromScore(score: number): Confidence;
|
|
|
5
5
|
export declare function passesLuhn(value: string): boolean;
|
|
6
6
|
export declare function isValidAadhaar(value: string): boolean;
|
|
7
7
|
export declare function maskPiiValue(value: string, entityType: string, maskExamples?: boolean): string;
|
|
8
|
-
export
|
|
8
|
+
export type DetectPiiFindingsOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* When set, only these files are scanned (already path-normalized preferred).
|
|
11
|
+
* Used by DPDP changed-scope collection so privacy reuse the same allowlist.
|
|
12
|
+
*/
|
|
13
|
+
fileAllowlist?: string[];
|
|
14
|
+
/** Override include patterns (defaults to config.paths.include). Ignored when fileAllowlist is set. */
|
|
15
|
+
include?: string[];
|
|
16
|
+
/** Override exclude patterns (defaults to config.paths.exclude). Ignored when fileAllowlist is set. */
|
|
17
|
+
exclude?: string[];
|
|
18
|
+
/** Bypass process-lifetime cache (tests / forced refresh). */
|
|
19
|
+
skipCache?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare function clearPrivacyFindingsCache(): void;
|
|
22
|
+
export declare function getPrivacyFindingsCacheStats(): {
|
|
23
|
+
size: number;
|
|
24
|
+
hits: number;
|
|
25
|
+
misses: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Deterministic privacy scan with process-lifetime cache.
|
|
29
|
+
* Concurrent callers with the same key share one in-flight computation (dedupes privacy + DPDP double walks).
|
|
30
|
+
*/
|
|
31
|
+
export declare function detectPiiFindings(ctx: ToolAdapterContext, options?: DetectPiiFindingsOptions): Promise<Finding[]>;
|
|
9
32
|
export declare const privacyDetectorAdapter: ToolAdapter;
|
|
10
33
|
export declare function normalizeExternalFile(file: string | undefined, root: string): string | undefined;
|
|
@@ -8,6 +8,8 @@ exports.confidenceFromScore = confidenceFromScore;
|
|
|
8
8
|
exports.passesLuhn = passesLuhn;
|
|
9
9
|
exports.isValidAadhaar = isValidAadhaar;
|
|
10
10
|
exports.maskPiiValue = maskPiiValue;
|
|
11
|
+
exports.clearPrivacyFindingsCache = clearPrivacyFindingsCache;
|
|
12
|
+
exports.getPrivacyFindingsCacheStats = getPrivacyFindingsCacheStats;
|
|
11
13
|
exports.detectPiiFindings = detectPiiFindings;
|
|
12
14
|
exports.normalizeExternalFile = normalizeExternalFile;
|
|
13
15
|
const node_fs_1 = require("node:fs");
|
|
@@ -459,9 +461,64 @@ async function readCandidate(root, file, maxFileBytes) {
|
|
|
459
461
|
function passesConfidenceThreshold(finding, minimum) {
|
|
460
462
|
return CONFIDENCE_RANK[finding.confidence] >= CONFIDENCE_RANK[minimum];
|
|
461
463
|
}
|
|
462
|
-
|
|
464
|
+
/** Process-lifetime cache: privacy adapter + DPDP collectors often scan the same tree once per run. */
|
|
465
|
+
const privacyFindingsCache = new Map();
|
|
466
|
+
let privacyCacheHits = 0;
|
|
467
|
+
let privacyCacheMisses = 0;
|
|
468
|
+
function clearPrivacyFindingsCache() {
|
|
469
|
+
privacyFindingsCache.clear();
|
|
470
|
+
privacyCacheHits = 0;
|
|
471
|
+
privacyCacheMisses = 0;
|
|
472
|
+
}
|
|
473
|
+
function getPrivacyFindingsCacheStats() {
|
|
474
|
+
return {
|
|
475
|
+
size: privacyFindingsCache.size,
|
|
476
|
+
hits: privacyCacheHits,
|
|
477
|
+
misses: privacyCacheMisses
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function privacyConfigFingerprint(ctx) {
|
|
481
|
+
const privacy = ctx.config.checks.privacy;
|
|
482
|
+
return JSON.stringify({
|
|
483
|
+
minConfidenceToReport: privacy.minConfidenceToReport,
|
|
484
|
+
maskExamples: privacy.maskExamples,
|
|
485
|
+
maxFileBytes: privacy.maxFileBytes,
|
|
486
|
+
detectUnsanitizedLogs: privacy.detectUnsanitizedLogs,
|
|
487
|
+
detectApiOverfetching: privacy.detectApiOverfetching,
|
|
488
|
+
detectMissingRetention: privacy.detectMissingRetention
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
function resolvePrivacyCandidates(ctx, options) {
|
|
492
|
+
if (options.fileAllowlist !== undefined) {
|
|
493
|
+
return options.fileAllowlist.filter(isTextCandidate).map((file) => file.replaceAll("\\", "/")).sort();
|
|
494
|
+
}
|
|
495
|
+
return (0, paths_1.filterPaths)(ctx.project.projectFiles, options.include ?? ctx.config.paths.include, options.exclude ?? ctx.config.paths.exclude)
|
|
496
|
+
.filter(isTextCandidate)
|
|
497
|
+
.map((file) => file.replaceAll("\\", "/"))
|
|
498
|
+
.sort();
|
|
499
|
+
}
|
|
500
|
+
async function buildPrivacyFindingsCacheKey(ctx, options, candidates) {
|
|
501
|
+
const fileVersions = [];
|
|
502
|
+
for (const candidate of candidates) {
|
|
503
|
+
const stat = await node_fs_1.promises.stat(node_path_1.default.join(ctx.root, candidate)).catch(() => undefined);
|
|
504
|
+
fileVersions.push(`${candidate}:${stat?.size ?? -1}:${stat?.mtimeMs ?? -1}`);
|
|
505
|
+
}
|
|
506
|
+
return [
|
|
507
|
+
ctx.root,
|
|
508
|
+
privacyConfigFingerprint(ctx),
|
|
509
|
+
fileVersions.join("\n"),
|
|
510
|
+
JSON.stringify({
|
|
511
|
+
include: options.include ?? null,
|
|
512
|
+
exclude: options.exclude ?? null,
|
|
513
|
+
allowlist: options.fileAllowlist !== undefined
|
|
514
|
+
})
|
|
515
|
+
].join("::");
|
|
516
|
+
}
|
|
517
|
+
function cloneFindings(findings) {
|
|
518
|
+
return structuredClone(findings);
|
|
519
|
+
}
|
|
520
|
+
async function detectPiiFindingsUncached(ctx, candidates) {
|
|
463
521
|
const privacyCfg = ctx.config.checks.privacy;
|
|
464
|
-
const candidates = (0, paths_1.filterPaths)(ctx.project.projectFiles, ctx.config.paths.include, ctx.config.paths.exclude).filter(isTextCandidate);
|
|
465
522
|
const findings = [];
|
|
466
523
|
for (const file of candidates) {
|
|
467
524
|
const content = await readCandidate(ctx.root, file, privacyCfg.maxFileBytes);
|
|
@@ -583,6 +640,33 @@ async function detectPiiFindings(ctx) {
|
|
|
583
640
|
}
|
|
584
641
|
return findings.filter((finding) => passesConfidenceThreshold(finding, privacyCfg.minConfidenceToReport));
|
|
585
642
|
}
|
|
643
|
+
/**
|
|
644
|
+
* Deterministic privacy scan with process-lifetime cache.
|
|
645
|
+
* Concurrent callers with the same key share one in-flight computation (dedupes privacy + DPDP double walks).
|
|
646
|
+
*/
|
|
647
|
+
async function detectPiiFindings(ctx, options = {}) {
|
|
648
|
+
const candidates = resolvePrivacyCandidates(ctx, options);
|
|
649
|
+
if (options.skipCache) {
|
|
650
|
+
return detectPiiFindingsUncached(ctx, candidates);
|
|
651
|
+
}
|
|
652
|
+
const key = await buildPrivacyFindingsCacheKey(ctx, options, candidates);
|
|
653
|
+
const existing = privacyFindingsCache.get(key);
|
|
654
|
+
if (existing) {
|
|
655
|
+
privacyCacheHits += 1;
|
|
656
|
+
return cloneFindings(await existing);
|
|
657
|
+
}
|
|
658
|
+
privacyCacheMisses += 1;
|
|
659
|
+
const pending = detectPiiFindingsUncached(ctx, candidates);
|
|
660
|
+
privacyFindingsCache.set(key, pending);
|
|
661
|
+
try {
|
|
662
|
+
const findings = await pending;
|
|
663
|
+
return cloneFindings(findings);
|
|
664
|
+
}
|
|
665
|
+
catch (error) {
|
|
666
|
+
privacyFindingsCache.delete(key);
|
|
667
|
+
throw error;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
586
670
|
exports.privacyDetectorAdapter = {
|
|
587
671
|
id: "privacy-detector",
|
|
588
672
|
category: "privacy",
|
|
@@ -7,6 +7,12 @@ export type ToolAdapterContext = {
|
|
|
7
7
|
project: ProjectContext;
|
|
8
8
|
config: VibeDoctorConfig;
|
|
9
9
|
scanMode: "default" | "changed" | "quick" | "full";
|
|
10
|
+
/** Results already produced by the scan engine, available to dependent adapters for reuse. */
|
|
11
|
+
sharedToolResults?: Record<string, SharedToolExecution>;
|
|
12
|
+
};
|
|
13
|
+
export type SharedToolExecution = {
|
|
14
|
+
findings: Finding[];
|
|
15
|
+
status?: ToolResult;
|
|
10
16
|
};
|
|
11
17
|
export type ToolAdapter = {
|
|
12
18
|
id: string;
|