@neuralaxis/vibedoctor 0.2.0 → 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 +86 -0
- package/dist/adapters/biome.js +135 -21
- package/dist/adapters/osvScanner.js +136 -17
- package/dist/adapters/presidio.js +3 -1
- package/dist/cli/commands/init.js +105 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +36 -0
- package/dist/core/config.js +105 -3
- 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 +466 -85
- 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 +124 -0
- package/dist/core/finding.js +62 -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 -37
- 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/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/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 +1 -1
|
@@ -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,42 @@ 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
|
+
};
|
|
40
|
+
relevance: {
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
minConfidence: "low" | "medium" | "high";
|
|
43
|
+
maxFindingsPerTool: number;
|
|
44
|
+
maxFindingsTotal: number;
|
|
45
|
+
syntheticFilePolicy: "keep" | "downgrade" | "drop";
|
|
46
|
+
validateSecrets: boolean;
|
|
47
|
+
perTool: Record<string, {
|
|
48
|
+
minConfidence?: "low" | "medium" | "high";
|
|
49
|
+
minEvidenceGrade?: "unproven" | "heuristic" | "observed" | "verified";
|
|
50
|
+
maxFindings?: number;
|
|
51
|
+
requireCorroboration?: boolean;
|
|
52
|
+
}>;
|
|
53
|
+
/** Extra globs that classify files as tests, fixtures, generated, and so on. */
|
|
54
|
+
fileRoles: Partial<Record<"source" | "test" | "fixture" | "generated" | "vendor" | "config" | "docs", string[]>>;
|
|
55
|
+
};
|
|
56
|
+
suppressions: {
|
|
57
|
+
enabled: boolean;
|
|
58
|
+
file: string;
|
|
59
|
+
/** Reject acknowledgements with no expiry date. */
|
|
60
|
+
requireExpiry: boolean;
|
|
25
61
|
};
|
|
26
62
|
checks: {
|
|
27
63
|
security: {
|
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,27 @@ 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
|
+
},
|
|
67
|
+
relevance: {
|
|
68
|
+
enabled: true,
|
|
69
|
+
minConfidence: relevance_1.defaultRelevanceConfig.minConfidence,
|
|
70
|
+
maxFindingsPerTool: relevance_1.defaultRelevanceConfig.maxFindingsPerTool,
|
|
71
|
+
maxFindingsTotal: relevance_1.defaultRelevanceConfig.maxFindingsTotal,
|
|
72
|
+
syntheticFilePolicy: relevance_1.defaultRelevanceConfig.syntheticFilePolicy,
|
|
73
|
+
validateSecrets: relevance_1.defaultRelevanceConfig.validateSecrets,
|
|
74
|
+
perTool: relevance_1.defaultRelevanceConfig.perTool,
|
|
75
|
+
fileRoles: {}
|
|
76
|
+
},
|
|
77
|
+
suppressions: {
|
|
78
|
+
enabled: true,
|
|
79
|
+
file: suppressions_1.SUPPRESSIONS_FILE,
|
|
80
|
+
requireExpiry: false
|
|
59
81
|
},
|
|
60
82
|
checks: {
|
|
61
83
|
security: {
|
|
@@ -189,9 +211,66 @@ async function findConfigFile(root) {
|
|
|
189
211
|
}
|
|
190
212
|
return undefined;
|
|
191
213
|
}
|
|
214
|
+
function normalizeTimeoutPolicy(value, fallback) {
|
|
215
|
+
return value === "scoped_retry" || value === "skip" || value === "fail" ? value : fallback;
|
|
216
|
+
}
|
|
217
|
+
function normalizeConfidence(value, fallback) {
|
|
218
|
+
return value === "low" || value === "medium" || value === "high" ? value : fallback;
|
|
219
|
+
}
|
|
220
|
+
function normalizeRelevance(raw) {
|
|
221
|
+
const defaults = exports.defaultConfig.relevance;
|
|
222
|
+
const rawPerTool = (raw.perTool ?? raw.per_tool ?? {});
|
|
223
|
+
const rawFileRoles = (raw.fileRoles ?? raw.file_roles ?? {});
|
|
224
|
+
const policy = raw.syntheticFilePolicy ?? raw.synthetic_file_policy;
|
|
225
|
+
const perTool = { ...defaults.perTool };
|
|
226
|
+
for (const [tool, rawToolPolicy] of Object.entries(rawPerTool)) {
|
|
227
|
+
const existing = perTool[tool] ?? {};
|
|
228
|
+
const minConfidence = rawToolPolicy.minConfidence ?? rawToolPolicy.min_confidence;
|
|
229
|
+
const minEvidenceGrade = rawToolPolicy.minEvidenceGrade ?? rawToolPolicy.min_evidence_grade;
|
|
230
|
+
const maxFindings = rawToolPolicy.maxFindings ?? rawToolPolicy.max_findings;
|
|
231
|
+
const requireCorroboration = rawToolPolicy.requireCorroboration ?? rawToolPolicy.require_corroboration;
|
|
232
|
+
perTool[tool] = {
|
|
233
|
+
...existing,
|
|
234
|
+
...(minConfidence !== undefined ? { minConfidence: normalizeConfidence(minConfidence, "low") } : {}),
|
|
235
|
+
...(minEvidenceGrade === "unproven" ||
|
|
236
|
+
minEvidenceGrade === "heuristic" ||
|
|
237
|
+
minEvidenceGrade === "observed" ||
|
|
238
|
+
minEvidenceGrade === "verified"
|
|
239
|
+
? { minEvidenceGrade }
|
|
240
|
+
: {}),
|
|
241
|
+
...(typeof maxFindings === "number" ? { maxFindings } : {}),
|
|
242
|
+
...(typeof requireCorroboration === "boolean" ? { requireCorroboration } : {})
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const fileRoles = {};
|
|
246
|
+
for (const role of ["source", "test", "fixture", "generated", "vendor", "config", "docs"]) {
|
|
247
|
+
const patterns = normalizeStringArray(rawFileRoles[role], []);
|
|
248
|
+
if (patterns.length > 0) {
|
|
249
|
+
fileRoles[role] = patterns;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
enabled: raw.enabled ?? defaults.enabled,
|
|
254
|
+
minConfidence: normalizeConfidence(raw.minConfidence ?? raw.min_confidence, defaults.minConfidence),
|
|
255
|
+
maxFindingsPerTool: raw.maxFindingsPerTool ??
|
|
256
|
+
raw.max_findings_per_tool ??
|
|
257
|
+
defaults.maxFindingsPerTool,
|
|
258
|
+
maxFindingsTotal: raw.maxFindingsTotal ??
|
|
259
|
+
raw.max_findings_total ??
|
|
260
|
+
defaults.maxFindingsTotal,
|
|
261
|
+
syntheticFilePolicy: policy === "keep" || policy === "downgrade" || policy === "drop" ? policy : defaults.syntheticFilePolicy,
|
|
262
|
+
validateSecrets: raw.validateSecrets ??
|
|
263
|
+
raw.validate_secrets ??
|
|
264
|
+
defaults.validateSecrets,
|
|
265
|
+
perTool,
|
|
266
|
+
fileRoles
|
|
267
|
+
};
|
|
268
|
+
}
|
|
192
269
|
function normalizeRawConfig(raw) {
|
|
193
|
-
const { baseline: _baseline, checks: _checks, output: _output, runtime: _runtime, ...rest } = raw;
|
|
270
|
+
const { baseline: _baseline, checks: _checks, output: _output, runtime: _runtime, relevance: _relevance, suppressions: _suppressions, ...rest } = raw;
|
|
194
271
|
const rawChecks = raw.checks;
|
|
272
|
+
const rawRelevance = raw.relevance;
|
|
273
|
+
const rawSuppressions = raw.suppressions;
|
|
195
274
|
const rawBaseline = raw.baseline;
|
|
196
275
|
const rawOutput = raw.output;
|
|
197
276
|
const rawRuntime = raw.runtime;
|
|
@@ -223,7 +302,30 @@ function normalizeRawConfig(raw) {
|
|
|
223
302
|
exports.defaultConfig.runtime.requiredTools,
|
|
224
303
|
failOnIncompleteScan: rawRuntime.failOnIncompleteScan ??
|
|
225
304
|
rawRuntime.fail_on_incomplete_scan ??
|
|
226
|
-
exports.defaultConfig.runtime.failOnIncompleteScan
|
|
305
|
+
exports.defaultConfig.runtime.failOnIncompleteScan,
|
|
306
|
+
totalBudgetSeconds: rawRuntime.totalBudgetSeconds ??
|
|
307
|
+
rawRuntime.total_budget_seconds ??
|
|
308
|
+
exports.defaultConfig.runtime.totalBudgetSeconds,
|
|
309
|
+
onTimeout: normalizeTimeoutPolicy(rawRuntime.onTimeout ?? rawRuntime.on_timeout, exports.defaultConfig.runtime.onTimeout),
|
|
310
|
+
scopedRetryTimeoutSeconds: rawRuntime.scopedRetryTimeoutSeconds ??
|
|
311
|
+
rawRuntime.scoped_retry_timeout_seconds ??
|
|
312
|
+
exports.defaultConfig.runtime.scopedRetryTimeoutSeconds,
|
|
313
|
+
deferredTools: normalizeStringArray(rawRuntime.deferredTools ?? rawRuntime.deferred_tools, exports.defaultConfig.runtime.deferredTools),
|
|
314
|
+
verifyToolsBeforeScan: rawRuntime.verifyToolsBeforeScan ??
|
|
315
|
+
rawRuntime.verify_tools_before_scan ??
|
|
316
|
+
exports.defaultConfig.runtime.verifyToolsBeforeScan
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
: {}),
|
|
320
|
+
...(rawRelevance ? { relevance: normalizeRelevance(rawRelevance) } : {}),
|
|
321
|
+
...(rawSuppressions
|
|
322
|
+
? {
|
|
323
|
+
suppressions: {
|
|
324
|
+
enabled: rawSuppressions.enabled ?? exports.defaultConfig.suppressions.enabled,
|
|
325
|
+
file: rawSuppressions.file ?? exports.defaultConfig.suppressions.file,
|
|
326
|
+
requireExpiry: rawSuppressions.requireExpiry ??
|
|
327
|
+
rawSuppressions.require_expiry ??
|
|
328
|
+
exports.defaultConfig.suppressions.requireExpiry
|
|
227
329
|
}
|
|
228
330
|
}
|
|
229
331
|
: {}),
|
|
@@ -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
|
+
}
|
package/dist/core/engine.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { type Finding, type FindingCategory } from "./finding";
|
|
|
3
3
|
import { type ScanMode } from "./scanPlanner";
|
|
4
4
|
import { type ScoreBreakdown } from "./scoring";
|
|
5
5
|
import { type ToolResult } from "./toolRunner";
|
|
6
|
+
import { type CapabilityMatrix } from "./capability";
|
|
7
|
+
import { type RelevanceReport } from "./relevance";
|
|
8
|
+
import { type SuppressionReport } from "./suppressions";
|
|
9
|
+
import { type ToolVerification } from "./toolVerification";
|
|
6
10
|
import { type PrivacyReviewSummary } from "./privacyReview";
|
|
7
11
|
export type AgentPlanTarget = "generic" | "codex" | "copilot" | "claude" | "cursor";
|
|
8
12
|
export type AgentPlanTask = {
|
|
@@ -75,6 +79,16 @@ export type ScanOutput = {
|
|
|
75
79
|
testCommands: string[];
|
|
76
80
|
agentPlan: AgentPlan;
|
|
77
81
|
configPath?: string;
|
|
82
|
+
/** Per-tool record of what ran, what did not, and why. */
|
|
83
|
+
capabilityMatrix: CapabilityMatrix;
|
|
84
|
+
/** What relevance filtering withheld, so a short report is never mistaken for a clean one. */
|
|
85
|
+
relevance: RelevanceReport;
|
|
86
|
+
/** Acknowledged findings, their rationales, and any that lapsed. */
|
|
87
|
+
suppressions: SuppressionReport;
|
|
88
|
+
/** Findings hidden by an active acknowledgement, kept for audit. */
|
|
89
|
+
suppressedFindings: Finding[];
|
|
90
|
+
/** Tool-by-tool proof of what resolved and ran, with paths and versions. */
|
|
91
|
+
verifications: ToolVerification[];
|
|
78
92
|
};
|
|
79
93
|
export type SafeFixResult = {
|
|
80
94
|
before: ScanOutput;
|
|
@@ -89,6 +103,13 @@ export type ExplainPayload = {
|
|
|
89
103
|
relatedFindings: Finding[];
|
|
90
104
|
skippedTools: SkippedToolSummary[];
|
|
91
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Fills in the reporting fields a scan produces, for callers that reconstruct a
|
|
108
|
+
* `ScanOutput` from something other than a live scan — a cached report written by
|
|
109
|
+
* an older version, or a test fixture. The defaults describe an unknown scan
|
|
110
|
+
* rather than a clean one: an empty matrix claims no coverage.
|
|
111
|
+
*/
|
|
112
|
+
export declare function withReportingDefaults(partial: Partial<ScanOutput> & Pick<ScanOutput, "findings">): ScanOutput;
|
|
92
113
|
export type ToolRetryOutput = {
|
|
93
114
|
tool: string;
|
|
94
115
|
status: ToolResult["status"];
|