@codyswann/lisa 4.96.2 → 4.96.3
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 +7 -0
- package/all/copy-overwrite/scripts/lisa-audit.mjs +59 -0
- package/all/copy-overwrite/scripts/lisa-gates.mjs +30 -13
- package/all/copy-overwrite/scripts/npm-updater-helper-graph.json +1 -1
- package/dist/cli/doctor-readiness-audit-allowlist.d.ts +19 -2
- package/dist/cli/doctor-readiness-audit-allowlist.d.ts.map +1 -1
- package/dist/cli/doctor-readiness-audit-allowlist.js +70 -17
- package/dist/cli/doctor-readiness-audit-allowlist.js.map +1 -1
- package/dist/cli/doctor-readiness-audit-scope.d.ts +24 -0
- package/dist/cli/doctor-readiness-audit-scope.d.ts.map +1 -0
- package/dist/cli/doctor-readiness-audit-scope.js +165 -0
- package/dist/cli/doctor-readiness-audit-scope.js.map +1 -0
- package/dist/cli/doctor-readiness-supply-chain-scan.js +1 -1
- package/dist/cli/doctor-readiness-supply-chain-scan.js.map +1 -1
- package/dist/cli/doctor-readiness-supply-chain.d.ts.map +1 -1
- package/dist/cli/doctor-readiness-supply-chain.js +4 -2
- package/dist/cli/doctor-readiness-supply-chain.js.map +1 -1
- package/dist/core/audit-capture.d.ts +31 -0
- package/dist/core/audit-capture.d.ts.map +1 -0
- package/dist/core/audit-capture.js +82 -0
- package/dist/core/audit-capture.js.map +1 -0
- package/dist/core/audit-exclusions.d.ts +32 -0
- package/dist/core/audit-exclusions.d.ts.map +1 -0
- package/dist/core/audit-exclusions.js +109 -0
- package/dist/core/audit-exclusions.js.map +1 -0
- package/dist/core/audit-field-names.d.ts +32 -0
- package/dist/core/audit-field-names.d.ts.map +1 -0
- package/dist/core/audit-field-names.js +107 -0
- package/dist/core/audit-field-names.js.map +1 -0
- package/dist/core/audit-lockfile.d.ts +9 -0
- package/dist/core/audit-lockfile.d.ts.map +1 -0
- package/dist/core/audit-lockfile.js +197 -0
- package/dist/core/audit-lockfile.js.map +1 -0
- package/dist/core/audit-manager.d.ts +8 -0
- package/dist/core/audit-manager.d.ts.map +1 -0
- package/dist/core/audit-manager.js +94 -0
- package/dist/core/audit-manager.js.map +1 -0
- package/dist/core/audit-matcher.d.ts +10 -0
- package/dist/core/audit-matcher.d.ts.map +1 -0
- package/dist/core/audit-matcher.js +103 -0
- package/dist/core/audit-matcher.js.map +1 -0
- package/dist/core/audit-report.d.ts +9 -0
- package/dist/core/audit-report.d.ts.map +1 -0
- package/dist/core/audit-report.js +132 -0
- package/dist/core/audit-report.js.map +1 -0
- package/dist/core/audit-types.d.ts +31 -0
- package/dist/core/audit-types.d.ts.map +1 -0
- package/dist/core/audit-types.js +2 -0
- package/dist/core/audit-types.js.map +1 -0
- package/dist/core/audit.d.ts +25 -0
- package/dist/core/audit.d.ts.map +1 -0
- package/dist/core/audit.js +53 -0
- package/dist/core/audit.js.map +1 -0
- package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
- package/dist/core/lisa-owned-hash-ledger.js +40 -0
- package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
- package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
- package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
- package/dist/core/upstream-evidence-manifest.js +52 -9
- package/dist/core/upstream-evidence-manifest.js.map +1 -1
- package/package.json +11 -6
- package/plugins/lisa/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa/rules/eager/security-audit-handling.md +2 -2
- package/plugins/lisa/rules/reference/security-audit-handling.md +9 -0
- package/plugins/lisa-agy/plugin.json +1 -1
- package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-agy/plugin.json +1 -1
- package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-copilot/rules/eager/security-audit-handling.md +2 -2
- package/plugins/lisa-copilot/rules/reference/security-audit-handling.md +9 -0
- package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-cursor/rules/security-audit-handling-reference.mdc +9 -0
- package/plugins/lisa-cursor/rules/security-audit-handling.mdc +2 -2
- package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-devin/rules/eager/security-audit-handling.md +2 -2
- package/plugins/lisa-devin/rules/reference/security-audit-handling.md +9 -0
- package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-agy/plugin.json +1 -1
- package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-agy/plugin.json +1 -1
- package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-agy/plugin.json +1 -1
- package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-agy/plugin.json +1 -1
- package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-agy/plugin.json +1 -1
- package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-agy/plugin.json +1 -1
- package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-agy/plugin.json +1 -1
- package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
- package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
- package/plugins/src/base/rules/eager/security-audit-handling.md +2 -2
- package/plugins/src/base/rules/reference/security-audit-handling.md +9 -0
- package/scripts/lisa-audit.mjs +59 -0
- package/scripts/two-channel-couplings.json +2 -2
- package/typescript/copy-contents/.husky/pre-push +5 -124
- package/typescript/copy-overwrite/.prettierignore +1 -0
- package/typescript/copy-overwrite/audit.ignore.config.json +6 -6
- package/typescript/package-lisa/package.lisa.json +4 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { parse as parseJsonc } from "jsonc-parser";
|
|
4
|
+
import * as yarnLockfile from "@yarnpkg/lockfile";
|
|
5
|
+
import { load as parseYaml } from "js-yaml";
|
|
6
|
+
import { valid, validRange } from "semver";
|
|
7
|
+
import { auditRecord } from "./audit-exclusions.js";
|
|
8
|
+
// Node 22's CommonJS lexer cannot see `parse` on this webpack bundle, so a named
|
|
9
|
+
// import crashes the module at load there. A namespace import always loads; the
|
|
10
|
+
// function is on it directly (bundlers, Node 24) or on its `default` (Node 22).
|
|
11
|
+
const yarnModule = yarnLockfile;
|
|
12
|
+
const parseYarn = yarnModule.parse ?? yarnModule.default?.parse;
|
|
13
|
+
/**
|
|
14
|
+
* Protocols whose copies come from somewhere other than the package registry.
|
|
15
|
+
* A registry advisory is reported for registry copies; a git, file, link,
|
|
16
|
+
* tarball, workspace or patch entry is not one, and treating it as unknown data
|
|
17
|
+
* used to fail every scoped exclusion in a project that has any such entry.
|
|
18
|
+
*/
|
|
19
|
+
const NON_REGISTRY_PROTOCOLS = new Set([
|
|
20
|
+
"workspace",
|
|
21
|
+
"root",
|
|
22
|
+
"file",
|
|
23
|
+
"link",
|
|
24
|
+
"portal",
|
|
25
|
+
"patch",
|
|
26
|
+
"exec",
|
|
27
|
+
"git",
|
|
28
|
+
"github",
|
|
29
|
+
"gitlab",
|
|
30
|
+
"bitbucket",
|
|
31
|
+
"http",
|
|
32
|
+
"https",
|
|
33
|
+
]);
|
|
34
|
+
/**
|
|
35
|
+
* Whether a resolved spec names a non-registry source.
|
|
36
|
+
* @param spec - The part after the package name (`1.2.3`, `file:../x`, …)
|
|
37
|
+
* @returns True for a non-registry source
|
|
38
|
+
*/
|
|
39
|
+
function isNonRegistrySpec(spec) {
|
|
40
|
+
const protocol = /^([a-z][a-z0-9+.-]*):/u.exec(spec)?.[1];
|
|
41
|
+
if (protocol === undefined)
|
|
42
|
+
return false;
|
|
43
|
+
// `git+https:`, `git+ssh:` and any `scheme://` URL are not registry copies.
|
|
44
|
+
return (NON_REGISTRY_PROTOCOLS.has(protocol) ||
|
|
45
|
+
protocol.startsWith("git+") ||
|
|
46
|
+
spec.startsWith(`${protocol}://`));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Split `name@spec`, honoring a leading scope; an `@` inside the spec stays.
|
|
50
|
+
* @param identity - Resolved identity such as `@scope/name@1.2.3`
|
|
51
|
+
* @returns The name and spec, or null when there is no separator
|
|
52
|
+
*/
|
|
53
|
+
function splitIdentity(identity) {
|
|
54
|
+
const index = identity.indexOf("@", identity.startsWith("@") ? 1 : 0);
|
|
55
|
+
return index < 1
|
|
56
|
+
? null
|
|
57
|
+
: { name: identity.slice(0, index), spec: identity.slice(index + 1) };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Split an exact resolved identity, including scoped package names.
|
|
61
|
+
* @param path - Exact lockfile key for this resolved package copy
|
|
62
|
+
* @param identity - Resolved package name and exact version
|
|
63
|
+
* @returns The validated result described above
|
|
64
|
+
*/
|
|
65
|
+
function resolvedCopy(path, identity) {
|
|
66
|
+
const split = splitIdentity(identity);
|
|
67
|
+
if (split === null || valid(split.spec) === null) {
|
|
68
|
+
throw new Error(`Unknown lockfile package data at ${path}: ${identity}`);
|
|
69
|
+
}
|
|
70
|
+
return { path, name: split.name, version: split.spec };
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Bun JSONC keys are paths; the resolved tuple carries the real alias name.
|
|
74
|
+
* @param source - Complete provider report or lockfile text
|
|
75
|
+
* @returns The validated result described above
|
|
76
|
+
*/
|
|
77
|
+
function bunCopies(source) {
|
|
78
|
+
const errors = [];
|
|
79
|
+
const parsed = parseJsonc(source, errors, {
|
|
80
|
+
allowTrailingComma: true,
|
|
81
|
+
});
|
|
82
|
+
if (errors.length || !auditRecord(parsed) || !auditRecord(parsed.packages)) {
|
|
83
|
+
throw new Error("Cannot parse bun.lock packages map (expected text JSONC)");
|
|
84
|
+
}
|
|
85
|
+
return Object.entries(parsed.packages).flatMap(([path, tuple]) => {
|
|
86
|
+
if (!Array.isArray(tuple) || typeof tuple[0] !== "string") {
|
|
87
|
+
throw new Error(`Unknown bun.lock package data at ${path}`);
|
|
88
|
+
}
|
|
89
|
+
// Workspace, git, file, link and tarball entries are not registry copies;
|
|
90
|
+
// their own dependencies are separate keys.
|
|
91
|
+
if (isNonRegistrySpec(splitIdentity(tuple[0])?.spec ?? ""))
|
|
92
|
+
return [];
|
|
93
|
+
return [resolvedCopy(path, tuple[0])];
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* npm's packages map records the resolved name for aliases.
|
|
98
|
+
* @param source - Complete provider report or lockfile text
|
|
99
|
+
* @returns The validated result described above
|
|
100
|
+
*/
|
|
101
|
+
function npmCopies(source) {
|
|
102
|
+
const parsed = JSON.parse(source);
|
|
103
|
+
if (!auditRecord(parsed) || !auditRecord(parsed.packages)) {
|
|
104
|
+
throw new Error("Cannot parse package-lock.json packages map (requires lockfile v2/v3)");
|
|
105
|
+
}
|
|
106
|
+
return Object.entries(parsed.packages).flatMap(([path, entry]) => {
|
|
107
|
+
if (!path)
|
|
108
|
+
return [];
|
|
109
|
+
// A workspace source (`packages/app`) is not an installed registry copy;
|
|
110
|
+
// every installed copy lives under node_modules/, and a workspace's own
|
|
111
|
+
// installed form is a `link: true` entry skipped below. Private workspaces
|
|
112
|
+
// often declare no version, so treating the source as package data failed
|
|
113
|
+
// every scoped exclusion in an npm monorepo.
|
|
114
|
+
if (!path.includes("node_modules/"))
|
|
115
|
+
return [];
|
|
116
|
+
if (!auditRecord(entry))
|
|
117
|
+
throw new Error(`Unknown package-lock.json entry at ${path}`);
|
|
118
|
+
if (entry.link === true)
|
|
119
|
+
return [];
|
|
120
|
+
const source = typeof entry.version === "string" ? entry.version : entry.resolved;
|
|
121
|
+
if (typeof source === "string" && isNonRegistrySpec(source))
|
|
122
|
+
return [];
|
|
123
|
+
const name = typeof entry.name === "string"
|
|
124
|
+
? entry.name
|
|
125
|
+
: path.split("node_modules/").at(-1);
|
|
126
|
+
if (!name || typeof entry.version !== "string") {
|
|
127
|
+
throw new Error(`Unknown package-lock.json package data at ${path}`);
|
|
128
|
+
}
|
|
129
|
+
const identity = entry.version.startsWith("npm:")
|
|
130
|
+
? entry.version.slice(4)
|
|
131
|
+
: `${name}@${entry.version}`;
|
|
132
|
+
return [resolvedCopy(path, identity)];
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Yarn key selectors are the exact paths exposed by its lockfile.
|
|
137
|
+
* @param source - Complete provider report or lockfile text
|
|
138
|
+
* @returns The validated result described above
|
|
139
|
+
*/
|
|
140
|
+
function yarnCopies(source) {
|
|
141
|
+
const berry = /(?:^|\n)__metadata:/u.test(source);
|
|
142
|
+
const classic = berry ? null : parseYarn(source);
|
|
143
|
+
if (classic && classic.type !== "success")
|
|
144
|
+
throw new Error("Cannot parse yarn.lock");
|
|
145
|
+
const parsed = berry ? parseYaml(source) : classic?.object;
|
|
146
|
+
if (!auditRecord(parsed))
|
|
147
|
+
throw new Error("Cannot parse yarn.lock package map");
|
|
148
|
+
if (!Object.keys(parsed).some(key => key !== "__metadata")) {
|
|
149
|
+
throw new Error("Cannot establish scoped audit coverage from empty yarn.lock package map");
|
|
150
|
+
}
|
|
151
|
+
return Object.entries(parsed).flatMap(([path, entry]) => {
|
|
152
|
+
if (path === "__metadata")
|
|
153
|
+
return [];
|
|
154
|
+
if (!auditRecord(entry) || typeof entry.version !== "string") {
|
|
155
|
+
throw new Error(`Unknown yarn.lock package data at ${path}`);
|
|
156
|
+
}
|
|
157
|
+
const descriptor = path.split(", ")[0] ?? "";
|
|
158
|
+
const separator = descriptor.indexOf("@", descriptor.startsWith("@") ? 1 : 0);
|
|
159
|
+
const selector = descriptor.slice(separator + 1);
|
|
160
|
+
const selectorRange = selector.startsWith("npm:")
|
|
161
|
+
? selector.slice(4)
|
|
162
|
+
: selector;
|
|
163
|
+
// A file, git, tarball, workspace or patch selector is not a registry copy.
|
|
164
|
+
if (separator > 0 && isNonRegistrySpec(selectorRange))
|
|
165
|
+
return [];
|
|
166
|
+
const realRange = selectorRange.includes("@")
|
|
167
|
+
? selectorRange.slice(selectorRange.lastIndexOf("@") + 1)
|
|
168
|
+
: selectorRange;
|
|
169
|
+
if (separator < 1 || validRange(realRange) === null) {
|
|
170
|
+
throw new Error(`Unknown yarn.lock package selector at ${path}`);
|
|
171
|
+
}
|
|
172
|
+
const alias = descriptor.indexOf("@npm:");
|
|
173
|
+
const name = descriptor.slice(0, separator);
|
|
174
|
+
const target = alias > 0 ? descriptor.slice(alias + 5) : "";
|
|
175
|
+
const realName = target.includes("@")
|
|
176
|
+
? target.slice(0, target.lastIndexOf("@"))
|
|
177
|
+
: name;
|
|
178
|
+
return [resolvedCopy(path, `${realName}@${entry.version}`)];
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Read the selected manager's actual lockfile, without fallback to id-wide scope.
|
|
183
|
+
* @param root - Project root containing the exact lockfile and exclusion documents
|
|
184
|
+
* @param manager - Package manager whose report and lockfile are evaluated
|
|
185
|
+
* @returns The validated result described above
|
|
186
|
+
*/
|
|
187
|
+
export function readAuditCopies(root, manager) {
|
|
188
|
+
const file = { bun: "bun.lock", npm: "package-lock.json", yarn: "yarn.lock" }[manager];
|
|
189
|
+
try {
|
|
190
|
+
const source = readFileSync(join(root, file), "utf8");
|
|
191
|
+
return { bun: bunCopies, npm: npmCopies, yarn: yarnCopies }[manager](source);
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
throw new Error(`Cannot evaluate scoped audit exclusions from ${file}: ${error.message}`, { cause: error });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=audit-lockfile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-lockfile.js","sourceRoot":"","sources":["../../src/core/audit-lockfile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,IAAI,UAAU,EAAmB,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,YAAY,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,iFAAiF;AACjF,gFAAgF;AAChF,gFAAgF;AAChF,MAAM,UAAU,GAAG,YAElB,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AE,CACjB,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AuditManager } from "./audit-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Select the manager with the shipped hook's precedence.
|
|
4
|
+
* @param root - Project root containing the manifest and lockfiles
|
|
5
|
+
* @returns The manager whose audit and lockfile are evaluated
|
|
6
|
+
*/
|
|
7
|
+
export declare function detectAuditManager(root: string): AuditManager;
|
|
8
|
+
//# sourceMappingURL=audit-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-manager.d.ts","sourceRoot":"","sources":["../../src/core/audit-manager.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAsFrD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAc7D"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choose the package manager whose audit and lockfile the canonical gate reads.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the shipped pre-push hook's `lisa_detect_pm` (#4521 review), so the
|
|
5
|
+
* hook, the registry task and the exported helper audit the same manager on
|
|
6
|
+
* the same tree: the `packageManager` field first, then an engines
|
|
7
|
+
* `please-use-<pm>` sentinel, then the lockfiles whose manager the engines do
|
|
8
|
+
* not forbid, in the hook's order. A lockfile left behind by another manager
|
|
9
|
+
* would otherwise make the registry route audit a different tree than the hook.
|
|
10
|
+
* @module core/audit-manager
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
/** Managers whose production audits the canonical matcher understands. */
|
|
15
|
+
const AUDITABLE = ["bun", "npm", "yarn"];
|
|
16
|
+
/** The hook's lockfile order, including pnpm so a pnpm tree is not mistaken. */
|
|
17
|
+
const LOCKFILES = [
|
|
18
|
+
["bun.lockb", "bun"],
|
|
19
|
+
["bun.lock", "bun"],
|
|
20
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
21
|
+
["yarn.lock", "yarn"],
|
|
22
|
+
["package-lock.json", "npm"],
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Parse package.json, treating an absent or unreadable one as no hints (the
|
|
26
|
+
* hook's jq reads it the same way: failure yields empty strings).
|
|
27
|
+
* @param file - Path to package.json
|
|
28
|
+
* @returns The parsed manifest, or null
|
|
29
|
+
*/
|
|
30
|
+
function readManifest(file) {
|
|
31
|
+
if (!existsSync(file))
|
|
32
|
+
return null;
|
|
33
|
+
try {
|
|
34
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Read the manager hints exactly as the hook's jq expressions do.
|
|
42
|
+
* @param root - Project root
|
|
43
|
+
* @returns The packageManager name, the forced manager, the forbidden managers
|
|
44
|
+
*/
|
|
45
|
+
function manifestHints(root) {
|
|
46
|
+
const none = { field: "", forced: "", forbidden: new Set() };
|
|
47
|
+
const manifest = readManifest(join(root, "package.json"));
|
|
48
|
+
if (manifest === null || typeof manifest !== "object")
|
|
49
|
+
return none;
|
|
50
|
+
const { packageManager, engines } = manifest;
|
|
51
|
+
const entries = engines !== null && typeof engines === "object"
|
|
52
|
+
? Object.entries(engines).filter((pair) => typeof pair[1] === "string")
|
|
53
|
+
: [];
|
|
54
|
+
const forced = entries
|
|
55
|
+
.map(([, value]) => /please-use-(bun|npm|yarn|pnpm)/u.exec(value)?.[1])
|
|
56
|
+
.find(name => name !== undefined) ?? "";
|
|
57
|
+
return {
|
|
58
|
+
field: typeof packageManager === "string"
|
|
59
|
+
? (packageManager.split("@")[0] ?? "")
|
|
60
|
+
: "",
|
|
61
|
+
forced,
|
|
62
|
+
forbidden: new Set(entries
|
|
63
|
+
.filter(([, value]) => /please-use|do-not-use/iu.test(value))
|
|
64
|
+
.map(([key]) => key)),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Accept a selected manager only if its audit is one Lisa can evaluate.
|
|
69
|
+
* @param manager - The selected manager name
|
|
70
|
+
* @param why - How it was selected, for the operator
|
|
71
|
+
* @returns The manager
|
|
72
|
+
*/
|
|
73
|
+
function auditable(manager, why) {
|
|
74
|
+
if (AUDITABLE.includes(manager))
|
|
75
|
+
return manager;
|
|
76
|
+
throw new Error(`This project uses ${manager} (${why}), whose audit Lisa's canonical matcher does not evaluate; declare a dependency-vulnerability task for it`);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Select the manager with the shipped hook's precedence.
|
|
80
|
+
* @param root - Project root containing the manifest and lockfiles
|
|
81
|
+
* @returns The manager whose audit and lockfile are evaluated
|
|
82
|
+
*/
|
|
83
|
+
export function detectAuditManager(root) {
|
|
84
|
+
const hints = manifestHints(root);
|
|
85
|
+
if (["bun", "npm", "yarn", "pnpm"].includes(hints.field))
|
|
86
|
+
return auditable(hints.field, "packageManager in package.json");
|
|
87
|
+
if (hints.forced !== "")
|
|
88
|
+
return auditable(hints.forced, "an engines please-use sentinel");
|
|
89
|
+
const found = LOCKFILES.find(([file, manager]) => !hints.forbidden.has(manager) && existsSync(join(root, file)));
|
|
90
|
+
if (found)
|
|
91
|
+
return auditable(found[1], `${found[0]} is present`);
|
|
92
|
+
throw new Error("No supported audit lockfile found (bun.lock, package-lock.json or yarn.lock)");
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=audit-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-manager.js","sourceRoot":"","sources":["../../src/core/audit-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGj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AClE,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE;QACrB,OAAO,SAAS,CAAC,KAAK,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAC;IACnE,MAAM,KAAK,GAAG,SAAS,CAAC,IAAI,CAC1B,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE,CAClB,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAChE,CAAC;IACF,IAAI,KAAK;QAAE,OAAO,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC;IAChE,MAAM,IAAI,KAAK,CACb,8EAA8E,CAC/E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuditCopy, AuditExclusion, AuditFinding, AuditVerdict } from "./audit-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate every finding; an unmatched finding remains a finding.
|
|
4
|
+
* @param findings - All normalized high and critical advisories
|
|
5
|
+
* @param exclusions - Validated active exclusions from both decision files
|
|
6
|
+
* @param copies - Resolved lockfile copies with real package identities
|
|
7
|
+
* @returns The validated result described above
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchAuditFindings(findings: readonly AuditFinding[], exclusions: readonly AuditExclusion[], copies: readonly AuditCopy[]): AuditVerdict;
|
|
10
|
+
//# sourceMappingURL=audit-matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-matcher.d.ts","sourceRoot":"","sources":["../../src/core/audit-matcher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,cAAc,EACd,YAAY,EACZ,YAAY,EACb,MAAM,kBAAkB,CAAC;AAyF1B;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,UAAU,EAAE,SAAS,cAAc,EAAE,EACrC,MAAM,EAAE,SAAS,SAAS,EAAE,GAC3B,YAAY,CAiCd"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { satisfies, validRange } from "semver";
|
|
2
|
+
import { requiresLockfileScope } from "./audit-exclusions.js";
|
|
3
|
+
/**
|
|
4
|
+
* Match advisory identity, package, installed version and path together.
|
|
5
|
+
* @param entry - Exclusion fields to validate or match
|
|
6
|
+
* @param finding - Normalized provider advisory
|
|
7
|
+
* @param copies - Resolved lockfile copies with real package identities
|
|
8
|
+
* @returns The validated result described above
|
|
9
|
+
*/
|
|
10
|
+
function matchExclusion(entry, finding, copies) {
|
|
11
|
+
if (entry.package !== undefined && entry.package !== finding.name) {
|
|
12
|
+
return {
|
|
13
|
+
passed: false,
|
|
14
|
+
messages: [
|
|
15
|
+
`${finding.ids[0]}: package ${finding.name} is outside exclusion package ${entry.package}`,
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (entry.paths === undefined && entry.versions === undefined)
|
|
20
|
+
return { passed: true, messages: [] };
|
|
21
|
+
if (!finding.range || validRange(finding.range) === null) {
|
|
22
|
+
throw new Error(`${finding.ids[0]}: cannot determine vulnerable versions for scoped exclusion`);
|
|
23
|
+
}
|
|
24
|
+
const affected = copies.filter(copy => copy.name === finding.name &&
|
|
25
|
+
satisfies(copy.version, finding.range ?? "", { includePrerelease: true }));
|
|
26
|
+
if (!affected.length)
|
|
27
|
+
throw new Error(`${finding.ids[0]}: no resolved vulnerable copies found for ${finding.name}; scope cannot be established`);
|
|
28
|
+
const outside = affected.filter(copy => (entry.paths !== undefined && !entry.paths.includes(copy.path)) ||
|
|
29
|
+
(entry.versions !== undefined &&
|
|
30
|
+
!satisfies(copy.version, entry.versions, { includePrerelease: true })));
|
|
31
|
+
const outsidePaths = outside
|
|
32
|
+
.map(copy => `${copy.path} (${copy.name}@${copy.version})`)
|
|
33
|
+
.join(", ");
|
|
34
|
+
return {
|
|
35
|
+
passed: outside.length === 0,
|
|
36
|
+
messages: outside.length
|
|
37
|
+
? [
|
|
38
|
+
`${finding.ids[0]}: vulnerable paths outside exclusion: ${outsidePaths}`,
|
|
39
|
+
]
|
|
40
|
+
: [
|
|
41
|
+
`excluded ${finding.ids[0]} for ${affected.map(copy => copy.path).join(", ")} (${entry.reason ?? "no reason recorded"})`,
|
|
42
|
+
],
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Choose which exclusions may decide a finding.
|
|
47
|
+
*
|
|
48
|
+
* A paths/versions entry records that someone reviewed particular copies. An
|
|
49
|
+
* advisory-wide entry for the same advisory and package — typically a managed,
|
|
50
|
+
* shared decision — must not quietly accept the copies that review rejected,
|
|
51
|
+
* so once a scoped entry applies to this package only scoped entries decide.
|
|
52
|
+
* A scoped entry for a DIFFERENT package says nothing about this one.
|
|
53
|
+
* @param candidates - Active exclusions whose id or CVE names the finding
|
|
54
|
+
* @param finding - Normalized provider advisory
|
|
55
|
+
* @returns The entries that decide, and the wide ones set aside
|
|
56
|
+
*/
|
|
57
|
+
function narrowestCandidates(candidates, finding) {
|
|
58
|
+
const samePackage = (entry) => entry.package === undefined || entry.package === finding.name;
|
|
59
|
+
const scoped = candidates.filter(entry => samePackage(entry) && requiresLockfileScope(entry));
|
|
60
|
+
if (!scoped.length)
|
|
61
|
+
return { applied: candidates, shadowed: [] };
|
|
62
|
+
return {
|
|
63
|
+
applied: candidates.filter(entry => requiresLockfileScope(entry)),
|
|
64
|
+
shadowed: candidates.filter(entry => samePackage(entry) && !requiresLockfileScope(entry)),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Evaluate every finding; an unmatched finding remains a finding.
|
|
69
|
+
* @param findings - All normalized high and critical advisories
|
|
70
|
+
* @param exclusions - Validated active exclusions from both decision files
|
|
71
|
+
* @param copies - Resolved lockfile copies with real package identities
|
|
72
|
+
* @returns The validated result described above
|
|
73
|
+
*/
|
|
74
|
+
export function matchAuditFindings(findings, exclusions, copies) {
|
|
75
|
+
const outcomes = findings.map(finding => {
|
|
76
|
+
const candidates = exclusions.filter(entry => entry.active !== false &&
|
|
77
|
+
(finding.ids.includes(entry.id) ||
|
|
78
|
+
(entry.cve !== undefined && finding.ids.includes(entry.cve))));
|
|
79
|
+
const { applied, shadowed } = narrowestCandidates(candidates, finding);
|
|
80
|
+
const notes = shadowed.length
|
|
81
|
+
? [
|
|
82
|
+
`${finding.ids[0]}: advisory-wide exclusion was not applied because a narrower paths/versions exclusion exists for ${finding.name}`,
|
|
83
|
+
]
|
|
84
|
+
: [];
|
|
85
|
+
const matches = applied.map(entry => matchExclusion(entry, finding, copies));
|
|
86
|
+
const accepted = matches.find(match => match.passed);
|
|
87
|
+
if (accepted)
|
|
88
|
+
return { passed: true, messages: [...notes, ...accepted.messages] };
|
|
89
|
+
return {
|
|
90
|
+
passed: false,
|
|
91
|
+
messages: matches.length
|
|
92
|
+
? [...notes, ...matches.flatMap(match => match.messages)]
|
|
93
|
+
: [
|
|
94
|
+
`${finding.ids[0]}: unresolved high/critical advisory for ${finding.name}`,
|
|
95
|
+
],
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
passed: outcomes.every(outcome => outcome.passed),
|
|
100
|
+
messages: outcomes.flatMap(outcome => outcome.messages),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=audit-matcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-matcher.js","sourceRoot":"","sources":["../../src/core/audit-matcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAQ9D;;;;;;GAMG;AACH,SAAS,cAAc,CACrB,KAAqB,EACrB,OAAqB,EACrB,MAA4B;IAE5B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,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,QAAQ;YACV,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtE,OAAO;YACL,MAAM,EAAE,KAAK;YACb,QAAQ,EAAE,OAAO,CAAC,MAAM;gBACtB,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;gBACzD,CAAC,CAAC;oBACE,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,2CAA2C,OAAO,CAAC,IAAI,EAAE;iBAC3E;SACN,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;QACjD,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AuditFinding, AuditManager } from "./audit-types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parse a complete provider report. Empty/error payloads are never clean reports.
|
|
4
|
+
* @param source - Complete provider report or lockfile text
|
|
5
|
+
* @param manager - Package manager whose report and lockfile are evaluated
|
|
6
|
+
* @returns The validated result described above
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseAuditReport(source: string, manager: AuditManager): AuditFinding[];
|
|
9
|
+
//# sourceMappingURL=audit-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-report.d.ts","sourceRoot":"","sources":["../../src/core/audit-report.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiKnE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,GACpB,YAAY,EAAE,CAKhB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { auditRecord } from "./audit-exclusions.js";
|
|
2
|
+
/**
|
|
3
|
+
* Normalize the provider's advisory identity without trusting its display title.
|
|
4
|
+
* @param name - Provider package name for the advisory
|
|
5
|
+
* @param value - Untrusted input value to validate
|
|
6
|
+
* @param severity - Severity inherited from an npm vulnerability record
|
|
7
|
+
* @returns The validated result described above
|
|
8
|
+
*/
|
|
9
|
+
function finding(name, value, severity) {
|
|
10
|
+
if (!auditRecord(value))
|
|
11
|
+
throw new Error("Unknown advisory record");
|
|
12
|
+
const level = value.severity ?? severity;
|
|
13
|
+
if (typeof level !== "string")
|
|
14
|
+
throw new Error("Unknown advisory severity");
|
|
15
|
+
if (!["high", "critical"].includes(level))
|
|
16
|
+
return [];
|
|
17
|
+
const urlId = typeof value.url === "string" ? value.url.split("/").at(-1) : undefined;
|
|
18
|
+
const ids = [
|
|
19
|
+
urlId,
|
|
20
|
+
value.github_advisory_id,
|
|
21
|
+
value.id,
|
|
22
|
+
value.source,
|
|
23
|
+
value.cve,
|
|
24
|
+
...(Array.isArray(value.cves) ? value.cves : []),
|
|
25
|
+
]
|
|
26
|
+
.filter((id) => typeof id === "string" || typeof id === "number")
|
|
27
|
+
.map(String);
|
|
28
|
+
if (!ids.length)
|
|
29
|
+
throw new Error("High/critical advisory has no identity");
|
|
30
|
+
const range = value.vulnerable_versions ?? value.range;
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
ids,
|
|
34
|
+
name: typeof value.name === "string" ? value.name : name,
|
|
35
|
+
severity: level === "critical" ? "critical" : "high",
|
|
36
|
+
...(typeof range === "string" ? { range } : {}),
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Bun's report is an object mapping real package names to advisory arrays.
|
|
42
|
+
* @param value - Untrusted input value to validate
|
|
43
|
+
* @returns The validated result described above
|
|
44
|
+
*/
|
|
45
|
+
function bunFindings(value) {
|
|
46
|
+
if (!auditRecord(value) ||
|
|
47
|
+
Object.values(value).some(entry => !Array.isArray(entry))) {
|
|
48
|
+
throw new Error("Unknown bun audit report shape");
|
|
49
|
+
}
|
|
50
|
+
return Object.entries(value).flatMap(([name, advisories]) => advisories.flatMap(advisory => finding(name, advisory)));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* npm v7+ reports concrete advisories in via objects; strings reference peers.
|
|
54
|
+
* @param value - Untrusted input value to validate
|
|
55
|
+
* @returns The validated result described above
|
|
56
|
+
*/
|
|
57
|
+
function npmFindings(value) {
|
|
58
|
+
if (!auditRecord(value) || !auditRecord(value.vulnerabilities)) {
|
|
59
|
+
throw new Error("Unknown npm audit report shape");
|
|
60
|
+
}
|
|
61
|
+
const result = Object.entries(value.vulnerabilities).flatMap(([name, row]) => {
|
|
62
|
+
if (!auditRecord(row) || !Array.isArray(row.via))
|
|
63
|
+
throw new Error(`Unknown npm advisory for ${name}`);
|
|
64
|
+
return row.via.flatMap((via) => typeof via === "string" ? [] : finding(name, via, row.severity));
|
|
65
|
+
});
|
|
66
|
+
if (!result.length &&
|
|
67
|
+
Object.values(value.vulnerabilities).some(row => auditRecord(row) && ["high", "critical"].includes(String(row.severity)))) {
|
|
68
|
+
throw new Error("npm reported high/critical findings without concrete advisory data");
|
|
69
|
+
}
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Yarn classic emits newline-delimited advisories followed by its summary.
|
|
74
|
+
* @param source - Complete provider report or lockfile text
|
|
75
|
+
* @returns The validated result described above
|
|
76
|
+
*/
|
|
77
|
+
function yarnFindings(source) {
|
|
78
|
+
const lines = source
|
|
79
|
+
.trim()
|
|
80
|
+
.split(/\r?\n/u)
|
|
81
|
+
.map(line => JSON.parse(line));
|
|
82
|
+
const summaries = lines.filter(line => auditRecord(line) && line.type === "auditSummary");
|
|
83
|
+
if (summaries.length !== 1 ||
|
|
84
|
+
lines.some(line => auditRecord(line) && line.type === "error")) {
|
|
85
|
+
throw new Error("Unknown yarn audit report shape (missing auditSummary)");
|
|
86
|
+
}
|
|
87
|
+
const counts = yarnSummaryCounts(summaries[0]);
|
|
88
|
+
const result = lines.flatMap(line => {
|
|
89
|
+
if (!auditRecord(line) || line.type !== "auditAdvisory")
|
|
90
|
+
return [];
|
|
91
|
+
if (!auditRecord(line.data) || !auditRecord(line.data.advisory))
|
|
92
|
+
throw new Error("Unknown yarn advisory data");
|
|
93
|
+
const advisory = line.data.advisory;
|
|
94
|
+
return finding(typeof advisory.module_name === "string" ? advisory.module_name : "", advisory);
|
|
95
|
+
});
|
|
96
|
+
const missing = ["high", "critical"].filter(level => counts[level] > 0 && !result.some(advisory => advisory.severity === level));
|
|
97
|
+
if (missing.length > 0) {
|
|
98
|
+
throw new Error(`Yarn reported high/critical findings without concrete advisory data for ${missing.join(", ")}; nothing was audited completely`);
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Validate the provider's summary before treating an advisory-free stream as clean.
|
|
104
|
+
* @param value - The single Yarn summary record
|
|
105
|
+
* @returns Validated occurrence counts for each governed severity
|
|
106
|
+
*/
|
|
107
|
+
function yarnSummaryCounts(value) {
|
|
108
|
+
const data = auditRecord(value) ? value.data : undefined;
|
|
109
|
+
const counts = auditRecord(data) ? data.vulnerabilities : undefined;
|
|
110
|
+
if (!auditRecord(counts))
|
|
111
|
+
throw new Error("Unknown Yarn audit summary vulnerability counts");
|
|
112
|
+
const levels = [counts.high, counts.critical];
|
|
113
|
+
if (levels.some(count => typeof count !== "number" || !Number.isSafeInteger(count) || count < 0)) {
|
|
114
|
+
throw new Error("Unknown Yarn audit summary high/critical counts");
|
|
115
|
+
}
|
|
116
|
+
return { high: counts.high, critical: counts.critical };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Parse a complete provider report. Empty/error payloads are never clean reports.
|
|
120
|
+
* @param source - Complete provider report or lockfile text
|
|
121
|
+
* @param manager - Package manager whose report and lockfile are evaluated
|
|
122
|
+
* @returns The validated result described above
|
|
123
|
+
*/
|
|
124
|
+
export function parseAuditReport(source, manager) {
|
|
125
|
+
if (!source.trim())
|
|
126
|
+
throw new Error(`${manager} audit produced no output`);
|
|
127
|
+
if (manager === "yarn")
|
|
128
|
+
return yarnFindings(source);
|
|
129
|
+
const parsed = JSON.parse(source);
|
|
130
|
+
return manager === "bun" ? bunFindings(parsed) : npmFindings(parsed);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=audit-report.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-report.js","sourceRoot":"","sources":["../../src/core/audit-report.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD;;;;;;GAMG;AACH,SAAS,OAAO,CACd,IAAY,EACZ,KAAc,EACd,QAAkB;IAElB,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACpE,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,IAAI,QAAQ,CAAC;IACzC,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IAC5E,IAAI,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IACrD,MAAM,KAAK,GACT,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CA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,CAAC,iDAAiD,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAkB,EAAE,CAAC;AAC9E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,MAAc,EACd,OAAqB;IAErB,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,OAAO,2BAA2B,CAAC,CAAC;IAC3E,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;IACpD,MAAM,MAAM,GAAY,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3C,OAAO,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The package managers whose production audits Lisa understands. */
|
|
2
|
+
export type AuditManager = "bun" | "npm" | "yarn";
|
|
3
|
+
/** An exclusion's optional scope is conjunctive, never advisory-wide fallback. */
|
|
4
|
+
export interface AuditExclusion {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly cve?: string;
|
|
7
|
+
readonly package?: string;
|
|
8
|
+
readonly versions?: string;
|
|
9
|
+
readonly paths?: readonly string[];
|
|
10
|
+
readonly reason?: string;
|
|
11
|
+
readonly active?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/** One resolved copy, identified by the lockfile key rather than basename. */
|
|
14
|
+
export interface AuditCopy {
|
|
15
|
+
readonly path: string;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
readonly version: string;
|
|
18
|
+
}
|
|
19
|
+
/** A normalized high/critical advisory from a package manager's own report. */
|
|
20
|
+
export interface AuditFinding {
|
|
21
|
+
readonly ids: readonly string[];
|
|
22
|
+
readonly name: string;
|
|
23
|
+
readonly severity: "high" | "critical";
|
|
24
|
+
readonly range?: string;
|
|
25
|
+
}
|
|
26
|
+
/** A determinate audit verdict and the operator-facing explanation. */
|
|
27
|
+
export interface AuditVerdict {
|
|
28
|
+
readonly passed: boolean;
|
|
29
|
+
readonly messages: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=audit-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-types.d.ts","sourceRoot":"","sources":["../../src/core/audit-types.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,KAAK,GAAG,MAAM,CAAC;AAElD,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,8EAA8E;AAC9E,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,+EAA+E;AAC/E,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IACvC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,uEAAuE;AACvE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC"}
|