@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,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPathKey = getPathKey;
|
|
7
|
+
exports.getLocalToolSearchPaths = getLocalToolSearchPaths;
|
|
8
|
+
exports.buildCommandEnv = buildCommandEnv;
|
|
9
|
+
exports.resolveExecutable = resolveExecutable;
|
|
10
|
+
exports.commandExists = commandExists;
|
|
11
|
+
exports.describeSearchPaths = describeSearchPaths;
|
|
12
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
/**
|
|
15
|
+
* Executable discovery, shared by every code path that needs to know whether a
|
|
16
|
+
* tool is usable.
|
|
17
|
+
*
|
|
18
|
+
* Setup used to answer "is this installed?" with one mechanism (`where`/`which`
|
|
19
|
+
* against a bare name) while the scanner answered it with another (PATH probing
|
|
20
|
+
* plus a shell fallback). When the two disagreed, setup reported success for a
|
|
21
|
+
* tool the scanner could not run. Everything now resolves through
|
|
22
|
+
* `resolveExecutable` against the same augmented environment, so "setup found
|
|
23
|
+
* it" and "the scanner can run it" are the same claim.
|
|
24
|
+
*/
|
|
25
|
+
const LOCAL_TOOL_PATHS = [
|
|
26
|
+
["node_modules", ".bin"],
|
|
27
|
+
[".venv", "Scripts"],
|
|
28
|
+
[".venv", "bin"],
|
|
29
|
+
["venv", "Scripts"],
|
|
30
|
+
["venv", "bin"]
|
|
31
|
+
];
|
|
32
|
+
function ancestorDirs(startDir) {
|
|
33
|
+
if (!startDir) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
const dirs = [];
|
|
37
|
+
let current = node_path_1.default.resolve(startDir);
|
|
38
|
+
while (true) {
|
|
39
|
+
dirs.push(current);
|
|
40
|
+
const parent = node_path_1.default.dirname(current);
|
|
41
|
+
if (parent === current) {
|
|
42
|
+
return dirs;
|
|
43
|
+
}
|
|
44
|
+
current = parent;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function getPathKey(env) {
|
|
48
|
+
return Object.keys(env).find((key) => key.toLowerCase() === "path") ?? "PATH";
|
|
49
|
+
}
|
|
50
|
+
function getLocalToolSearchPaths(cwd) {
|
|
51
|
+
const paths = ancestorDirs(cwd).flatMap((dir) => LOCAL_TOOL_PATHS.map((segments) => node_path_1.default.join(dir, ...segments)));
|
|
52
|
+
return Array.from(new Set(paths));
|
|
53
|
+
}
|
|
54
|
+
function getUserToolSearchPaths(env) {
|
|
55
|
+
const paths = [];
|
|
56
|
+
if (process.platform === "win32" && env.APPDATA) {
|
|
57
|
+
const pythonRoot = node_path_1.default.join(env.APPDATA, "Python");
|
|
58
|
+
try {
|
|
59
|
+
for (const entry of (0, node_fs_1.readdirSync)(pythonRoot, { withFileTypes: true })) {
|
|
60
|
+
if (entry.isDirectory() && /^Python\d+$/i.test(entry.name)) {
|
|
61
|
+
paths.push(node_path_1.default.join(pythonRoot, entry.name, "Scripts"));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// Python user packages have not been installed for this account.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (env.HOME) {
|
|
70
|
+
paths.push(node_path_1.default.join(env.HOME, ".local", "bin"));
|
|
71
|
+
}
|
|
72
|
+
return paths;
|
|
73
|
+
}
|
|
74
|
+
function buildCommandEnv(cwd, overrides) {
|
|
75
|
+
const env = { ...process.env, ...overrides };
|
|
76
|
+
const pathKey = getPathKey(env);
|
|
77
|
+
const existingPath = env[pathKey];
|
|
78
|
+
env[pathKey] = [...getLocalToolSearchPaths(cwd), ...getUserToolSearchPaths(env), existingPath]
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join(node_path_1.default.delimiter);
|
|
81
|
+
return env;
|
|
82
|
+
}
|
|
83
|
+
function isExecutableFile(candidate) {
|
|
84
|
+
try {
|
|
85
|
+
if (!(0, node_fs_1.statSync)(candidate).isFile()) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (process.platform === "win32") {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
(0, node_fs_1.accessSync)(candidate, node_fs_1.constants.X_OK);
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resolves a command name to a concrete file, searching the same augmented PATH
|
|
105
|
+
* the scanner uses. Returns undefined when nothing on PATH matches — callers
|
|
106
|
+
* should treat that as "not installed" and report the searched locations.
|
|
107
|
+
*/
|
|
108
|
+
function resolveExecutable(command, cwd, env = buildCommandEnv(cwd, undefined)) {
|
|
109
|
+
if (node_path_1.default.isAbsolute(command)) {
|
|
110
|
+
return isExecutableFile(command) ? { path: command, requiresShell: /\.(?:cmd|bat)$/i.test(command) } : undefined;
|
|
111
|
+
}
|
|
112
|
+
const pathValue = env[getPathKey(env)] ?? "";
|
|
113
|
+
const directories = pathValue.split(node_path_1.default.delimiter).filter(Boolean);
|
|
114
|
+
const extensions = process.platform === "win32"
|
|
115
|
+
? // An explicit extension on the command wins; otherwise try each PATHEXT entry.
|
|
116
|
+
node_path_1.default.extname(command)
|
|
117
|
+
? [""]
|
|
118
|
+
: (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").map((extension) => extension.toLowerCase())
|
|
119
|
+
: [""];
|
|
120
|
+
for (const directory of directories) {
|
|
121
|
+
for (const extension of extensions) {
|
|
122
|
+
const candidate = node_path_1.default.join(directory, `${command}${extension}`);
|
|
123
|
+
if ((0, node_fs_1.existsSync)(candidate) && isExecutableFile(candidate)) {
|
|
124
|
+
return { path: candidate, requiresShell: /\.(?:cmd|bat)$/i.test(candidate) };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
function commandExists(command, cwd) {
|
|
131
|
+
return resolveExecutable(command, cwd) !== undefined;
|
|
132
|
+
}
|
|
133
|
+
/** The directories searched, so a "not found" report can say where we looked. */
|
|
134
|
+
function describeSearchPaths(cwd) {
|
|
135
|
+
const env = buildCommandEnv(cwd, undefined);
|
|
136
|
+
return (env[getPathKey(env)] ?? "").split(node_path_1.default.delimiter).filter(Boolean);
|
|
137
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classifies what a file is for.
|
|
3
|
+
*
|
|
4
|
+
* Relevance decisions kept being made per tool: one detector learned to ignore
|
|
5
|
+
* fixtures, another flagged them as critical. A secret in a test fixture, a dead
|
|
6
|
+
* function in a generated client, and a type error in production code are not
|
|
7
|
+
* the same finding, and every tool needs the same answer to that question.
|
|
8
|
+
*/
|
|
9
|
+
export type FileRole = "source" | "test" | "fixture" | "generated" | "vendor" | "config" | "docs" | "unknown";
|
|
10
|
+
export type FileRoleClassifier = (file: string | undefined) => FileRole;
|
|
11
|
+
export type FileRoleOverrides = Partial<Record<FileRole, string[]>>;
|
|
12
|
+
/**
|
|
13
|
+
* Builds a classifier. Repository-specific globs are checked before the defaults
|
|
14
|
+
* so a project can correct a misclassification without disabling the rest.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createFileRoleClassifier(overrides?: FileRoleOverrides): FileRoleClassifier;
|
|
17
|
+
/** Roles where a finding is usually about the repository's real behaviour. */
|
|
18
|
+
export declare function isProductionRole(role: FileRole): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Roles where a "secret", a dead function, or a hardcoded personal identifier is
|
|
21
|
+
* expected by design. Findings here are still reported, at reduced severity, so
|
|
22
|
+
* a real leak in a fixture is not hidden outright.
|
|
23
|
+
*/
|
|
24
|
+
export declare function isSyntheticRole(role: FileRole): boolean;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFileRoleClassifier = createFileRoleClassifier;
|
|
4
|
+
exports.isProductionRole = isProductionRole;
|
|
5
|
+
exports.isSyntheticRole = isSyntheticRole;
|
|
6
|
+
const minimatch_1 = require("minimatch");
|
|
7
|
+
const DEFAULT_ROLE_PATTERNS = [
|
|
8
|
+
{
|
|
9
|
+
role: "fixture",
|
|
10
|
+
patterns: [
|
|
11
|
+
"**/fixtures/**",
|
|
12
|
+
"**/fixture/**",
|
|
13
|
+
"**/__fixtures__/**",
|
|
14
|
+
"**/testdata/**",
|
|
15
|
+
"**/test-data/**",
|
|
16
|
+
"**/mocks/**",
|
|
17
|
+
"**/__mocks__/**",
|
|
18
|
+
"**/samples/**",
|
|
19
|
+
"**/examples/**",
|
|
20
|
+
"**/seeds/**",
|
|
21
|
+
"**/*.fixture.*",
|
|
22
|
+
"**/*.mock.*"
|
|
23
|
+
]
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
role: "test",
|
|
27
|
+
patterns: [
|
|
28
|
+
"**/test/**",
|
|
29
|
+
"**/tests/**",
|
|
30
|
+
"**/__tests__/**",
|
|
31
|
+
"**/spec/**",
|
|
32
|
+
"**/*.test.*",
|
|
33
|
+
"**/*.spec.*",
|
|
34
|
+
"**/*_test.py",
|
|
35
|
+
"**/test_*.py",
|
|
36
|
+
"**/conftest.py",
|
|
37
|
+
"**/e2e/**"
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
role: "generated",
|
|
42
|
+
patterns: [
|
|
43
|
+
"**/*.generated.*",
|
|
44
|
+
"**/*.gen.*",
|
|
45
|
+
"**/generated/**",
|
|
46
|
+
"**/__generated__/**",
|
|
47
|
+
"**/*_pb2.py",
|
|
48
|
+
"**/*_pb2_grpc.py",
|
|
49
|
+
"**/*.pb.go",
|
|
50
|
+
"**/migrations/**",
|
|
51
|
+
"**/.next/**",
|
|
52
|
+
"**/dist/**",
|
|
53
|
+
"**/build/**",
|
|
54
|
+
"**/*.min.js",
|
|
55
|
+
"**/*.d.ts",
|
|
56
|
+
"**/*.snap"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
role: "vendor",
|
|
61
|
+
patterns: ["**/vendor/**", "**/node_modules/**", "**/third_party/**", "**/site-packages/**", "**/.venv/**"]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
role: "config",
|
|
65
|
+
patterns: [
|
|
66
|
+
"*.json",
|
|
67
|
+
"*.yml",
|
|
68
|
+
"*.yaml",
|
|
69
|
+
"*.toml",
|
|
70
|
+
"*.ini",
|
|
71
|
+
"*.cfg",
|
|
72
|
+
"**/.*rc",
|
|
73
|
+
"**/.*rc.*",
|
|
74
|
+
"**/*.config.*",
|
|
75
|
+
"**/Dockerfile*",
|
|
76
|
+
"**/*.env.example",
|
|
77
|
+
"**/.github/**"
|
|
78
|
+
]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
role: "docs",
|
|
82
|
+
patterns: ["**/*.md", "**/*.mdx", "**/*.rst", "**/*.txt", "**/docs/**", "**/LICENSE*", "**/CHANGELOG*"]
|
|
83
|
+
}
|
|
84
|
+
];
|
|
85
|
+
/**
|
|
86
|
+
* Builds a classifier. Repository-specific globs are checked before the defaults
|
|
87
|
+
* so a project can correct a misclassification without disabling the rest.
|
|
88
|
+
*/
|
|
89
|
+
function createFileRoleClassifier(overrides = {}) {
|
|
90
|
+
const compiled = [];
|
|
91
|
+
for (const [role, patterns] of Object.entries(overrides)) {
|
|
92
|
+
if (patterns && patterns.length > 0) {
|
|
93
|
+
compiled.push({ role, matchers: patterns.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true })) });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
for (const { role, patterns } of DEFAULT_ROLE_PATTERNS) {
|
|
97
|
+
compiled.push({ role, matchers: patterns.map((pattern) => new minimatch_1.Minimatch(pattern, { dot: true })) });
|
|
98
|
+
}
|
|
99
|
+
const cache = new Map();
|
|
100
|
+
return (file) => {
|
|
101
|
+
if (!file) {
|
|
102
|
+
return "unknown";
|
|
103
|
+
}
|
|
104
|
+
const cached = cache.get(file);
|
|
105
|
+
if (cached) {
|
|
106
|
+
return cached;
|
|
107
|
+
}
|
|
108
|
+
const normalized = file.split("\\").join("/");
|
|
109
|
+
const role = compiled.find(({ matchers }) => matchers.some((matcher) => matcher.match(normalized)))?.role ?? "source";
|
|
110
|
+
cache.set(file, role);
|
|
111
|
+
return role;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** Roles where a finding is usually about the repository's real behaviour. */
|
|
115
|
+
function isProductionRole(role) {
|
|
116
|
+
return role === "source" || role === "config";
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Roles where a "secret", a dead function, or a hardcoded personal identifier is
|
|
120
|
+
* expected by design. Findings here are still reported, at reduced severity, so
|
|
121
|
+
* a real leak in a fixture is not hidden outright.
|
|
122
|
+
*/
|
|
123
|
+
function isSyntheticRole(role) {
|
|
124
|
+
return role === "fixture" || role === "test" || role === "generated" || role === "vendor";
|
|
125
|
+
}
|
package/dist/core/finding.d.ts
CHANGED
|
@@ -4,6 +4,95 @@ export type FindingSource = (typeof FINDING_SOURCES)[number];
|
|
|
4
4
|
export type FindingCategory = (typeof FINDING_CATEGORIES)[number];
|
|
5
5
|
export type Severity = "info" | "low" | "medium" | "high" | "critical";
|
|
6
6
|
export type Confidence = "low" | "medium" | "high";
|
|
7
|
+
/**
|
|
8
|
+
* How strongly the evidence supports the claim, independent of how bad the claim
|
|
9
|
+
* would be if true.
|
|
10
|
+
*
|
|
11
|
+
* Severity and confidence together could not express the difference between "we
|
|
12
|
+
* traced this data into a log call" and "a variable name looked like an email
|
|
13
|
+
* field", so both were presented the same way. Reports that mix the two read as
|
|
14
|
+
* stronger than the evidence supports.
|
|
15
|
+
*/
|
|
16
|
+
export type EvidenceGrade =
|
|
17
|
+
/** A code path was followed and the claim holds. */
|
|
18
|
+
"verified"
|
|
19
|
+
/** A concrete match exists at a real location; its meaning is inferred. */
|
|
20
|
+
| "observed"
|
|
21
|
+
/** Inferred from names, patterns, or shape rather than behaviour. */
|
|
22
|
+
| "heuristic"
|
|
23
|
+
/** Neither presence nor absence could be established from the code. */
|
|
24
|
+
| "unproven";
|
|
25
|
+
/**
|
|
26
|
+
* For findings that assert something is missing, whether the absence is a fact
|
|
27
|
+
* or a limit of static analysis. A missing control and an unprovable control
|
|
28
|
+
* need different responses, and conflating them inflates readiness scores.
|
|
29
|
+
*/
|
|
30
|
+
export type AbsenceClaim = "control_absent" | "not_statically_provable" | "not_applicable";
|
|
31
|
+
/** How precisely the finding is anchored in the source. */
|
|
32
|
+
export type LocationQuality =
|
|
33
|
+
/** File, line, and column. */
|
|
34
|
+
"exact"
|
|
35
|
+
/** File and line. */
|
|
36
|
+
| "line_only"
|
|
37
|
+
/** File only; the tool reported no position. */
|
|
38
|
+
| "file_only"
|
|
39
|
+
/** No file; the claim is about the repository as a whole. */
|
|
40
|
+
| "repository";
|
|
41
|
+
/** Where a finding stands relative to the recorded baseline. */
|
|
42
|
+
export type BaselineState =
|
|
43
|
+
/** Not in the baseline. */
|
|
44
|
+
"new"
|
|
45
|
+
/** In the baseline; pre-existing debt. */
|
|
46
|
+
| "existing"
|
|
47
|
+
/** In the baseline but previously suppressed, and the suppression has lapsed. */
|
|
48
|
+
| "resurfaced";
|
|
49
|
+
/** One hop in a traced data path, for findings that follow data rather than match text. */
|
|
50
|
+
export type DataFlowStep = {
|
|
51
|
+
kind: "source" | "store" | "transform" | "processor" | "sink";
|
|
52
|
+
/** What this step is, in the repository's own terms ("sessionStorage", "OpenAI chat completion"). */
|
|
53
|
+
label: string;
|
|
54
|
+
file?: string;
|
|
55
|
+
startLine?: number;
|
|
56
|
+
/** How this specific hop was established. */
|
|
57
|
+
evidenceGrade: EvidenceGrade;
|
|
58
|
+
detail?: string;
|
|
59
|
+
};
|
|
60
|
+
/** What kind of work a fix actually is, so it reaches the right person. */
|
|
61
|
+
export type RemediationKind = "code" | "config" | "dependency" | "policy" | "human_review";
|
|
62
|
+
export type FindingRemediation = {
|
|
63
|
+
kind: RemediationKind;
|
|
64
|
+
/** The component or module that owns the fix. */
|
|
65
|
+
component?: string;
|
|
66
|
+
steps: string[];
|
|
67
|
+
/** What would have to be shown for this finding to be considered resolved. */
|
|
68
|
+
requiredEvidence?: string;
|
|
69
|
+
/** Set when the fix is not something an automated agent should attempt. */
|
|
70
|
+
requiresHumanDecision?: boolean;
|
|
71
|
+
};
|
|
72
|
+
/** Dependency identity, so advisories can be triaged rather than just counted. */
|
|
73
|
+
export type PackageReference = {
|
|
74
|
+
name: string;
|
|
75
|
+
version?: string;
|
|
76
|
+
ecosystem?: string;
|
|
77
|
+
/** Runtime exposure. A dev-only advisory is not equivalent to a shipped one. */
|
|
78
|
+
scope: "runtime" | "dev" | "optional" | "transitive" | "unknown";
|
|
79
|
+
/** Path from a direct dependency to this package. */
|
|
80
|
+
dependencyPath?: string[];
|
|
81
|
+
/** First version that resolves the advisory. */
|
|
82
|
+
fixedIn?: string;
|
|
83
|
+
/** Manifest or lockfile the dependency was read from. */
|
|
84
|
+
manifest?: string;
|
|
85
|
+
};
|
|
86
|
+
export type FindingSuppression = {
|
|
87
|
+
/** Suppression rule that matched. */
|
|
88
|
+
ruleId: string;
|
|
89
|
+
classification: "false_positive" | "accepted_risk" | "deferred" | "fixture";
|
|
90
|
+
reason: string;
|
|
91
|
+
owner?: string;
|
|
92
|
+
/** ISO date. A suppression without an expiry is a permanent exemption. */
|
|
93
|
+
expiresAt?: string;
|
|
94
|
+
expired: boolean;
|
|
95
|
+
};
|
|
7
96
|
export type Finding = {
|
|
8
97
|
id: string;
|
|
9
98
|
source: FindingSource;
|
|
@@ -15,12 +104,40 @@ export type Finding = {
|
|
|
15
104
|
file?: string;
|
|
16
105
|
startLine?: number;
|
|
17
106
|
endLine?: number;
|
|
107
|
+
startColumn?: number;
|
|
108
|
+
endColumn?: number;
|
|
18
109
|
isNew: boolean;
|
|
19
110
|
isAutofixable: boolean;
|
|
20
111
|
safeToAutofix: boolean;
|
|
21
112
|
fixCommand?: string;
|
|
22
113
|
agentInstruction?: string;
|
|
23
114
|
tags: string[];
|
|
115
|
+
/** How well the evidence supports the claim. Defaults per source at normalization. */
|
|
116
|
+
evidenceGrade?: EvidenceGrade;
|
|
117
|
+
/** Only meaningful for findings asserting something is missing. */
|
|
118
|
+
absenceClaim?: AbsenceClaim;
|
|
119
|
+
/** Set by the normalizer from whichever position fields the tool supplied. */
|
|
120
|
+
locationQuality?: LocationQuality;
|
|
121
|
+
/** Traced path from data source to sink, when the finding follows data. */
|
|
122
|
+
dataFlow?: DataFlowStep[];
|
|
123
|
+
remediation?: FindingRemediation;
|
|
124
|
+
package?: PackageReference;
|
|
125
|
+
/** Position relative to the baseline. `isNew` stays as the boolean shorthand. */
|
|
126
|
+
baselineState?: BaselineState;
|
|
127
|
+
/** True when the finding sits in a file changed on this branch. */
|
|
128
|
+
inChangedFile?: boolean;
|
|
129
|
+
/** Role of the containing file, used for relevance decisions. */
|
|
130
|
+
fileRole?: "source" | "test" | "fixture" | "generated" | "vendor" | "config" | "docs" | "unknown";
|
|
131
|
+
/** Ranking score used to order and cap output. Higher is more worth reading. */
|
|
132
|
+
priority?: number;
|
|
133
|
+
/**
|
|
134
|
+
* Other tools that independently reported the same problem. Agreement between
|
|
135
|
+
* tools is the cheapest available corroboration, and it lets noisy detectors
|
|
136
|
+
* be filtered down to their cross-validated subset.
|
|
137
|
+
*/
|
|
138
|
+
corroboratedBy?: string[];
|
|
139
|
+
/** Present when a suppression rule matched this finding. */
|
|
140
|
+
suppression?: FindingSuppression;
|
|
24
141
|
evidence?: {
|
|
25
142
|
snippet?: string;
|
|
26
143
|
toolRawId?: string;
|
|
@@ -39,6 +156,13 @@ export type Finding = {
|
|
|
39
156
|
rationale?: string;
|
|
40
157
|
recommendedAction?: string;
|
|
41
158
|
reasons?: string[];
|
|
159
|
+
/**
|
|
160
|
+
* Byte offset into the file, when a tool reports positions that way. The
|
|
161
|
+
* normalizer converts it to a line number so no tool's locations are lost
|
|
162
|
+
* just because it uses a different position model.
|
|
163
|
+
*/
|
|
164
|
+
startOffset?: number;
|
|
165
|
+
endOffset?: number;
|
|
42
166
|
};
|
|
43
167
|
scoreImpact: number;
|
|
44
168
|
};
|
package/dist/core/finding.js
CHANGED
|
@@ -91,11 +91,17 @@ function fingerprintFinding(finding) {
|
|
|
91
91
|
return (0, node_crypto_1.createHash)("sha1").update(payload).digest("hex");
|
|
92
92
|
}
|
|
93
93
|
function applyBaseline(findings, baselineFingerprints) {
|
|
94
|
-
return findings.map((finding) =>
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
94
|
+
return findings.map((finding) => {
|
|
95
|
+
const isNew = !baselineFingerprints.has(fingerprintFinding(finding));
|
|
96
|
+
return {
|
|
97
|
+
...finding,
|
|
98
|
+
id: finding.id || fingerprintFinding(finding),
|
|
99
|
+
isNew,
|
|
100
|
+
// A finding whose suppression has lapsed is neither new nor quietly
|
|
101
|
+
// pre-existing: it was deliberately hidden and that decision has expired.
|
|
102
|
+
baselineState: finding.suppression?.expired ? "resurfaced" : isNew ? "new" : "existing"
|
|
103
|
+
};
|
|
104
|
+
});
|
|
99
105
|
}
|
|
100
106
|
function dedupeKey(finding) {
|
|
101
107
|
return [
|
|
@@ -118,6 +124,46 @@ const confidenceOrder = {
|
|
|
118
124
|
medium: 1,
|
|
119
125
|
high: 2
|
|
120
126
|
};
|
|
127
|
+
const evidenceGradeOrder = {
|
|
128
|
+
unproven: 0,
|
|
129
|
+
heuristic: 1,
|
|
130
|
+
observed: 2,
|
|
131
|
+
verified: 3
|
|
132
|
+
};
|
|
133
|
+
const locationQualityOrder = {
|
|
134
|
+
repository: 0,
|
|
135
|
+
file_only: 1,
|
|
136
|
+
line_only: 2,
|
|
137
|
+
exact: 3
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* When two tools report the same problem, keep the better-supported version of
|
|
141
|
+
* each fact rather than whichever arrived first: the stronger evidence grade,
|
|
142
|
+
* the more precise location, and any structured detail the other tool lacked.
|
|
143
|
+
*/
|
|
144
|
+
function mergeEvidenceGrade(left, right) {
|
|
145
|
+
if (!left.evidenceGrade) {
|
|
146
|
+
return right.evidenceGrade;
|
|
147
|
+
}
|
|
148
|
+
if (!right.evidenceGrade) {
|
|
149
|
+
return left.evidenceGrade;
|
|
150
|
+
}
|
|
151
|
+
return evidenceGradeOrder[right.evidenceGrade] > evidenceGradeOrder[left.evidenceGrade]
|
|
152
|
+
? right.evidenceGrade
|
|
153
|
+
: left.evidenceGrade;
|
|
154
|
+
}
|
|
155
|
+
function preferPreciseLocation(left, right) {
|
|
156
|
+
const leftRank = locationQualityOrder[left.locationQuality ?? "file_only"];
|
|
157
|
+
const rightRank = locationQualityOrder[right.locationQuality ?? "file_only"];
|
|
158
|
+
const winner = rightRank > leftRank ? right : left;
|
|
159
|
+
return {
|
|
160
|
+
startLine: winner.startLine,
|
|
161
|
+
endLine: winner.endLine,
|
|
162
|
+
startColumn: winner.startColumn,
|
|
163
|
+
endColumn: winner.endColumn,
|
|
164
|
+
locationQuality: winner.locationQuality
|
|
165
|
+
};
|
|
166
|
+
}
|
|
121
167
|
function dedupeFindings(findings) {
|
|
122
168
|
const byKey = new Map();
|
|
123
169
|
for (const finding of findings) {
|
|
@@ -140,6 +186,17 @@ function dedupeFindings(findings) {
|
|
|
140
186
|
evidence: existing.evidence ?? finding.evidence,
|
|
141
187
|
fixCommand: existing.fixCommand ?? finding.fixCommand,
|
|
142
188
|
agentInstruction: existing.agentInstruction ?? finding.agentInstruction,
|
|
189
|
+
...preferPreciseLocation(existing, finding),
|
|
190
|
+
evidenceGrade: mergeEvidenceGrade(existing, finding),
|
|
191
|
+
absenceClaim: existing.absenceClaim ?? finding.absenceClaim,
|
|
192
|
+
dataFlow: existing.dataFlow ?? finding.dataFlow,
|
|
193
|
+
remediation: existing.remediation ?? finding.remediation,
|
|
194
|
+
package: existing.package ?? finding.package,
|
|
195
|
+
fileRole: existing.fileRole ?? finding.fileRole,
|
|
196
|
+
suppression: existing.suppression ?? finding.suppression,
|
|
197
|
+
inChangedFile: existing.inChangedFile ?? finding.inChangedFile,
|
|
198
|
+
// Two tools agreeing is itself corroboration, so record who else saw it.
|
|
199
|
+
corroboratedBy: Array.from(new Set([...(existing.corroboratedBy ?? []), ...(finding.corroboratedBy ?? []), finding.source, existing.source])).filter((source) => source !== existing.source),
|
|
143
200
|
scoreImpact: Math.max(existing.scoreImpact, finding.scoreImpact)
|
|
144
201
|
});
|
|
145
202
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { FileRoleClassifier } from "./fileRole";
|
|
2
|
+
import { type Finding } from "./finding";
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes whatever adapters produce into a consistent finding.
|
|
5
|
+
*
|
|
6
|
+
* Adapters translate tool output by hand, so each one can lose a different thing:
|
|
7
|
+
* one drops line numbers because its tool reports byte offsets, another emits a
|
|
8
|
+
* severity string the report has no rendering for. The losses were invisible —
|
|
9
|
+
* the report simply had no location, and nothing said why. This pass fills in
|
|
10
|
+
* what can be recovered, records how precise each location actually is, and
|
|
11
|
+
* counts what could not be recovered so the capability matrix can disclose it.
|
|
12
|
+
*/
|
|
13
|
+
export type NormalizationIssue = {
|
|
14
|
+
tool: string;
|
|
15
|
+
kind: "missing_location" | "unresolved_offset" | "invalid_enum" | "missing_message";
|
|
16
|
+
count: number;
|
|
17
|
+
detail: string;
|
|
18
|
+
};
|
|
19
|
+
export type NormalizationResult = {
|
|
20
|
+
findings: Finding[];
|
|
21
|
+
issues: NormalizationIssue[];
|
|
22
|
+
/** Share of findings from this tool with no usable position, 0..1. */
|
|
23
|
+
locationLossRate: number;
|
|
24
|
+
};
|
|
25
|
+
export type NormalizeOptions = {
|
|
26
|
+
root: string;
|
|
27
|
+
tool: string;
|
|
28
|
+
classifyFile: FileRoleClassifier;
|
|
29
|
+
changedFiles?: string[];
|
|
30
|
+
};
|
|
31
|
+
export declare function normalizeFindings(raw: Finding[], options: NormalizeOptions): Promise<NormalizationResult>;
|
|
32
|
+
/** Human-readable summary of what a tool's output lost, for the capability matrix. */
|
|
33
|
+
export declare function describeNormalizationIssues(issues: NormalizationIssue[]): string | undefined;
|