@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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { FindingCategory } from "./finding";
|
|
2
|
+
import type { ToolCoverage } from "./toolRunner";
|
|
3
|
+
/**
|
|
4
|
+
* The capability matrix: one row per tool VibeDoctor considered, recording what
|
|
5
|
+
* actually happened to it.
|
|
6
|
+
*
|
|
7
|
+
* The previous model had two lists — `toolStatuses` and `skippedTools` — which
|
|
8
|
+
* could not express the distinctions that matter. A tool that was installed but
|
|
9
|
+
* never ran, a tool that ran but only over part of the repo, and a tool that was
|
|
10
|
+
* never applicable all collapsed into "skipped". Reports built on that could say
|
|
11
|
+
* a tool was installed while its findings were absent, with no way to tell which
|
|
12
|
+
* link in the chain broke. Each facet below is recorded independently, and
|
|
13
|
+
* `state` is derived from them rather than asserted.
|
|
14
|
+
*/
|
|
15
|
+
export type CapabilityState =
|
|
16
|
+
/** Ran to completion over the full requested scope. */
|
|
17
|
+
"completed"
|
|
18
|
+
/** Ran, but covered less than the requested scope (scoped fallback after a timeout). */
|
|
19
|
+
| "partial"
|
|
20
|
+
/** Exceeded its time budget and was killed. */
|
|
21
|
+
| "timed_out"
|
|
22
|
+
/** Ran and failed, or produced output that could not be parsed. */
|
|
23
|
+
| "failed"
|
|
24
|
+
/** Not present on PATH. */
|
|
25
|
+
| "not_installed"
|
|
26
|
+
/** Present, but the runtime cannot run it. */
|
|
27
|
+
| "runtime_incompatible"
|
|
28
|
+
/** Deliberately deferred by configuration. */
|
|
29
|
+
| "deferred"
|
|
30
|
+
/** Turned off by configuration. */
|
|
31
|
+
| "disabled"
|
|
32
|
+
/** Nothing in this repository for it to analyse. */
|
|
33
|
+
| "not_applicable"
|
|
34
|
+
/** Excluded by the current scan mode (for example a full-scan-only tool in quick mode). */
|
|
35
|
+
| "not_selected";
|
|
36
|
+
/** Whether findings from this tool can be trusted as covering the repository. */
|
|
37
|
+
export type CapabilityTrust = "authoritative" | "partial" | "absent";
|
|
38
|
+
export type ToolCapability = {
|
|
39
|
+
id: string;
|
|
40
|
+
category: FindingCategory;
|
|
41
|
+
state: CapabilityState;
|
|
42
|
+
/** Selected for this scan mode. */
|
|
43
|
+
planned: boolean;
|
|
44
|
+
/** There is something in this repository for the tool to analyse. */
|
|
45
|
+
applicable: boolean;
|
|
46
|
+
/** Found on PATH (or importable, for module-driven tools). */
|
|
47
|
+
discovered: boolean;
|
|
48
|
+
/** Started at least once. */
|
|
49
|
+
executed: boolean;
|
|
50
|
+
resolvedPath?: string;
|
|
51
|
+
version?: string;
|
|
52
|
+
/** Exact command line that ran, so any row can be reproduced by hand. */
|
|
53
|
+
command?: string;
|
|
54
|
+
durationMs?: number;
|
|
55
|
+
timeoutSeconds?: number;
|
|
56
|
+
coverage?: ToolCoverage;
|
|
57
|
+
/** Findings the tool reported, before relevance filtering and suppressions. */
|
|
58
|
+
findingsReported: number;
|
|
59
|
+
/** Findings that reached the report. Differs from reported whenever filters ran. */
|
|
60
|
+
findingsSurfaced: number;
|
|
61
|
+
/** Why this row ended in this state. Always populated. */
|
|
62
|
+
reason: string;
|
|
63
|
+
/** What to do about it, when there is something to do. */
|
|
64
|
+
remediation?: string;
|
|
65
|
+
trust: CapabilityTrust;
|
|
66
|
+
};
|
|
67
|
+
export declare function trustForState(state: CapabilityState): CapabilityTrust;
|
|
68
|
+
/**
|
|
69
|
+
* States that mean "this check did not happen and you should know". Deliberate
|
|
70
|
+
* exclusions are not gaps; a tool that timed out or is missing is.
|
|
71
|
+
*/
|
|
72
|
+
export declare function isCoverageGap(capability: ToolCapability): boolean;
|
|
73
|
+
export declare function didRun(capability: ToolCapability): boolean;
|
|
74
|
+
export type CapabilityMatrix = {
|
|
75
|
+
tools: ToolCapability[];
|
|
76
|
+
counts: Record<CapabilityState, number>;
|
|
77
|
+
/** Tools whose absence or partial coverage limits what the report can claim. */
|
|
78
|
+
gaps: string[];
|
|
79
|
+
/** Gaps for tools the config marks required. */
|
|
80
|
+
requiredGaps: string[];
|
|
81
|
+
/** True when every planned tool completed over full scope. */
|
|
82
|
+
fullCoverage: boolean;
|
|
83
|
+
};
|
|
84
|
+
export declare function buildCapabilityMatrix(tools: ToolCapability[], requiredTools: string[]): CapabilityMatrix;
|
|
85
|
+
export declare function capabilityStateLabel(state: CapabilityState): string;
|
|
86
|
+
/**
|
|
87
|
+
* Renders the matrix as aligned text. Every row states what happened, why, and
|
|
88
|
+
* what to do — including the findings-reported vs findings-surfaced split, so a
|
|
89
|
+
* tool that ran but had everything filtered out cannot look like a tool that
|
|
90
|
+
* found nothing.
|
|
91
|
+
*/
|
|
92
|
+
export declare function renderCapabilityMatrixLines(matrix: CapabilityMatrix): string[];
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trustForState = trustForState;
|
|
4
|
+
exports.isCoverageGap = isCoverageGap;
|
|
5
|
+
exports.didRun = didRun;
|
|
6
|
+
exports.buildCapabilityMatrix = buildCapabilityMatrix;
|
|
7
|
+
exports.capabilityStateLabel = capabilityStateLabel;
|
|
8
|
+
exports.renderCapabilityMatrixLines = renderCapabilityMatrixLines;
|
|
9
|
+
const COMPLETE_STATES = new Set(["completed"]);
|
|
10
|
+
const RAN_STATES = new Set(["completed", "partial", "timed_out", "failed"]);
|
|
11
|
+
function trustForState(state) {
|
|
12
|
+
if (COMPLETE_STATES.has(state)) {
|
|
13
|
+
return "authoritative";
|
|
14
|
+
}
|
|
15
|
+
if (state === "partial") {
|
|
16
|
+
return "partial";
|
|
17
|
+
}
|
|
18
|
+
// "not_applicable", "disabled" and "not_selected" are deliberate: there is no
|
|
19
|
+
// missing coverage to disclose, so they do not weaken the report.
|
|
20
|
+
if (state === "not_applicable" || state === "disabled" || state === "not_selected") {
|
|
21
|
+
return "authoritative";
|
|
22
|
+
}
|
|
23
|
+
return "absent";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* States that mean "this check did not happen and you should know". Deliberate
|
|
27
|
+
* exclusions are not gaps; a tool that timed out or is missing is.
|
|
28
|
+
*/
|
|
29
|
+
function isCoverageGap(capability) {
|
|
30
|
+
return capability.trust === "absent" || capability.trust === "partial";
|
|
31
|
+
}
|
|
32
|
+
function didRun(capability) {
|
|
33
|
+
return RAN_STATES.has(capability.state);
|
|
34
|
+
}
|
|
35
|
+
const EMPTY_COUNTS = {
|
|
36
|
+
completed: 0,
|
|
37
|
+
partial: 0,
|
|
38
|
+
timed_out: 0,
|
|
39
|
+
failed: 0,
|
|
40
|
+
not_installed: 0,
|
|
41
|
+
runtime_incompatible: 0,
|
|
42
|
+
deferred: 0,
|
|
43
|
+
disabled: 0,
|
|
44
|
+
not_applicable: 0,
|
|
45
|
+
not_selected: 0
|
|
46
|
+
};
|
|
47
|
+
function buildCapabilityMatrix(tools, requiredTools) {
|
|
48
|
+
const sorted = [...tools].sort((left, right) => left.id.localeCompare(right.id));
|
|
49
|
+
const counts = { ...EMPTY_COUNTS };
|
|
50
|
+
for (const tool of sorted) {
|
|
51
|
+
counts[tool.state] += 1;
|
|
52
|
+
}
|
|
53
|
+
const gaps = sorted.filter(isCoverageGap).map((tool) => tool.id);
|
|
54
|
+
const required = new Set(requiredTools);
|
|
55
|
+
return {
|
|
56
|
+
tools: sorted,
|
|
57
|
+
counts,
|
|
58
|
+
gaps,
|
|
59
|
+
requiredGaps: gaps.filter((id) => required.has(id)),
|
|
60
|
+
fullCoverage: sorted.every((tool) => !isCoverageGap(tool))
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const STATE_LABELS = {
|
|
64
|
+
completed: "completed",
|
|
65
|
+
partial: "partial",
|
|
66
|
+
timed_out: "timed out",
|
|
67
|
+
failed: "failed",
|
|
68
|
+
not_installed: "not installed",
|
|
69
|
+
runtime_incompatible: "runtime mismatch",
|
|
70
|
+
deferred: "deferred",
|
|
71
|
+
disabled: "disabled",
|
|
72
|
+
not_applicable: "not applicable",
|
|
73
|
+
not_selected: "not selected"
|
|
74
|
+
};
|
|
75
|
+
function capabilityStateLabel(state) {
|
|
76
|
+
return STATE_LABELS[state];
|
|
77
|
+
}
|
|
78
|
+
function formatDuration(durationMs) {
|
|
79
|
+
if (durationMs === undefined) {
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
return durationMs >= 1000 ? `${(durationMs / 1000).toFixed(1)}s` : `${durationMs}ms`;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Renders the matrix as aligned text. Every row states what happened, why, and
|
|
86
|
+
* what to do — including the findings-reported vs findings-surfaced split, so a
|
|
87
|
+
* tool that ran but had everything filtered out cannot look like a tool that
|
|
88
|
+
* found nothing.
|
|
89
|
+
*/
|
|
90
|
+
function renderCapabilityMatrixLines(matrix) {
|
|
91
|
+
if (matrix.tools.length === 0) {
|
|
92
|
+
return [];
|
|
93
|
+
}
|
|
94
|
+
const rows = matrix.tools.map((tool) => ({
|
|
95
|
+
id: tool.id,
|
|
96
|
+
state: capabilityStateLabel(tool.state),
|
|
97
|
+
findings: tool.findingsReported === tool.findingsSurfaced
|
|
98
|
+
? String(tool.findingsSurfaced)
|
|
99
|
+
: `${tool.findingsSurfaced} of ${tool.findingsReported}`,
|
|
100
|
+
time: formatDuration(tool.durationMs),
|
|
101
|
+
detail: tool.reason
|
|
102
|
+
}));
|
|
103
|
+
const idWidth = Math.max(4, ...rows.map((row) => row.id.length));
|
|
104
|
+
const stateWidth = Math.max(6, ...rows.map((row) => row.state.length));
|
|
105
|
+
const findingsWidth = Math.max(8, ...rows.map((row) => row.findings.length));
|
|
106
|
+
const timeWidth = Math.max(4, ...rows.map((row) => row.time.length));
|
|
107
|
+
const lines = [
|
|
108
|
+
`${"TOOL".padEnd(idWidth)} ${"STATE".padEnd(stateWidth)} ${"FINDINGS".padEnd(findingsWidth)} ${"TIME".padEnd(timeWidth)} DETAIL`
|
|
109
|
+
];
|
|
110
|
+
for (const row of rows) {
|
|
111
|
+
lines.push(`${row.id.padEnd(idWidth)} ${row.state.padEnd(stateWidth)} ${row.findings.padEnd(findingsWidth)} ${row.time.padEnd(timeWidth)} ${row.detail}`);
|
|
112
|
+
}
|
|
113
|
+
const remediations = matrix.tools.filter((tool) => tool.remediation && isCoverageGap(tool));
|
|
114
|
+
if (remediations.length > 0) {
|
|
115
|
+
lines.push("");
|
|
116
|
+
lines.push("TO RESTORE COVERAGE");
|
|
117
|
+
for (const tool of remediations) {
|
|
118
|
+
lines.push(`- ${tool.id}: ${tool.remediation}`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return lines;
|
|
122
|
+
}
|
package/dist/core/config.d.ts
CHANGED
|
@@ -22,6 +22,50 @@ export type VibeDoctorConfig = {
|
|
|
22
22
|
toolTimeouts: Record<string, number>;
|
|
23
23
|
requiredTools: string[];
|
|
24
24
|
failOnIncompleteScan: boolean;
|
|
25
|
+
/** Wall-clock ceiling for the whole scan. 0 disables the ceiling. */
|
|
26
|
+
totalBudgetSeconds: number;
|
|
27
|
+
/**
|
|
28
|
+
* What to do when a tool exhausts its budget. `scoped_retry` reruns it over
|
|
29
|
+
* changed files only and reports the partial coverage, which beats losing
|
|
30
|
+
* the check entirely on a repository the tool cannot finish.
|
|
31
|
+
*/
|
|
32
|
+
onTimeout: "scoped_retry" | "skip" | "fail";
|
|
33
|
+
/** Budget for the narrowed retry. */
|
|
34
|
+
scopedRetryTimeoutSeconds: number;
|
|
35
|
+
/** Tools deliberately not run, with the report saying so rather than implying they passed. */
|
|
36
|
+
deferredTools: string[];
|
|
37
|
+
/** Verify each tool resolves and runs before trusting its absence of findings. */
|
|
38
|
+
verifyToolsBeforeScan: boolean;
|
|
39
|
+
/** Resolve/provision engines into a VibeDoctor-owned cache instead of mutating the repo. */
|
|
40
|
+
managedTools: {
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
/** Override for ~/.cache/vibedoctor. */
|
|
43
|
+
cacheDir?: string;
|
|
44
|
+
allowNetwork: boolean;
|
|
45
|
+
preferProjectLocal: boolean;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
relevance: {
|
|
49
|
+
enabled: boolean;
|
|
50
|
+
minConfidence: "low" | "medium" | "high";
|
|
51
|
+
maxFindingsPerTool: number;
|
|
52
|
+
maxFindingsTotal: number;
|
|
53
|
+
syntheticFilePolicy: "keep" | "downgrade" | "drop";
|
|
54
|
+
validateSecrets: boolean;
|
|
55
|
+
perTool: Record<string, {
|
|
56
|
+
minConfidence?: "low" | "medium" | "high";
|
|
57
|
+
minEvidenceGrade?: "unproven" | "heuristic" | "observed" | "verified";
|
|
58
|
+
maxFindings?: number;
|
|
59
|
+
requireCorroboration?: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
/** Extra globs that classify files as tests, fixtures, generated, and so on. */
|
|
62
|
+
fileRoles: Partial<Record<"source" | "test" | "fixture" | "generated" | "vendor" | "config" | "docs", string[]>>;
|
|
63
|
+
};
|
|
64
|
+
suppressions: {
|
|
65
|
+
enabled: boolean;
|
|
66
|
+
file: string;
|
|
67
|
+
/** Reject acknowledgements with no expiry date. */
|
|
68
|
+
requireExpiry: boolean;
|
|
25
69
|
};
|
|
26
70
|
checks: {
|
|
27
71
|
security: {
|
|
@@ -84,6 +128,9 @@ export type VibeDoctorConfig = {
|
|
|
84
128
|
enabled: boolean;
|
|
85
129
|
};
|
|
86
130
|
};
|
|
131
|
+
flowAnalysis: {
|
|
132
|
+
enabled: boolean;
|
|
133
|
+
};
|
|
87
134
|
dpdp: {
|
|
88
135
|
enabled: boolean;
|
|
89
136
|
include: string[];
|
package/dist/core/config.js
CHANGED
|
@@ -10,6 +10,8 @@ const node_fs_1 = require("node:fs");
|
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
11
|
const yaml_1 = __importDefault(require("yaml"));
|
|
12
12
|
const paths_1 = require("./paths");
|
|
13
|
+
const relevance_1 = require("./relevance");
|
|
14
|
+
const suppressions_1 = require("./suppressions");
|
|
13
15
|
exports.defaultConfig = {
|
|
14
16
|
version: 1,
|
|
15
17
|
profile: "startup",
|
|
@@ -55,7 +57,32 @@ exports.defaultConfig = {
|
|
|
55
57
|
semgrep: 300
|
|
56
58
|
},
|
|
57
59
|
requiredTools: [],
|
|
58
|
-
failOnIncompleteScan: false
|
|
60
|
+
failOnIncompleteScan: false,
|
|
61
|
+
totalBudgetSeconds: 0,
|
|
62
|
+
onTimeout: "scoped_retry",
|
|
63
|
+
scopedRetryTimeoutSeconds: 60,
|
|
64
|
+
deferredTools: [],
|
|
65
|
+
verifyToolsBeforeScan: true,
|
|
66
|
+
managedTools: {
|
|
67
|
+
enabled: true,
|
|
68
|
+
allowNetwork: true,
|
|
69
|
+
preferProjectLocal: true
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
relevance: {
|
|
73
|
+
enabled: true,
|
|
74
|
+
minConfidence: relevance_1.defaultRelevanceConfig.minConfidence,
|
|
75
|
+
maxFindingsPerTool: relevance_1.defaultRelevanceConfig.maxFindingsPerTool,
|
|
76
|
+
maxFindingsTotal: relevance_1.defaultRelevanceConfig.maxFindingsTotal,
|
|
77
|
+
syntheticFilePolicy: relevance_1.defaultRelevanceConfig.syntheticFilePolicy,
|
|
78
|
+
validateSecrets: relevance_1.defaultRelevanceConfig.validateSecrets,
|
|
79
|
+
perTool: relevance_1.defaultRelevanceConfig.perTool,
|
|
80
|
+
fileRoles: {}
|
|
81
|
+
},
|
|
82
|
+
suppressions: {
|
|
83
|
+
enabled: true,
|
|
84
|
+
file: suppressions_1.SUPPRESSIONS_FILE,
|
|
85
|
+
requireExpiry: false
|
|
59
86
|
},
|
|
60
87
|
checks: {
|
|
61
88
|
security: {
|
|
@@ -119,6 +146,9 @@ exports.defaultConfig = {
|
|
|
119
146
|
enabled: true
|
|
120
147
|
}
|
|
121
148
|
},
|
|
149
|
+
flowAnalysis: {
|
|
150
|
+
enabled: true
|
|
151
|
+
},
|
|
122
152
|
dpdp: {
|
|
123
153
|
enabled: true,
|
|
124
154
|
include: [],
|
|
@@ -189,9 +219,66 @@ async function findConfigFile(root) {
|
|
|
189
219
|
}
|
|
190
220
|
return undefined;
|
|
191
221
|
}
|
|
222
|
+
function normalizeTimeoutPolicy(value, fallback) {
|
|
223
|
+
return value === "scoped_retry" || value === "skip" || value === "fail" ? value : fallback;
|
|
224
|
+
}
|
|
225
|
+
function normalizeConfidence(value, fallback) {
|
|
226
|
+
return value === "low" || value === "medium" || value === "high" ? value : fallback;
|
|
227
|
+
}
|
|
228
|
+
function normalizeRelevance(raw) {
|
|
229
|
+
const defaults = exports.defaultConfig.relevance;
|
|
230
|
+
const rawPerTool = (raw.perTool ?? raw.per_tool ?? {});
|
|
231
|
+
const rawFileRoles = (raw.fileRoles ?? raw.file_roles ?? {});
|
|
232
|
+
const policy = raw.syntheticFilePolicy ?? raw.synthetic_file_policy;
|
|
233
|
+
const perTool = { ...defaults.perTool };
|
|
234
|
+
for (const [tool, rawToolPolicy] of Object.entries(rawPerTool)) {
|
|
235
|
+
const existing = perTool[tool] ?? {};
|
|
236
|
+
const minConfidence = rawToolPolicy.minConfidence ?? rawToolPolicy.min_confidence;
|
|
237
|
+
const minEvidenceGrade = rawToolPolicy.minEvidenceGrade ?? rawToolPolicy.min_evidence_grade;
|
|
238
|
+
const maxFindings = rawToolPolicy.maxFindings ?? rawToolPolicy.max_findings;
|
|
239
|
+
const requireCorroboration = rawToolPolicy.requireCorroboration ?? rawToolPolicy.require_corroboration;
|
|
240
|
+
perTool[tool] = {
|
|
241
|
+
...existing,
|
|
242
|
+
...(minConfidence !== undefined ? { minConfidence: normalizeConfidence(minConfidence, "low") } : {}),
|
|
243
|
+
...(minEvidenceGrade === "unproven" ||
|
|
244
|
+
minEvidenceGrade === "heuristic" ||
|
|
245
|
+
minEvidenceGrade === "observed" ||
|
|
246
|
+
minEvidenceGrade === "verified"
|
|
247
|
+
? { minEvidenceGrade }
|
|
248
|
+
: {}),
|
|
249
|
+
...(typeof maxFindings === "number" ? { maxFindings } : {}),
|
|
250
|
+
...(typeof requireCorroboration === "boolean" ? { requireCorroboration } : {})
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const fileRoles = {};
|
|
254
|
+
for (const role of ["source", "test", "fixture", "generated", "vendor", "config", "docs"]) {
|
|
255
|
+
const patterns = normalizeStringArray(rawFileRoles[role], []);
|
|
256
|
+
if (patterns.length > 0) {
|
|
257
|
+
fileRoles[role] = patterns;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
enabled: raw.enabled ?? defaults.enabled,
|
|
262
|
+
minConfidence: normalizeConfidence(raw.minConfidence ?? raw.min_confidence, defaults.minConfidence),
|
|
263
|
+
maxFindingsPerTool: raw.maxFindingsPerTool ??
|
|
264
|
+
raw.max_findings_per_tool ??
|
|
265
|
+
defaults.maxFindingsPerTool,
|
|
266
|
+
maxFindingsTotal: raw.maxFindingsTotal ??
|
|
267
|
+
raw.max_findings_total ??
|
|
268
|
+
defaults.maxFindingsTotal,
|
|
269
|
+
syntheticFilePolicy: policy === "keep" || policy === "downgrade" || policy === "drop" ? policy : defaults.syntheticFilePolicy,
|
|
270
|
+
validateSecrets: raw.validateSecrets ??
|
|
271
|
+
raw.validate_secrets ??
|
|
272
|
+
defaults.validateSecrets,
|
|
273
|
+
perTool,
|
|
274
|
+
fileRoles
|
|
275
|
+
};
|
|
276
|
+
}
|
|
192
277
|
function normalizeRawConfig(raw) {
|
|
193
|
-
const { baseline: _baseline, checks: _checks, output: _output, runtime: _runtime, ...rest } = raw;
|
|
278
|
+
const { baseline: _baseline, checks: _checks, output: _output, runtime: _runtime, relevance: _relevance, suppressions: _suppressions, ...rest } = raw;
|
|
194
279
|
const rawChecks = raw.checks;
|
|
280
|
+
const rawRelevance = raw.relevance;
|
|
281
|
+
const rawSuppressions = raw.suppressions;
|
|
195
282
|
const rawBaseline = raw.baseline;
|
|
196
283
|
const rawOutput = raw.output;
|
|
197
284
|
const rawRuntime = raw.runtime;
|
|
@@ -205,6 +292,7 @@ function normalizeRawConfig(raw) {
|
|
|
205
292
|
const rawPrivacy = rawChecks?.privacy;
|
|
206
293
|
const rawPrivacyAi = (rawPrivacy?.ai ?? {});
|
|
207
294
|
const rawPresidio = (rawPrivacy?.presidio ?? {});
|
|
295
|
+
const rawFlow = (rawChecks?.flowAnalysis ?? rawChecks?.flow_analysis);
|
|
208
296
|
const rawDpdp = rawChecks?.dpdp;
|
|
209
297
|
const rawDpdpOrg = (rawDpdp?.organization ?? rawDpdp?.organisation ?? {});
|
|
210
298
|
return {
|
|
@@ -223,7 +311,31 @@ function normalizeRawConfig(raw) {
|
|
|
223
311
|
exports.defaultConfig.runtime.requiredTools,
|
|
224
312
|
failOnIncompleteScan: rawRuntime.failOnIncompleteScan ??
|
|
225
313
|
rawRuntime.fail_on_incomplete_scan ??
|
|
226
|
-
exports.defaultConfig.runtime.failOnIncompleteScan
|
|
314
|
+
exports.defaultConfig.runtime.failOnIncompleteScan,
|
|
315
|
+
totalBudgetSeconds: rawRuntime.totalBudgetSeconds ??
|
|
316
|
+
rawRuntime.total_budget_seconds ??
|
|
317
|
+
exports.defaultConfig.runtime.totalBudgetSeconds,
|
|
318
|
+
onTimeout: normalizeTimeoutPolicy(rawRuntime.onTimeout ?? rawRuntime.on_timeout, exports.defaultConfig.runtime.onTimeout),
|
|
319
|
+
scopedRetryTimeoutSeconds: rawRuntime.scopedRetryTimeoutSeconds ??
|
|
320
|
+
rawRuntime.scoped_retry_timeout_seconds ??
|
|
321
|
+
exports.defaultConfig.runtime.scopedRetryTimeoutSeconds,
|
|
322
|
+
deferredTools: normalizeStringArray(rawRuntime.deferredTools ?? rawRuntime.deferred_tools, exports.defaultConfig.runtime.deferredTools),
|
|
323
|
+
verifyToolsBeforeScan: rawRuntime.verifyToolsBeforeScan ??
|
|
324
|
+
rawRuntime.verify_tools_before_scan ??
|
|
325
|
+
exports.defaultConfig.runtime.verifyToolsBeforeScan,
|
|
326
|
+
managedTools: normalizeManagedTools(rawRuntime.managedTools ?? rawRuntime.managed_tools)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
: {}),
|
|
330
|
+
...(rawRelevance ? { relevance: normalizeRelevance(rawRelevance) } : {}),
|
|
331
|
+
...(rawSuppressions
|
|
332
|
+
? {
|
|
333
|
+
suppressions: {
|
|
334
|
+
enabled: rawSuppressions.enabled ?? exports.defaultConfig.suppressions.enabled,
|
|
335
|
+
file: rawSuppressions.file ?? exports.defaultConfig.suppressions.file,
|
|
336
|
+
requireExpiry: rawSuppressions.requireExpiry ??
|
|
337
|
+
rawSuppressions.require_expiry ??
|
|
338
|
+
exports.defaultConfig.suppressions.requireExpiry
|
|
227
339
|
}
|
|
228
340
|
}
|
|
229
341
|
: {}),
|
|
@@ -390,6 +502,11 @@ function normalizeRawConfig(raw) {
|
|
|
390
502
|
}
|
|
391
503
|
}
|
|
392
504
|
: exports.defaultConfig.checks.privacy,
|
|
505
|
+
flowAnalysis: rawFlow
|
|
506
|
+
? {
|
|
507
|
+
enabled: rawFlow.enabled ?? exports.defaultConfig.checks.flowAnalysis.enabled
|
|
508
|
+
}
|
|
509
|
+
: exports.defaultConfig.checks.flowAnalysis,
|
|
393
510
|
dpdp: rawDpdp
|
|
394
511
|
? {
|
|
395
512
|
enabled: rawDpdp.enabled ?? exports.defaultConfig.checks.dpdp.enabled,
|
|
@@ -434,6 +551,20 @@ function normalizeRawConfig(raw) {
|
|
|
434
551
|
: {})
|
|
435
552
|
};
|
|
436
553
|
}
|
|
554
|
+
function normalizeManagedTools(raw) {
|
|
555
|
+
const defaults = exports.defaultConfig.runtime.managedTools;
|
|
556
|
+
if (!isRecord(raw)) {
|
|
557
|
+
return { ...defaults };
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
enabled: raw.enabled ?? defaults.enabled,
|
|
561
|
+
cacheDir: raw.cacheDir ?? raw.cache_dir ?? defaults.cacheDir,
|
|
562
|
+
allowNetwork: raw.allowNetwork ?? raw.allow_network ?? defaults.allowNetwork,
|
|
563
|
+
preferProjectLocal: raw.preferProjectLocal ??
|
|
564
|
+
raw.prefer_project_local ??
|
|
565
|
+
defaults.preferProjectLocal
|
|
566
|
+
};
|
|
567
|
+
}
|
|
437
568
|
function normalizeTriState(value, fallback) {
|
|
438
569
|
if (value === true || value === "true" || value === "yes") {
|
|
439
570
|
return "true";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decides whether a string is plausibly a credential.
|
|
3
|
+
*
|
|
4
|
+
* Secret scanners match on assignment shape, so any identifier whose name ends
|
|
5
|
+
* in `key`, `token`, or `secret` can be reported as a critical leak — including
|
|
6
|
+
* ordinary map keys like `format_key` or `thread_key`. Reporting those at
|
|
7
|
+
* critical severity trains users to ignore the secrets category entirely, which
|
|
8
|
+
* costs more than the occasional missed finding. This evaluates the matched text
|
|
9
|
+
* itself: a real credential is high-entropy and structureless, while an
|
|
10
|
+
* identifier is short, lowercase, and made of dictionary-shaped words.
|
|
11
|
+
*/
|
|
12
|
+
export type CredentialAssessment = {
|
|
13
|
+
/** Best guess at what the matched text is. */
|
|
14
|
+
verdict: "credential" | "identifier" | "placeholder" | "unknown";
|
|
15
|
+
/** Shannon entropy in bits per character. */
|
|
16
|
+
entropy: number;
|
|
17
|
+
/** Why the verdict was reached, for the report. */
|
|
18
|
+
reason: string;
|
|
19
|
+
};
|
|
20
|
+
export declare function shannonEntropy(value: string): number;
|
|
21
|
+
export declare function assessCredential(value: string | undefined): CredentialAssessment;
|
|
22
|
+
/** Masks a value for reporting, keeping enough to recognise it. */
|
|
23
|
+
export declare function maskValue(value: string | undefined): string | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Pulls the candidate secret out of a source line. Scanners often redact their
|
|
26
|
+
* own output, so the line the finding points at is the only place left to look.
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractAssignedValue(line: string | undefined): string | undefined;
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Decides whether a string is plausibly a credential.
|
|
4
|
+
*
|
|
5
|
+
* Secret scanners match on assignment shape, so any identifier whose name ends
|
|
6
|
+
* in `key`, `token`, or `secret` can be reported as a critical leak — including
|
|
7
|
+
* ordinary map keys like `format_key` or `thread_key`. Reporting those at
|
|
8
|
+
* critical severity trains users to ignore the secrets category entirely, which
|
|
9
|
+
* costs more than the occasional missed finding. This evaluates the matched text
|
|
10
|
+
* itself: a real credential is high-entropy and structureless, while an
|
|
11
|
+
* identifier is short, lowercase, and made of dictionary-shaped words.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.shannonEntropy = shannonEntropy;
|
|
15
|
+
exports.assessCredential = assessCredential;
|
|
16
|
+
exports.maskValue = maskValue;
|
|
17
|
+
exports.extractAssignedValue = extractAssignedValue;
|
|
18
|
+
/** Prefixes that are self-identifying credentials regardless of entropy. */
|
|
19
|
+
const KNOWN_CREDENTIAL_PREFIXES = [
|
|
20
|
+
"sk-",
|
|
21
|
+
"pk-",
|
|
22
|
+
"rk_",
|
|
23
|
+
"ghp_",
|
|
24
|
+
"gho_",
|
|
25
|
+
"ghu_",
|
|
26
|
+
"ghs_",
|
|
27
|
+
"ghr_",
|
|
28
|
+
"github_pat_",
|
|
29
|
+
"glpat-",
|
|
30
|
+
"xox",
|
|
31
|
+
"AKIA",
|
|
32
|
+
"ASIA",
|
|
33
|
+
"AIza",
|
|
34
|
+
"ya29.",
|
|
35
|
+
"SG.",
|
|
36
|
+
"dop_v1_",
|
|
37
|
+
"shpat_",
|
|
38
|
+
"npm_",
|
|
39
|
+
"hf_",
|
|
40
|
+
"-----BEGIN"
|
|
41
|
+
];
|
|
42
|
+
/** Values that exist to be replaced, not protected. */
|
|
43
|
+
const PLACEHOLDER_PATTERNS = [
|
|
44
|
+
/^(?:x{3,}|\*{3,}|\.{3,}|-{3,})$/i,
|
|
45
|
+
/^(?:your|my|the)[-_ ]?(?:api[-_ ]?)?(?:key|token|secret|password)$/i,
|
|
46
|
+
/^(?:changeme|change[-_ ]me|replace[-_ ]me|todo|tbd|none|null|undefined|empty|example|sample|dummy|test|fake|foo|bar|baz)$/i,
|
|
47
|
+
/^(?:REDACTED|MASKED|HIDDEN|SECRET|PASSWORD|API[-_]?KEY)$/i,
|
|
48
|
+
/^\$\{?[A-Z0-9_]+\}?$/,
|
|
49
|
+
/^<[^>]+>$/,
|
|
50
|
+
/^\{\{.*\}\}$/,
|
|
51
|
+
/^process\.env\./,
|
|
52
|
+
/^os\.(?:environ|getenv)/
|
|
53
|
+
];
|
|
54
|
+
/** Shapes a programmer writes deliberately: identifiers, paths, dotted names. */
|
|
55
|
+
const IDENTIFIER_PATTERN = /^[a-z][a-z0-9]*(?:[_-][a-z0-9]+)*$/;
|
|
56
|
+
const CAMEL_CASE_PATTERN = /^[a-z][a-zA-Z0-9]*$/;
|
|
57
|
+
const DOTTED_PATH_PATTERN = /^[a-zA-Z_][\w-]*(?:[./][\w-]+)+$/;
|
|
58
|
+
function shannonEntropy(value) {
|
|
59
|
+
if (value.length === 0) {
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
const counts = new Map();
|
|
63
|
+
for (const character of value) {
|
|
64
|
+
counts.set(character, (counts.get(character) ?? 0) + 1);
|
|
65
|
+
}
|
|
66
|
+
let entropy = 0;
|
|
67
|
+
for (const count of counts.values()) {
|
|
68
|
+
const probability = count / value.length;
|
|
69
|
+
entropy -= probability * Math.log2(probability);
|
|
70
|
+
}
|
|
71
|
+
return entropy;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Splits on case and separator boundaries. An identifier made entirely of short
|
|
75
|
+
* word-like segments is a name; a credential is not decomposable that way.
|
|
76
|
+
*/
|
|
77
|
+
function wordSegments(value) {
|
|
78
|
+
return value
|
|
79
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
80
|
+
.split(/[\s_\-./]+/)
|
|
81
|
+
.filter(Boolean);
|
|
82
|
+
}
|
|
83
|
+
function looksLikeWords(value) {
|
|
84
|
+
const segments = wordSegments(value);
|
|
85
|
+
if (segments.length === 0) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
// Every segment alphabetic and of pronounceable length.
|
|
89
|
+
return segments.every((segment) => /^[A-Za-z]{2,14}$/.test(segment));
|
|
90
|
+
}
|
|
91
|
+
const MIN_CREDENTIAL_LENGTH = 16;
|
|
92
|
+
const CREDENTIAL_ENTROPY_THRESHOLD = 3.2;
|
|
93
|
+
function assessCredential(value) {
|
|
94
|
+
const trimmed = value?.trim().replace(/^["'`]|["'`]$/g, "") ?? "";
|
|
95
|
+
if (!trimmed) {
|
|
96
|
+
return { verdict: "unknown", entropy: 0, reason: "No matched value was available to evaluate." };
|
|
97
|
+
}
|
|
98
|
+
if (KNOWN_CREDENTIAL_PREFIXES.some((prefix) => trimmed.startsWith(prefix))) {
|
|
99
|
+
return {
|
|
100
|
+
verdict: "credential",
|
|
101
|
+
entropy: shannonEntropy(trimmed),
|
|
102
|
+
reason: "Value carries a recognised credential prefix."
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (PLACEHOLDER_PATTERNS.some((pattern) => pattern.test(trimmed))) {
|
|
106
|
+
return {
|
|
107
|
+
verdict: "placeholder",
|
|
108
|
+
entropy: shannonEntropy(trimmed),
|
|
109
|
+
reason: "Value is a placeholder or an environment-variable reference, not a literal credential."
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const entropy = shannonEntropy(trimmed);
|
|
113
|
+
if (trimmed.length < MIN_CREDENTIAL_LENGTH && (IDENTIFIER_PATTERN.test(trimmed) || CAMEL_CASE_PATTERN.test(trimmed))) {
|
|
114
|
+
return {
|
|
115
|
+
verdict: "identifier",
|
|
116
|
+
entropy,
|
|
117
|
+
reason: `Value is a ${trimmed.length}-character identifier ("${trimmed}"), too short and too structured to be a credential.`
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (DOTTED_PATH_PATTERN.test(trimmed) && entropy < CREDENTIAL_ENTROPY_THRESHOLD) {
|
|
121
|
+
return {
|
|
122
|
+
verdict: "identifier",
|
|
123
|
+
entropy,
|
|
124
|
+
reason: "Value is a dotted or path-like name rather than an opaque token."
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (looksLikeWords(trimmed) && entropy < CREDENTIAL_ENTROPY_THRESHOLD) {
|
|
128
|
+
return {
|
|
129
|
+
verdict: "identifier",
|
|
130
|
+
entropy,
|
|
131
|
+
reason: `Value decomposes into dictionary-shaped words (entropy ${entropy.toFixed(2)} bits/char).`
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (entropy < CREDENTIAL_ENTROPY_THRESHOLD && trimmed.length < 32) {
|
|
135
|
+
return {
|
|
136
|
+
verdict: "identifier",
|
|
137
|
+
entropy,
|
|
138
|
+
reason: `Entropy ${entropy.toFixed(2)} bits/char over ${trimmed.length} characters is below what a generated credential shows.`
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
verdict: "credential",
|
|
143
|
+
entropy,
|
|
144
|
+
reason: `Entropy ${entropy.toFixed(2)} bits/char over ${trimmed.length} characters is consistent with a generated credential.`
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/** Masks a value for reporting, keeping enough to recognise it. */
|
|
148
|
+
function maskValue(value) {
|
|
149
|
+
if (!value) {
|
|
150
|
+
return undefined;
|
|
151
|
+
}
|
|
152
|
+
const trimmed = value.trim();
|
|
153
|
+
if (trimmed.length <= 8) {
|
|
154
|
+
return `${trimmed.slice(0, 2)}${"*".repeat(Math.max(0, trimmed.length - 2))}`;
|
|
155
|
+
}
|
|
156
|
+
return `${trimmed.slice(0, 4)}${"*".repeat(6)}${trimmed.slice(-2)}`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Pulls the candidate secret out of a source line. Scanners often redact their
|
|
160
|
+
* own output, so the line the finding points at is the only place left to look.
|
|
161
|
+
*/
|
|
162
|
+
function extractAssignedValue(line) {
|
|
163
|
+
if (!line) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
// Quoted literal on the right of an assignment, mapping, or argument.
|
|
167
|
+
const quoted = /(?::|=|=>|,)\s*(?:r|b|f|u)?(["'`])((?:(?!\1).){3,})\1/.exec(line);
|
|
168
|
+
if (quoted) {
|
|
169
|
+
return quoted[2];
|
|
170
|
+
}
|
|
171
|
+
// Bare value after an assignment (env files, YAML, INI).
|
|
172
|
+
const bare = /^[\s#-]*[A-Za-z_][\w.-]*\s*[:=]\s*([^\s"'#]{3,})\s*$/.exec(line);
|
|
173
|
+
if (bare) {
|
|
174
|
+
return bare[1];
|
|
175
|
+
}
|
|
176
|
+
// Any long quoted literal anywhere on the line.
|
|
177
|
+
const anyQuoted = /(["'`])((?:(?!\1).){8,})\1/.exec(line);
|
|
178
|
+
return anyQuoted?.[2];
|
|
179
|
+
}
|