@neuralaxis/vibedoctor 0.2.0 → 0.2.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/README.md +135 -23
- package/dist/adapters/biome.js +136 -21
- package/dist/adapters/flowDoctor.d.ts +7 -0
- package/dist/adapters/flowDoctor.js +195 -0
- package/dist/adapters/gitleaks.js +4 -2
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js +3 -1
- package/dist/adapters/osvScanner.js +140 -19
- package/dist/adapters/presidio.js +3 -1
- package/dist/adapters/ruff.js +7 -3
- package/dist/adapters/shared.d.ts +4 -0
- package/dist/cli/commands/init.js +112 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/scan.d.ts +6 -0
- package/dist/cli/commands/scan.js +16 -2
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/cli/index.js +4 -4
- package/dist/core/agentDiagnosis.d.ts +39 -0
- package/dist/core/agentDiagnosis.js +96 -0
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +47 -0
- package/dist/core/config.js +134 -3
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +29 -1
- package/dist/core/engine.js +510 -126
- 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 +70 -8
- package/dist/core/findingCorrelator.d.ts +19 -0
- package/dist/core/findingCorrelator.js +112 -0
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +172 -0
- package/dist/core/managedTools.d.ts +25 -0
- package/dist/core/managedTools.js +186 -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/repoGraph.d.ts +62 -0
- package/dist/core/repoGraph.js +408 -0
- package/dist/core/riskRanker.d.ts +6 -0
- package/dist/core/riskRanker.js +127 -0
- package/dist/core/scanContext.d.ts +26 -0
- package/dist/core/scanContext.js +44 -0
- package/dist/core/scanPlanner.d.ts +13 -0
- package/dist/core/scanPlanner.js +66 -38
- 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 +254 -0
- package/dist/core/toolRunner.d.ts +27 -2
- package/dist/core/toolRunner.js +79 -93
- package/dist/core/toolRuntime.d.ts +40 -0
- package/dist/core/toolRuntime.js +417 -0
- package/dist/core/toolVerification.d.ts +89 -0
- package/dist/core/toolVerification.js +425 -0
- package/dist/dpdp/collectors/optionalScanners.js +120 -30
- package/dist/dpdp/findings.d.ts +33 -3
- package/dist/dpdp/findings.js +191 -4
- package/dist/dpdp/scan.js +2 -2
- package/dist/dpdp/scoring.d.ts +14 -4
- package/dist/dpdp/scoring.js +34 -8
- package/dist/dpdp/types.d.ts +19 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/reporters/agent.d.ts +1 -1
- package/dist/reporters/agent.js +7 -0
- package/dist/reporters/html.js +57 -13
- package/dist/reporters/json.js +7 -1
- package/dist/reporters/markdown.js +46 -4
- package/dist/reporters/sarif.js +54 -5
- package/package.json +80 -80
|
@@ -125,26 +125,49 @@ function scopedScannerContext(ctx, candidates) {
|
|
|
125
125
|
}
|
|
126
126
|
function capabilityFromExecution(id, execution, mapped) {
|
|
127
127
|
const status = execution.status;
|
|
128
|
-
if (status?.status === "skipped") {
|
|
129
|
-
return {
|
|
130
|
-
id,
|
|
131
|
-
status: "skipped",
|
|
132
|
-
message: status.installHint ?? (status.stderr.trim() || `${id} was unavailable (never counted as pass)`)
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
128
|
if (status?.status === "error" || status?.status === "timeout") {
|
|
136
129
|
return {
|
|
137
130
|
id,
|
|
138
131
|
status: "error",
|
|
139
|
-
|
|
132
|
+
cause: status.status === "timeout" ? "timed_out" : "failed",
|
|
133
|
+
message: status.stderr.trim() || status.stdout.trim() || `${id} failed`,
|
|
134
|
+
remediation: `Run \`vibedoctor tool retry ${id}\` to see the full output.`
|
|
140
135
|
};
|
|
141
136
|
}
|
|
142
137
|
return {
|
|
143
138
|
id,
|
|
144
139
|
status: "available",
|
|
145
|
-
|
|
140
|
+
cause: "ran",
|
|
141
|
+
message: `Reused ${id} scan; ${mapped} scoped finding(s) contributed to DPDP evidence`,
|
|
142
|
+
resolvedVia: status?.resolvedPath,
|
|
143
|
+
signalsContributed: mapped
|
|
146
144
|
};
|
|
147
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Whether a shared scan result can stand in for a DPDP-scoped run.
|
|
148
|
+
*
|
|
149
|
+
* DPDP runs these scanners under a context that forces privacy checks on, so a
|
|
150
|
+
* shared result that was skipped for a configuration reason says nothing about
|
|
151
|
+
* whether the scanner works — inheriting that skip is what reported an installed
|
|
152
|
+
* Presidio as unavailable for DPDP.
|
|
153
|
+
*
|
|
154
|
+
* A skip caused by the tool being absent is different: it is authoritative, and
|
|
155
|
+
* retrying under a different config would only spend time failing again.
|
|
156
|
+
*/
|
|
157
|
+
function canReuseExecution(execution) {
|
|
158
|
+
if (!execution) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
// An entry with no process status came from an adapter that did its work
|
|
162
|
+
// in-process, so the results stand.
|
|
163
|
+
if (!execution.status) {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (execution.status.status !== "skipped") {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
return Boolean(execution.status.installHint);
|
|
170
|
+
}
|
|
148
171
|
/**
|
|
149
172
|
* Run opt-out optional scanners (Presidio, Semgrep) when enabled.
|
|
150
173
|
* Missing tools are skipped — never counted as a pass.
|
|
@@ -160,8 +183,20 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
160
183
|
signals,
|
|
161
184
|
findings,
|
|
162
185
|
capabilities: [
|
|
163
|
-
{
|
|
164
|
-
|
|
186
|
+
{
|
|
187
|
+
id: "presidio",
|
|
188
|
+
status: "skipped",
|
|
189
|
+
cause: "quick_mode",
|
|
190
|
+
message: "Skipped in quick mode",
|
|
191
|
+
remediation: "Run `vibedoctor dpdp scan --full` for evidence from the optional scanners."
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
id: "semgrep",
|
|
195
|
+
status: "skipped",
|
|
196
|
+
cause: "quick_mode",
|
|
197
|
+
message: "Skipped in quick mode",
|
|
198
|
+
remediation: "Run `vibedoctor dpdp scan --full` for evidence from the optional scanners."
|
|
199
|
+
}
|
|
165
200
|
]
|
|
166
201
|
};
|
|
167
202
|
}
|
|
@@ -171,15 +206,27 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
171
206
|
capabilities.push({
|
|
172
207
|
id: "presidio",
|
|
173
208
|
status: "skipped",
|
|
174
|
-
|
|
209
|
+
cause: "opted_out",
|
|
210
|
+
message: "Opted out (set checks.dpdp.use_presidio: true to re-enable for DPDP evidence)",
|
|
211
|
+
remediation: "Set checks.dpdp.use_presidio: true in vibedoctor.yml."
|
|
175
212
|
});
|
|
176
213
|
}
|
|
177
214
|
else if (candidates.length === 0) {
|
|
178
|
-
capabilities.push({
|
|
215
|
+
capabilities.push({
|
|
216
|
+
id: "presidio",
|
|
217
|
+
status: "skipped",
|
|
218
|
+
cause: "nothing_in_scope",
|
|
219
|
+
message: "No DPDP candidate files in scope",
|
|
220
|
+
remediation: "Widen checks.dpdp.include or paths.include in vibedoctor.yml."
|
|
221
|
+
});
|
|
179
222
|
}
|
|
180
223
|
else {
|
|
181
224
|
try {
|
|
182
|
-
const
|
|
225
|
+
const shared = ctx.sharedToolResults?.presidio;
|
|
226
|
+
const reused = canReuseExecution(shared) ? shared : undefined;
|
|
227
|
+
// Note why the shared result could not be reused, so a fresh attempt that
|
|
228
|
+
// also fails can report both facts instead of only the second one.
|
|
229
|
+
const sharedSkipReason = shared && !reused ? shared.status?.installHint ?? shared.status?.stderr?.trim() : undefined;
|
|
183
230
|
if (reused) {
|
|
184
231
|
const scopedFindings = reused.findings.filter((finding) => inCandidateScope(finding, candidateSet));
|
|
185
232
|
findings.push(...scopedFindings);
|
|
@@ -210,26 +257,33 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
210
257
|
capabilities.push({
|
|
211
258
|
id: "presidio",
|
|
212
259
|
status: "skipped",
|
|
213
|
-
|
|
260
|
+
cause: "not_applicable",
|
|
261
|
+
message: "Presidio not selected for this project",
|
|
262
|
+
remediation: "Set checks.privacy.enabled and checks.dpdp.use_presidio to true in vibedoctor.yml."
|
|
214
263
|
});
|
|
215
264
|
}
|
|
216
265
|
else {
|
|
217
266
|
const result = await presidio_1.presidioAdapter.runStandalone?.(presidioCtx);
|
|
218
267
|
const status = result?.status;
|
|
219
268
|
if (!result || status?.status === "skipped") {
|
|
269
|
+
const detail = status?.installHint ?? status?.stderr?.trim() ?? "Presidio could not be started in the project Python environment.";
|
|
220
270
|
capabilities.push({
|
|
221
271
|
id: "presidio",
|
|
222
272
|
status: "skipped",
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
273
|
+
cause: "not_installed",
|
|
274
|
+
message: sharedSkipReason
|
|
275
|
+
? `${detail} (the privacy scan also skipped Presidio: ${sharedSkipReason})`
|
|
276
|
+
: detail,
|
|
277
|
+
remediation: "Install it in the interpreter the scanner uses: python -m pip install presidio-analyzer, then run `vibedoctor setup --apply` to confirm it resolves."
|
|
226
278
|
});
|
|
227
279
|
}
|
|
228
280
|
else if (status?.status === "error" || status?.status === "timeout") {
|
|
229
281
|
capabilities.push({
|
|
230
282
|
id: "presidio",
|
|
231
283
|
status: "error",
|
|
232
|
-
|
|
284
|
+
cause: status.status === "timeout" ? "timed_out" : "failed",
|
|
285
|
+
message: status.stderr?.trim() || status.stdout?.trim() || "Presidio failed",
|
|
286
|
+
remediation: "Run `vibedoctor tool retry presidio` to see the full output."
|
|
233
287
|
});
|
|
234
288
|
}
|
|
235
289
|
else {
|
|
@@ -240,7 +294,10 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
240
294
|
capabilities.push({
|
|
241
295
|
id: "presidio",
|
|
242
296
|
status: "available",
|
|
243
|
-
|
|
297
|
+
cause: "ran",
|
|
298
|
+
message: `Presidio contributed ${result.findings.length} finding(s) to DPDP evidence`,
|
|
299
|
+
resolvedVia: status?.resolvedPath,
|
|
300
|
+
signalsContributed: result.findings.length
|
|
244
301
|
});
|
|
245
302
|
}
|
|
246
303
|
}
|
|
@@ -250,6 +307,7 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
250
307
|
capabilities.push({
|
|
251
308
|
id: "presidio",
|
|
252
309
|
status: "error",
|
|
310
|
+
cause: "failed",
|
|
253
311
|
message: error instanceof Error ? error.message : String(error)
|
|
254
312
|
});
|
|
255
313
|
}
|
|
@@ -259,15 +317,25 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
259
317
|
capabilities.push({
|
|
260
318
|
id: "semgrep",
|
|
261
319
|
status: "skipped",
|
|
262
|
-
|
|
320
|
+
cause: "opted_out",
|
|
321
|
+
message: "Opted out (set checks.dpdp.use_semgrep: true to re-enable for DPDP evidence)",
|
|
322
|
+
remediation: "Set checks.dpdp.use_semgrep: true in vibedoctor.yml."
|
|
263
323
|
});
|
|
264
324
|
}
|
|
265
325
|
else if (candidates.length === 0) {
|
|
266
|
-
capabilities.push({
|
|
326
|
+
capabilities.push({
|
|
327
|
+
id: "semgrep",
|
|
328
|
+
status: "skipped",
|
|
329
|
+
cause: "nothing_in_scope",
|
|
330
|
+
message: "No DPDP candidate files in scope",
|
|
331
|
+
remediation: "Widen checks.dpdp.include or paths.include in vibedoctor.yml."
|
|
332
|
+
});
|
|
267
333
|
}
|
|
268
334
|
else {
|
|
269
335
|
try {
|
|
270
|
-
const
|
|
336
|
+
const sharedSemgrep = ctx.sharedToolResults?.semgrep;
|
|
337
|
+
const reused = canReuseExecution(sharedSemgrep) ? sharedSemgrep : undefined;
|
|
338
|
+
const sharedSkipReason = sharedSemgrep && !reused ? sharedSemgrep.status?.installHint ?? sharedSemgrep.status?.stderr?.trim() : undefined;
|
|
271
339
|
if (reused) {
|
|
272
340
|
const scopedFindings = reused.findings.filter((finding) => inCandidateScope(finding, candidateSet));
|
|
273
341
|
findings.push(...scopedFindings);
|
|
@@ -286,33 +354,51 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
286
354
|
capabilities.push({
|
|
287
355
|
id: "semgrep",
|
|
288
356
|
status: "skipped",
|
|
289
|
-
|
|
357
|
+
cause: "not_applicable",
|
|
358
|
+
message: "Semgrep not applicable for this project",
|
|
359
|
+
remediation: "Semgrep needs source files in a language it supports; widen paths.include if that is wrong."
|
|
290
360
|
});
|
|
291
361
|
}
|
|
292
362
|
else if (!semgrep_1.semgrepAdapter.buildScanCommand || !semgrep_1.semgrepAdapter.parseResult) {
|
|
293
363
|
capabilities.push({
|
|
294
364
|
id: "semgrep",
|
|
295
365
|
status: "skipped",
|
|
296
|
-
|
|
366
|
+
cause: "not_applicable",
|
|
367
|
+
message: "Semgrep adapter cannot run in this build",
|
|
368
|
+
remediation: "This is a packaging problem, not a configuration one; please report it."
|
|
297
369
|
});
|
|
298
370
|
}
|
|
299
371
|
else {
|
|
300
372
|
const command = semgrep_1.semgrepAdapter.buildScanCommand(semgrepCtx);
|
|
373
|
+
// Honour the configured budget here too. The adapter's own default is
|
|
374
|
+
// not the user's setting, and a DPDP scan that ignores
|
|
375
|
+
// runtime.tool_timeouts can outlast the whole scan it belongs to.
|
|
376
|
+
const timeoutSeconds = ctx.config.runtime.toolTimeouts.semgrep ?? ctx.config.runtime.defaultTimeoutSeconds;
|
|
377
|
+
command.timeoutMs = Math.max(1, timeoutSeconds) * 1000;
|
|
301
378
|
const toolResult = await (0, toolRunner_1.runCommand)(command, semgrep_1.semgrepAdapter.installHint);
|
|
302
379
|
if (toolResult.status === "skipped") {
|
|
303
380
|
capabilities.push({
|
|
304
381
|
id: "semgrep",
|
|
305
382
|
status: "skipped",
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
"Semgrep not installed (never counted as pass)"
|
|
383
|
+
cause: "not_installed",
|
|
384
|
+
message: (() => {
|
|
385
|
+
const detail = toolResult.installHint ?? toolResult.stderr?.trim() ?? "Semgrep not installed (never counted as pass)";
|
|
386
|
+
return sharedSkipReason ? `${detail} (the main scan also skipped Semgrep: ${sharedSkipReason})` : detail;
|
|
387
|
+
})(),
|
|
388
|
+
remediation: "Install Semgrep (pipx install semgrep), then run `vibedoctor setup --apply` to confirm it resolves."
|
|
309
389
|
});
|
|
310
390
|
}
|
|
311
391
|
else if (toolResult.status === "error" || toolResult.status === "timeout") {
|
|
312
392
|
capabilities.push({
|
|
313
393
|
id: "semgrep",
|
|
314
394
|
status: "error",
|
|
315
|
-
|
|
395
|
+
cause: toolResult.status === "timeout" ? "timed_out" : "failed",
|
|
396
|
+
message: toolResult.status === "timeout"
|
|
397
|
+
? `Semgrep exceeded its ${Math.round(toolResult.durationMs / 1000)}s budget, so its rules did not run over DPDP candidates.`
|
|
398
|
+
: toolResult.stderr?.trim() || "Semgrep failed",
|
|
399
|
+
remediation: toolResult.status === "timeout"
|
|
400
|
+
? "Raise runtime.tool_timeouts.semgrep in vibedoctor.yml, or narrow checks.dpdp.include."
|
|
401
|
+
: "Run `vibedoctor tool retry semgrep` to see the full output."
|
|
316
402
|
});
|
|
317
403
|
}
|
|
318
404
|
else {
|
|
@@ -329,7 +415,10 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
329
415
|
capabilities.push({
|
|
330
416
|
id: "semgrep",
|
|
331
417
|
status: "available",
|
|
332
|
-
|
|
418
|
+
cause: "ran",
|
|
419
|
+
message: `Semgrep ran (${semgrepFindings.length} finding(s); ${mapped} privacy-relevant mapped to DPDP evidence)`,
|
|
420
|
+
resolvedVia: toolResult.resolvedPath,
|
|
421
|
+
signalsContributed: mapped
|
|
333
422
|
});
|
|
334
423
|
}
|
|
335
424
|
}
|
|
@@ -339,6 +428,7 @@ async function collectOptionalScannerSignals(ctx, candidates, options = {}) {
|
|
|
339
428
|
capabilities.push({
|
|
340
429
|
id: "semgrep",
|
|
341
430
|
status: "error",
|
|
431
|
+
cause: "failed",
|
|
342
432
|
message: error instanceof Error ? error.message : String(error)
|
|
343
433
|
});
|
|
344
434
|
}
|
package/dist/dpdp/findings.d.ts
CHANGED
|
@@ -1,11 +1,41 @@
|
|
|
1
|
-
import type { Finding } from "../core/finding";
|
|
2
|
-
import type { ControlResult, EvidenceItem } from "./types";
|
|
1
|
+
import type { DataFlowStep, EvidenceGrade, Finding, FindingRemediation } from "../core/finding";
|
|
2
|
+
import type { ControlResult, DpdpCapabilityStatus, EvidenceItem, VerificationClass } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Build a stable, masked snippet for fingerprinting.
|
|
5
5
|
* When present, fingerprintFinding omits startLine so line-only moves do not thrash baselines.
|
|
6
6
|
*/
|
|
7
7
|
export declare function stableDpdpFindingSnippet(result: ControlResult, primary: EvidenceItem | undefined): string;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Maps how a control was checked onto how strongly its evidence supports the
|
|
10
|
+
* claim.
|
|
11
|
+
*
|
|
12
|
+
* A DPDP finding could previously carry critical severity whether it came from
|
|
13
|
+
* following a data path or from a variable name that looked like an identifier.
|
|
14
|
+
* A readiness figure built on that mixture reads as stronger than the evidence
|
|
15
|
+
* behind it, which is worse than a lower, honest one.
|
|
16
|
+
*/
|
|
17
|
+
export declare function evidenceGradeForControl(verificationClass: VerificationClass, primary: EvidenceItem | undefined): EvidenceGrade;
|
|
18
|
+
/**
|
|
19
|
+
* Whether a control that observed nothing means the control is missing, or only
|
|
20
|
+
* that static analysis could not settle the question.
|
|
21
|
+
*
|
|
22
|
+
* These need different responses — one is a gap to fix, the other a gap in
|
|
23
|
+
* coverage — and presenting them identically is what let a readiness score imply
|
|
24
|
+
* more than the scan established.
|
|
25
|
+
*/
|
|
26
|
+
export declare function absenceClaimForControl(result: ControlResult, capabilities: DpdpCapabilityStatus[]): Finding["absenceClaim"];
|
|
27
|
+
/**
|
|
28
|
+
* Assembles the data path behind a control from its own evidence items, ordered
|
|
29
|
+
* source to sink. Each step carries its own grade, so a traced storage write and
|
|
30
|
+
* an inferred processor hop are not presented as equally established.
|
|
31
|
+
*/
|
|
32
|
+
export declare function buildDataFlow(result: ControlResult, evidenceById: Map<string, EvidenceItem>): DataFlowStep[] | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Works out what kind of change a remediation actually is, so the finding
|
|
35
|
+
* reaches whoever can act on it rather than defaulting to an engineer.
|
|
36
|
+
*/
|
|
37
|
+
export declare function remediationForControl(result: ControlResult): FindingRemediation | undefined;
|
|
38
|
+
export declare function controlResultsToFindings(results: ControlResult[], evidenceById: Map<string, EvidenceItem>, capabilities?: DpdpCapabilityStatus[]): Finding[];
|
|
9
39
|
/**
|
|
10
40
|
* Sync control `isNew` from baselined findings.
|
|
11
41
|
* Controls without a finding (not VIOLATED/PARTIAL/ERROR) keep isNew=false after baseline is applied
|
package/dist/dpdp/findings.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.stableDpdpFindingSnippet = stableDpdpFindingSnippet;
|
|
4
|
+
exports.evidenceGradeForControl = evidenceGradeForControl;
|
|
5
|
+
exports.absenceClaimForControl = absenceClaimForControl;
|
|
6
|
+
exports.buildDataFlow = buildDataFlow;
|
|
7
|
+
exports.remediationForControl = remediationForControl;
|
|
4
8
|
exports.controlResultsToFindings = controlResultsToFindings;
|
|
5
9
|
exports.syncControlIsNewFromFindings = syncControlIsNewFromFindings;
|
|
6
10
|
const STATUS_TO_INCLUDE = new Set(["VIOLATED", "PARTIAL", "ERROR"]);
|
|
@@ -20,7 +24,156 @@ function stableDpdpFindingSnippet(result, primary) {
|
|
|
20
24
|
.join("|")
|
|
21
25
|
.slice(0, 400);
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Maps how a control was checked onto how strongly its evidence supports the
|
|
29
|
+
* claim.
|
|
30
|
+
*
|
|
31
|
+
* A DPDP finding could previously carry critical severity whether it came from
|
|
32
|
+
* following a data path or from a variable name that looked like an identifier.
|
|
33
|
+
* A readiness figure built on that mixture reads as stronger than the evidence
|
|
34
|
+
* behind it, which is worse than a lower, honest one.
|
|
35
|
+
*/
|
|
36
|
+
function evidenceGradeForControl(verificationClass, primary) {
|
|
37
|
+
if (verificationClass === "DETERMINISTIC") {
|
|
38
|
+
return primary?.certainty === "confirmed" ? "verified" : "observed";
|
|
39
|
+
}
|
|
40
|
+
if (verificationClass === "TECHNICAL_SIGNAL") {
|
|
41
|
+
// A signal anchored to a real file and line was observed; one inferred from
|
|
42
|
+
// shape alone is a heuristic, however plausible.
|
|
43
|
+
if (primary?.certainty === "confirmed" && primary.file) {
|
|
44
|
+
return "observed";
|
|
45
|
+
}
|
|
46
|
+
return "heuristic";
|
|
47
|
+
}
|
|
48
|
+
if (verificationClass === "DECLARED_EVIDENCE") {
|
|
49
|
+
return "unproven";
|
|
50
|
+
}
|
|
51
|
+
return "unproven";
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether a control that observed nothing means the control is missing, or only
|
|
55
|
+
* that static analysis could not settle the question.
|
|
56
|
+
*
|
|
57
|
+
* These need different responses — one is a gap to fix, the other a gap in
|
|
58
|
+
* coverage — and presenting them identically is what let a readiness score imply
|
|
59
|
+
* more than the scan established.
|
|
60
|
+
*/
|
|
61
|
+
function absenceClaimForControl(result, capabilities) {
|
|
62
|
+
if (!result.applicable || result.status === "NOT_APPLICABLE") {
|
|
63
|
+
return "not_applicable";
|
|
64
|
+
}
|
|
65
|
+
// A scanner that did not run cannot have failed to find something.
|
|
66
|
+
const unavailable = capabilities.filter((capability) => capability.status !== "available");
|
|
67
|
+
if (unavailable.length > 0 && result.verificationClass === "TECHNICAL_SIGNAL") {
|
|
68
|
+
return "not_statically_provable";
|
|
69
|
+
}
|
|
70
|
+
if (result.verificationClass === "HUMAN_REVIEW" || result.verificationClass === "DECLARED_EVIDENCE") {
|
|
71
|
+
return "not_statically_provable";
|
|
72
|
+
}
|
|
73
|
+
return result.status === "VIOLATED" ? "control_absent" : "not_statically_provable";
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Classifies an evidence item's place in a data path. The mapping is by evidence
|
|
77
|
+
* kind rather than by guesswork, so a step only appears when something concrete
|
|
78
|
+
* was recorded at that stage.
|
|
79
|
+
*/
|
|
80
|
+
function flowKindFor(item) {
|
|
81
|
+
const kind = item.kind;
|
|
82
|
+
if (/collect|input|form|field|schema|request|param/i.test(kind)) {
|
|
83
|
+
return "source";
|
|
84
|
+
}
|
|
85
|
+
if (/storage|store|cookie|database|table|column|persist|cache/i.test(kind)) {
|
|
86
|
+
return "store";
|
|
87
|
+
}
|
|
88
|
+
if (/transfer|processor|third_party|vendor|llm|model|ai|api_call/i.test(kind)) {
|
|
89
|
+
return "processor";
|
|
90
|
+
}
|
|
91
|
+
if (/log|export|sink|telemetry|analytics|email|report/i.test(kind)) {
|
|
92
|
+
return "sink";
|
|
93
|
+
}
|
|
94
|
+
if (/transform|mask|redact|hash|encrypt/i.test(kind)) {
|
|
95
|
+
return "transform";
|
|
96
|
+
}
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
const FLOW_ORDER = {
|
|
100
|
+
source: 0,
|
|
101
|
+
transform: 1,
|
|
102
|
+
store: 2,
|
|
103
|
+
processor: 3,
|
|
104
|
+
sink: 4
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Assembles the data path behind a control from its own evidence items, ordered
|
|
108
|
+
* source to sink. Each step carries its own grade, so a traced storage write and
|
|
109
|
+
* an inferred processor hop are not presented as equally established.
|
|
110
|
+
*/
|
|
111
|
+
function buildDataFlow(result, evidenceById) {
|
|
112
|
+
const steps = [];
|
|
113
|
+
for (const id of result.evidenceIds) {
|
|
114
|
+
const item = evidenceById.get(id);
|
|
115
|
+
if (!item) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const kind = flowKindFor(item);
|
|
119
|
+
if (!kind) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
steps.push({
|
|
123
|
+
kind,
|
|
124
|
+
label: item.field ?? item.symbol ?? item.summary.slice(0, 80),
|
|
125
|
+
file: item.file,
|
|
126
|
+
startLine: item.line,
|
|
127
|
+
evidenceGrade: item.certainty === "confirmed" && item.file ? "observed" : item.certainty === "declared" ? "unproven" : "heuristic",
|
|
128
|
+
detail: item.summary
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
if (steps.length < 2) {
|
|
132
|
+
// A single step is not a path; the finding's own location already says where
|
|
133
|
+
// it is, and calling one point a "flow" would overstate the evidence.
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
return steps.sort((left, right) => FLOW_ORDER[left.kind] - FLOW_ORDER[right.kind]);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Works out what kind of change a remediation actually is, so the finding
|
|
140
|
+
* reaches whoever can act on it rather than defaulting to an engineer.
|
|
141
|
+
*/
|
|
142
|
+
function remediationForControl(result) {
|
|
143
|
+
if (!result.remediation) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
// Domains whose controls are satisfied by a documented decision or process
|
|
147
|
+
// rather than by code. Routing these to an engineer produces a task nobody can
|
|
148
|
+
// close.
|
|
149
|
+
const policyDomains = new Set([
|
|
150
|
+
"grievance_handling",
|
|
151
|
+
"nomination",
|
|
152
|
+
"significant_data_fiduciary",
|
|
153
|
+
"exemptions_and_applicability",
|
|
154
|
+
"breach_preparedness",
|
|
155
|
+
"notice"
|
|
156
|
+
]);
|
|
157
|
+
const kind = result.verificationClass === "HUMAN_REVIEW" || result.verificationClass === "DECLARED_EVIDENCE"
|
|
158
|
+
? "human_review"
|
|
159
|
+
: policyDomains.has(result.domain)
|
|
160
|
+
? "policy"
|
|
161
|
+
: /config|setting|environment|flag|header|policy file/i.test(result.remediation)
|
|
162
|
+
? "config"
|
|
163
|
+
: "code";
|
|
164
|
+
return {
|
|
165
|
+
kind,
|
|
166
|
+
component: result.controlId,
|
|
167
|
+
steps: [result.remediation, ...(result.humanReviewQuestion ? [`Confirm with an owner: ${result.humanReviewQuestion}`] : [])],
|
|
168
|
+
requiredEvidence: result.verificationClass === "DETERMINISTIC"
|
|
169
|
+
? "A rerun of `vibedoctor dpdp scan` showing this control verified."
|
|
170
|
+
: result.verificationClass === "TECHNICAL_SIGNAL"
|
|
171
|
+
? "Code changes plus a rerun, or a declared-evidence entry recording the decision."
|
|
172
|
+
: `A signed-off entry in the declared-evidence file (${result.controlId}).`,
|
|
173
|
+
requiresHumanDecision: kind === "human_review" || kind === "policy"
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function controlResultsToFindings(results, evidenceById, capabilities = []) {
|
|
24
177
|
const findings = [];
|
|
25
178
|
for (const result of results) {
|
|
26
179
|
if (!STATUS_TO_INCLUDE.has(result.status)) {
|
|
@@ -35,6 +188,22 @@ function controlResultsToFindings(results, evidenceById) {
|
|
|
35
188
|
? "high"
|
|
36
189
|
: result.severity;
|
|
37
190
|
const snippet = primary?.snippet ?? stableDpdpFindingSnippet(result, primary);
|
|
191
|
+
const evidenceGrade = evidenceGradeForControl(result.verificationClass, primary);
|
|
192
|
+
const absenceClaim = absenceClaimForControl(result, capabilities);
|
|
193
|
+
const dataFlow = buildDataFlow(result, evidenceById);
|
|
194
|
+
// State the strength of the claim in the message itself. A reader scanning a
|
|
195
|
+
// list should not have to open the JSON to learn that a "critical" item rests
|
|
196
|
+
// on a naming heuristic.
|
|
197
|
+
const gradeNote = evidenceGrade === "verified"
|
|
198
|
+
? "Verified from code."
|
|
199
|
+
: evidenceGrade === "observed"
|
|
200
|
+
? "Observed at a specific location; its meaning is inferred."
|
|
201
|
+
: evidenceGrade === "heuristic"
|
|
202
|
+
? "Heuristic signal: inferred from names or shape, not from a traced code path."
|
|
203
|
+
: "Not established from code; needs human confirmation.";
|
|
204
|
+
const absenceNote = absenceClaim === "not_statically_provable"
|
|
205
|
+
? " This scan could not prove the control is absent, only that it was not observed."
|
|
206
|
+
: "";
|
|
38
207
|
findings.push({
|
|
39
208
|
id: `dpdp:${result.controlId}:${result.status}:${primary?.file ?? "repo"}:${primary?.line ?? 0}`,
|
|
40
209
|
source: "dpdp",
|
|
@@ -42,14 +211,25 @@ function controlResultsToFindings(results, evidenceById) {
|
|
|
42
211
|
severity,
|
|
43
212
|
confidence: result.confidence,
|
|
44
213
|
title: `DPDP ${result.status}: ${result.title}`,
|
|
45
|
-
message: result.explanation
|
|
214
|
+
message: `${result.explanation} ${gradeNote}${absenceNote}`,
|
|
46
215
|
file: primary?.file,
|
|
47
216
|
startLine: primary?.line,
|
|
48
217
|
isNew: result.isNew,
|
|
49
218
|
isAutofixable: false,
|
|
50
219
|
safeToAutofix: false,
|
|
51
220
|
agentInstruction: result.remediation,
|
|
52
|
-
|
|
221
|
+
evidenceGrade,
|
|
222
|
+
absenceClaim,
|
|
223
|
+
dataFlow,
|
|
224
|
+
remediation: remediationForControl(result),
|
|
225
|
+
tags: [
|
|
226
|
+
"dpdp",
|
|
227
|
+
result.controlId,
|
|
228
|
+
result.domain,
|
|
229
|
+
result.status.toLowerCase(),
|
|
230
|
+
result.verificationClass.toLowerCase(),
|
|
231
|
+
`evidence:${evidenceGrade}`
|
|
232
|
+
],
|
|
53
233
|
evidence: {
|
|
54
234
|
detector: "dpdp",
|
|
55
235
|
// Always set snippet so fingerprints prefer content hash over line number
|
|
@@ -57,7 +237,14 @@ function controlResultsToFindings(results, evidenceById) {
|
|
|
57
237
|
fieldPath: primary?.field,
|
|
58
238
|
matchedPattern: result.controlId,
|
|
59
239
|
detectionPath: result.verificationClass,
|
|
60
|
-
reasons: [
|
|
240
|
+
reasons: [
|
|
241
|
+
result.explanation,
|
|
242
|
+
gradeNote,
|
|
243
|
+
...(absenceClaim === "not_statically_provable"
|
|
244
|
+
? ["Absence of the control was not proven; it was not observed."]
|
|
245
|
+
: []),
|
|
246
|
+
...(result.limitations ?? [])
|
|
247
|
+
],
|
|
61
248
|
recommendedAction: result.remediation,
|
|
62
249
|
rationale: result.humanReviewQuestion,
|
|
63
250
|
entityType: primary?.dataCategory,
|
package/dist/dpdp/scan.js
CHANGED
|
@@ -99,14 +99,14 @@ async function runDpdpScan(root, mode = "full", options = {}) {
|
|
|
99
99
|
controlResults = (0, evaluators_1.attachDeclaredEvidenceIds)(controlResults, declared);
|
|
100
100
|
const generatedAt = new Date().toISOString();
|
|
101
101
|
const evidenceById = new Map(evidence.map((item) => [item.id, item]));
|
|
102
|
-
let findings = (0, findings_1.controlResultsToFindings)(controlResults, evidenceById);
|
|
102
|
+
let findings = (0, findings_1.controlResultsToFindings)(controlResults, evidenceById, capabilities);
|
|
103
103
|
// Apply shared baseline fingerprints, then sync control isNew from findings.
|
|
104
104
|
if (config.baseline.enabled) {
|
|
105
105
|
const baseline = await (0, baseline_1.loadBaseline)(root, config.baseline.file);
|
|
106
106
|
findings = (0, finding_1.applyBaseline)(findings, new Set(baseline.findings.map((entry) => entry.fingerprint)));
|
|
107
107
|
}
|
|
108
108
|
controlResults = (0, findings_1.syncControlIsNewFromFindings)(controlResults, findings, config.baseline.enabled);
|
|
109
|
-
const scores = (0, scoring_1.buildDpdpScores)(controlResults);
|
|
109
|
+
const scores = (0, scoring_1.buildDpdpScores)(controlResults, capabilities);
|
|
110
110
|
const dataMap = (0, dataMap_1.buildPersonalDataMap)(signals, evidence, controlResults, generatedAt);
|
|
111
111
|
const reviewQueue = (0, reviewQueue_1.buildReviewQueue)(controlResults);
|
|
112
112
|
const fixNext = controlResults
|
package/dist/dpdp/scoring.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Severity } from "../core/finding";
|
|
2
|
-
import type { ControlResult, ControlStatusCounts, DpdpScores } from "./types";
|
|
2
|
+
import type { ControlResult, ControlStatusCounts, DpdpCapabilityStatus, DpdpScores } from "./types";
|
|
3
3
|
/**
|
|
4
4
|
* Controls that expect an implementation signal when personal data is processed.
|
|
5
5
|
* NOT_OBSERVED on these is weak posture (missing expected control), not a clean bill of health.
|
|
@@ -12,8 +12,16 @@ export declare const GAP_CONTROL_EVALUATORS: Set<string>;
|
|
|
12
12
|
export declare function isPositiveControl(control: ControlResult): boolean;
|
|
13
13
|
export declare function isGapControl(control: ControlResult): boolean;
|
|
14
14
|
export declare function countStatuses(controls: ControlResult[]): ControlStatusCounts;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the scanners a control depends on actually ran.
|
|
17
|
+
*
|
|
18
|
+
* "Nothing bad was found" and "nothing looked" produce the same control status,
|
|
19
|
+
* and a gap detector's silence was credited at 0.85 either way. That let a
|
|
20
|
+
* posture score climb because a scanner was missing, which is exactly backwards.
|
|
21
|
+
*/
|
|
22
|
+
export declare function hasSupportingCoverage(capabilities: DpdpCapabilityStatus[]): boolean;
|
|
15
23
|
/** Points contributed by one control status toward technical posture (0–1). */
|
|
16
|
-
export declare function posturePointsForControl(control: ControlResult): number;
|
|
24
|
+
export declare function posturePointsForControl(control: ControlResult, coverageComplete?: boolean): number;
|
|
17
25
|
/**
|
|
18
26
|
* Technical posture score from applicable technically observable controls only.
|
|
19
27
|
* NOT a legal compliance percentage.
|
|
@@ -21,11 +29,13 @@ export declare function posturePointsForControl(control: ControlResult): number;
|
|
|
21
29
|
* Scoring table:
|
|
22
30
|
* - VERIFIED 1.0 · PARTIAL 0.5 · VIOLATED 0.0 · ERROR 0.15 · NEEDS_CONTEXT 0.4
|
|
23
31
|
* - NOT_OBSERVED: 0.25 (positive control), 0.85 (gap detector), 0.7 (other)
|
|
32
|
+
* - When supporting scanners did not run, unobserved controls score 0.4 instead,
|
|
33
|
+
* because their silence carries no information.
|
|
24
34
|
*/
|
|
25
|
-
export declare function computeTechnicalPostureScore(controls: ControlResult[]): number;
|
|
35
|
+
export declare function computeTechnicalPostureScore(controls: ControlResult[], capabilities?: DpdpCapabilityStatus[]): number;
|
|
26
36
|
/**
|
|
27
37
|
* Evidence completeness: share of applicable controls that have evidence or are verified/violated/partial.
|
|
28
38
|
*/
|
|
29
39
|
export declare function computeEvidenceCompleteness(controls: ControlResult[]): number;
|
|
30
40
|
export declare function openRiskBySeverity(controls: ControlResult[]): Record<Severity, number>;
|
|
31
|
-
export declare function buildDpdpScores(controls: ControlResult[]): DpdpScores;
|
|
41
|
+
export declare function buildDpdpScores(controls: ControlResult[], capabilities?: DpdpCapabilityStatus[]): DpdpScores;
|