cve-lite-cli 1.24.0 → 1.25.0
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 +56 -0
- package/dist/audit-log/events.js +3 -0
- package/dist/audit-log/handle.js +20 -0
- package/dist/audit-log/index.js +16 -0
- package/dist/audit-log/ndjson-writer.js +28 -0
- package/dist/cli/args.js +71 -0
- package/dist/cli/fix-overrides-hook.js +64 -0
- package/dist/cli/help.js +22 -0
- package/dist/cli/overrides.js +67 -0
- package/dist/index.js +270 -12
- package/dist/osv/cache.js +23 -3
- package/dist/output/formatters.js +23 -4
- package/dist/output/html-reporter.js +34 -4
- package/dist/output/override-findings-html.js +57 -0
- package/dist/output/override-findings-json.js +3 -0
- package/dist/output/override-findings-sarif.js +52 -0
- package/dist/output/override-findings-terminal.js +37 -0
- package/dist/output/printers.js +25 -8
- package/dist/output/sarif.js +77 -8
- package/dist/output/write-outputs.js +7 -3
- package/dist/overrides/api.js +79 -0
- package/dist/overrides/composite.js +23 -0
- package/dist/overrides/context-builder.js +150 -0
- package/dist/overrides/context.js +3 -0
- package/dist/overrides/detectors/index.js +23 -0
- package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
- package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
- package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
- package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
- package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
- package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
- package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
- package/dist/overrides/detectors/oa008-materialized.js +75 -0
- package/dist/overrides/detectors/platform-binary.js +37 -0
- package/dist/overrides/fixer.js +199 -0
- package/dist/overrides/index.js +5 -0
- package/dist/overrides/parsing/installed-tree.js +164 -0
- package/dist/overrides/parsing/json-pointer.js +8 -0
- package/dist/overrides/parsing/node-modules.js +19 -0
- package/dist/overrides/parsing/package-json.js +139 -0
- package/dist/overrides/parsing/registry.js +66 -0
- package/dist/overrides/types.js +2 -0
- package/dist/parsers/yarn-lock.js +2 -2
- package/dist/remediation/fix-commands.js +59 -5
- package/dist/remediation/npm-registry.js +30 -0
- package/dist/remediation/npm-transitive-resolution.js +2 -2
- package/dist/remediation/transitive-chain-resolver.js +100 -0
- package/dist/scan/multi-folder-scan.js +26 -0
- package/dist/scanner.js +61 -5
- package/dist/types.js +13 -1
- package/dist/utils/baseline.js +16 -0
- package/dist/utils/create-pr.js +19 -4
- package/dist/utils/string.js +34 -0
- package/dist/utils/version.js +115 -0
- package/package.json +3 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { detect as detectOA001 } from "./oa001-orphaned-target.js";
|
|
2
|
+
import { detect as detectOA002 } from "./oa002-floating-tag.js";
|
|
3
|
+
import { detect as detectOA003 } from "./oa003-wrong-section.js";
|
|
4
|
+
import { detect as detectOA004 } from "./oa004-surpassed-pin.js";
|
|
5
|
+
import { detect as detectOA005 } from "./oa005-nested-ineffective.js";
|
|
6
|
+
import { detect as detectOA006 } from "./oa006-coupled-platform-binary.js";
|
|
7
|
+
import { detect as detectOA007 } from "./oa007-frozen-latest.js";
|
|
8
|
+
import { detect as detectOA008 } from "./oa008-materialized.js";
|
|
9
|
+
export const ALL_DETECTORS = [
|
|
10
|
+
{ ruleId: "OA001", detect: detectOA001 },
|
|
11
|
+
{ ruleId: "OA002", detect: detectOA002 },
|
|
12
|
+
{ ruleId: "OA003", detect: detectOA003 },
|
|
13
|
+
{ ruleId: "OA004", detect: detectOA004 },
|
|
14
|
+
{ ruleId: "OA005", detect: detectOA005 },
|
|
15
|
+
{ ruleId: "OA006", detect: detectOA006 },
|
|
16
|
+
{ ruleId: "OA007", detect: detectOA007 },
|
|
17
|
+
{ ruleId: "OA008", detect: detectOA008 },
|
|
18
|
+
];
|
|
19
|
+
/** Verify subset - just OA001 and OA008 - for the post-fix verify path. */
|
|
20
|
+
export const VERIFY_DETECTORS = [
|
|
21
|
+
{ ruleId: "OA001", detect: detectOA001 },
|
|
22
|
+
{ ruleId: "OA008", detect: detectOA008 },
|
|
23
|
+
];
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
const RULE_ID = "OA001";
|
|
3
|
+
export function detect(ctx) {
|
|
4
|
+
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
5
|
+
return [];
|
|
6
|
+
if (ctx.lockfilePackageNames.size === 0)
|
|
7
|
+
return [];
|
|
8
|
+
const findings = [];
|
|
9
|
+
for (const entry of ctx.overrideEntries) {
|
|
10
|
+
// pnpm selective `parent>child` keys are nested overrides, not simple
|
|
11
|
+
// orphan candidates. OA005 owns the "is this nested override sensible"
|
|
12
|
+
// question; OA001 stays out of pnpm nested syntax (see #14/#15).
|
|
13
|
+
if (entry.parentScope !== undefined)
|
|
14
|
+
continue;
|
|
15
|
+
if (ctx.lockfilePackageNames.has(entry.packageName))
|
|
16
|
+
continue;
|
|
17
|
+
findings.push({
|
|
18
|
+
ruleId: RULE_ID,
|
|
19
|
+
severity: "high",
|
|
20
|
+
package: { name: entry.packageName },
|
|
21
|
+
location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
|
|
22
|
+
message: "Override target not in resolved tree",
|
|
23
|
+
details: `${entry.packageName} is declared in ${entry.container} but no package depends on it. ` +
|
|
24
|
+
`The override has no effect.`,
|
|
25
|
+
fix: {
|
|
26
|
+
type: "rfc6902",
|
|
27
|
+
patch: [{ op: "remove", path: jsonPointer(entry.path) }],
|
|
28
|
+
runnableCommand: `cve-lite overrides --fix --rule OA001`,
|
|
29
|
+
},
|
|
30
|
+
references: [
|
|
31
|
+
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA001.md",
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return findings;
|
|
36
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
import { isValidRange } from "../../utils/version.js";
|
|
3
|
+
const RULE_ID = "OA002";
|
|
4
|
+
const FLOATING = new Set(['latest', 'next', '*', 'x', '']);
|
|
5
|
+
export function detect(ctx) {
|
|
6
|
+
if (ctx.skippedDetectors.some(s => s.ruleId === RULE_ID))
|
|
7
|
+
return [];
|
|
8
|
+
const findings = [];
|
|
9
|
+
for (const entry of ctx.overrideEntries) {
|
|
10
|
+
if (typeof entry.value !== 'string')
|
|
11
|
+
continue; // OA005 handles nested objects
|
|
12
|
+
const v = entry.value.trim();
|
|
13
|
+
if (v.startsWith('workspace:') || v.startsWith('file:') || v.startsWith('link:') || v.startsWith('npm:'))
|
|
14
|
+
continue;
|
|
15
|
+
const isFloating = FLOATING.has(v.toLowerCase());
|
|
16
|
+
const isInvalidRange = !isFloating && !isValidRange(v);
|
|
17
|
+
if (!isFloating && !isInvalidRange)
|
|
18
|
+
continue;
|
|
19
|
+
const installed = ctx.installedVersions.get(entry.packageName);
|
|
20
|
+
const floor = installed ? `>=${installed}` : null;
|
|
21
|
+
const finding = {
|
|
22
|
+
ruleId: RULE_ID,
|
|
23
|
+
severity: 'medium',
|
|
24
|
+
package: { name: entry.packageName },
|
|
25
|
+
location: { file: 'package.json', jsonPath: jsonPointer(entry.path) },
|
|
26
|
+
message: 'Override pinned to floating tag',
|
|
27
|
+
details: `${entry.packageName} is pinned to "${v}" - every install may re-resolve the version, defeating the override.`,
|
|
28
|
+
references: ['https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA002.md'],
|
|
29
|
+
};
|
|
30
|
+
if (floor) {
|
|
31
|
+
finding.fix = {
|
|
32
|
+
type: 'rfc6902',
|
|
33
|
+
patch: [{ op: 'replace', path: jsonPointer(entry.path), value: floor }],
|
|
34
|
+
runnableCommand: `cve-lite overrides --fix --rule OA002`,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
findings.push(finding);
|
|
38
|
+
}
|
|
39
|
+
return findings;
|
|
40
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
const RULE_ID = "OA003";
|
|
3
|
+
const EXPECTED_CONTAINER = {
|
|
4
|
+
npm: "overrides",
|
|
5
|
+
pnpm: "pnpm.overrides",
|
|
6
|
+
yarn: "resolutions",
|
|
7
|
+
bun: "overrides",
|
|
8
|
+
};
|
|
9
|
+
const EXPECTED_PATH_PREFIX = {
|
|
10
|
+
npm: ["overrides"],
|
|
11
|
+
pnpm: ["pnpm", "overrides"],
|
|
12
|
+
yarn: ["resolutions"],
|
|
13
|
+
bun: ["overrides"],
|
|
14
|
+
};
|
|
15
|
+
export function detect(ctx) {
|
|
16
|
+
const expected = EXPECTED_CONTAINER[ctx.packageManager];
|
|
17
|
+
const expectedPath = EXPECTED_PATH_PREFIX[ctx.packageManager];
|
|
18
|
+
if (!expected || !expectedPath)
|
|
19
|
+
return [];
|
|
20
|
+
const findings = [];
|
|
21
|
+
for (const entry of ctx.overrideEntries) {
|
|
22
|
+
if (entry.container === expected)
|
|
23
|
+
continue;
|
|
24
|
+
const destination = [...expectedPath, entry.key];
|
|
25
|
+
findings.push({
|
|
26
|
+
ruleId: RULE_ID,
|
|
27
|
+
severity: "high",
|
|
28
|
+
package: { name: entry.packageName },
|
|
29
|
+
location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
|
|
30
|
+
message: "Override declared in wrong package-manager section",
|
|
31
|
+
details: `Project uses ${ctx.packageManager}, but override "${entry.key}" lives in ${entry.container}. ` +
|
|
32
|
+
`${ctx.packageManager} silently ignores this section - the override has no effect.`,
|
|
33
|
+
fix: {
|
|
34
|
+
type: "rfc6902",
|
|
35
|
+
patch: [{
|
|
36
|
+
op: "move",
|
|
37
|
+
from: jsonPointer(entry.path),
|
|
38
|
+
path: jsonPointer(destination),
|
|
39
|
+
}],
|
|
40
|
+
runnableCommand: `cve-lite overrides --fix --rule OA003`,
|
|
41
|
+
},
|
|
42
|
+
references: [
|
|
43
|
+
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA003.md",
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
return findings;
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
import { compareVersions, looksLikeVersion, majorVersion } from "../../utils/version.js";
|
|
3
|
+
const RULE_ID = "OA004";
|
|
4
|
+
export function detect(ctx) {
|
|
5
|
+
if (ctx.skippedDetectors.some((s) => s.ruleId === RULE_ID))
|
|
6
|
+
return [];
|
|
7
|
+
const findings = [];
|
|
8
|
+
for (const entry of ctx.overrideEntries) {
|
|
9
|
+
if (typeof entry.value !== "string")
|
|
10
|
+
continue; // OA005 handles nested
|
|
11
|
+
const pin = entry.value.trim();
|
|
12
|
+
// Concrete version only - not a range, not a floating tag.
|
|
13
|
+
if (!looksLikeVersion(pin))
|
|
14
|
+
continue;
|
|
15
|
+
const installed = ctx.installedVersions.get(entry.packageName);
|
|
16
|
+
if (!installed)
|
|
17
|
+
continue;
|
|
18
|
+
if (!looksLikeVersion(installed))
|
|
19
|
+
continue;
|
|
20
|
+
if (!(compareVersions(installed, pin) > 0))
|
|
21
|
+
continue;
|
|
22
|
+
// Safety heuristic for v1: same major -> safe remove; otherwise suggest.
|
|
23
|
+
// Fuller "parent depends on >=pin" check deferred (Spec 12.1).
|
|
24
|
+
const installedMajor = majorVersion(installed);
|
|
25
|
+
const pinMajor = majorVersion(pin);
|
|
26
|
+
const safe = installedMajor !== null && pinMajor !== null && installedMajor === pinMajor;
|
|
27
|
+
const finding = {
|
|
28
|
+
ruleId: RULE_ID,
|
|
29
|
+
severity: "low",
|
|
30
|
+
package: { name: entry.packageName },
|
|
31
|
+
location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
|
|
32
|
+
message: "Installed version surpasses concrete pin",
|
|
33
|
+
details: `${entry.packageName} is pinned to ${pin}; node_modules has ${installed}. ` +
|
|
34
|
+
`The override no longer raises the floor.`,
|
|
35
|
+
references: [
|
|
36
|
+
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA004.md",
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
if (safe) {
|
|
40
|
+
finding.fix = {
|
|
41
|
+
type: "rfc6902",
|
|
42
|
+
patch: [{ op: "remove", path: jsonPointer(entry.path) }],
|
|
43
|
+
runnableCommand: `cve-lite overrides --fix --rule OA004`,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
findings.push(finding);
|
|
47
|
+
}
|
|
48
|
+
return findings;
|
|
49
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
2
|
+
import { readInstalledManifest } from "../parsing/node-modules.js";
|
|
3
|
+
import { satisfiesRange, isValidRange } from "../../utils/version.js";
|
|
4
|
+
const RULE_ID = "OA005";
|
|
5
|
+
/**
|
|
6
|
+
* OA005-NESTED-INEFFECTIVE - nested overrides in two shapes:
|
|
7
|
+
* - npm object form `{ parent: { inner: ver } }`
|
|
8
|
+
* - pnpm flat-string `"parent>inner": ver`
|
|
9
|
+
* Single detector, five sub-codes routed in priority order:
|
|
10
|
+
* .a (critical) - nested form ineffective for this pm (silently ignored)
|
|
11
|
+
* .b (high) - outer parent not in resolved tree
|
|
12
|
+
* .c (high) - outer in tree, but inner not declared in parent's deps
|
|
13
|
+
* .d (medium) - inner installed elsewhere at version not satisfying pin
|
|
14
|
+
* .e (info) - valid + effective, stylistic suggestion to flatten
|
|
15
|
+
*
|
|
16
|
+
* The `.a` ineffectiveness test depends on the shape:
|
|
17
|
+
* - object form is npm-specific, so it is ineffective in any non-npm project.
|
|
18
|
+
* - flat-string `parent>child` is pnpm-specific, so it is ineffective in any
|
|
19
|
+
* non-pnpm project (npm/yarn/bun do not honour `>` selective syntax).
|
|
20
|
+
*/
|
|
21
|
+
export function detect(ctx) {
|
|
22
|
+
const lookup = ctx._testManifestLookup
|
|
23
|
+
?? ((name) => readInstalledManifest(ctx.projectPath, name));
|
|
24
|
+
const findings = [];
|
|
25
|
+
for (const entry of ctx.overrideEntries) {
|
|
26
|
+
if (typeof entry.value !== "string") {
|
|
27
|
+
// npm object form: each nested-object entry yields one finding per inner key.
|
|
28
|
+
for (const [innerKey, innerValue] of Object.entries(entry.value)) {
|
|
29
|
+
if (typeof innerValue !== "string")
|
|
30
|
+
continue;
|
|
31
|
+
const finding = classify({
|
|
32
|
+
ctx,
|
|
33
|
+
outerKey: entry.key,
|
|
34
|
+
innerKey,
|
|
35
|
+
innerValue,
|
|
36
|
+
entryPath: entry.path,
|
|
37
|
+
lookup,
|
|
38
|
+
form: "object",
|
|
39
|
+
});
|
|
40
|
+
if (finding)
|
|
41
|
+
findings.push(finding);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else if (entry.parentScope !== undefined) {
|
|
45
|
+
// pnpm flat-string form: `"parent>child": ver`. The parser put the child
|
|
46
|
+
// in packageName and the parent in parentScope.
|
|
47
|
+
const finding = classify({
|
|
48
|
+
ctx,
|
|
49
|
+
outerKey: entry.parentScope,
|
|
50
|
+
innerKey: entry.packageName,
|
|
51
|
+
innerValue: entry.value,
|
|
52
|
+
entryPath: entry.path,
|
|
53
|
+
lookup,
|
|
54
|
+
form: "flat-pnpm",
|
|
55
|
+
});
|
|
56
|
+
if (finding)
|
|
57
|
+
findings.push(finding);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return findings;
|
|
61
|
+
}
|
|
62
|
+
function classify(args) {
|
|
63
|
+
const { ctx, outerKey, innerKey, innerValue, entryPath, lookup, form } = args;
|
|
64
|
+
const findingBase = (subId, severity, message, details, action) => ({
|
|
65
|
+
ruleId: RULE_ID,
|
|
66
|
+
subRuleId: subId,
|
|
67
|
+
severity,
|
|
68
|
+
package: { name: outerKey },
|
|
69
|
+
location: { file: "package.json", jsonPath: jsonPointer(entryPath) },
|
|
70
|
+
message,
|
|
71
|
+
details,
|
|
72
|
+
...(action === "remove"
|
|
73
|
+
? {
|
|
74
|
+
fix: {
|
|
75
|
+
type: "rfc6902",
|
|
76
|
+
patch: [{ op: "remove", path: jsonPointer(entryPath) }],
|
|
77
|
+
runnableCommand: `cve-lite overrides --fix --rule OA005`,
|
|
78
|
+
},
|
|
79
|
+
}
|
|
80
|
+
: {}),
|
|
81
|
+
references: [
|
|
82
|
+
"https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA005.md",
|
|
83
|
+
],
|
|
84
|
+
});
|
|
85
|
+
// .a - nested form ineffective for this package manager: silently ignored.
|
|
86
|
+
// object form -> npm-specific, ineffective in any non-npm project.
|
|
87
|
+
// flat-pnpm -> pnpm-specific `parent>child`, ineffective in any non-pnpm
|
|
88
|
+
// project (npm/yarn/bun do not honour `>` selective syntax).
|
|
89
|
+
const ineffectiveForm = form === "object" ? ctx.packageManager !== "npm" : ctx.packageManager !== "pnpm";
|
|
90
|
+
if (ineffectiveForm) {
|
|
91
|
+
const formDesc = form === "object"
|
|
92
|
+
? `${ctx.packageManager} does not honour the npm-specific nested-object override form. The pin "${outerKey}.${innerKey}" = "${innerValue}" has no effect.`
|
|
93
|
+
: `${ctx.packageManager} does not honour the pnpm-specific "parent>child" selective override form. The pin "${outerKey}>${innerKey}" = "${innerValue}" has no effect.`;
|
|
94
|
+
return findingBase("OA005.a", "critical", "Nested override ineffective for this package manager (silently ignored)", formDesc, "remove");
|
|
95
|
+
}
|
|
96
|
+
// .b - outer parent not in resolved tree.
|
|
97
|
+
if (!ctx.lockfilePackageNames.has(outerKey)) {
|
|
98
|
+
return findingBase("OA005.b", "high", "Nested override outer parent not in resolved tree", `Outer parent ${outerKey} is not in the dependency tree. The nested override "${innerKey}" has no parent to apply to.`, "remove");
|
|
99
|
+
}
|
|
100
|
+
// .c - outer in tree but inner is not declared in parent's manifest deps.
|
|
101
|
+
const parentManifest = lookup(outerKey);
|
|
102
|
+
const declaredAsDep = !!parentManifest &&
|
|
103
|
+
((parentManifest.dependencies && innerKey in parentManifest.dependencies) ||
|
|
104
|
+
(parentManifest.optionalDependencies && innerKey in parentManifest.optionalDependencies) ||
|
|
105
|
+
(parentManifest.peerDependencies && innerKey in parentManifest.peerDependencies));
|
|
106
|
+
if (parentManifest && !declaredAsDep) {
|
|
107
|
+
return findingBase("OA005.c", "high", "Nested override inner dep not declared by parent", `${outerKey} does not declare ${innerKey} as a dependency. The override has no install path to apply to.`, "remove");
|
|
108
|
+
}
|
|
109
|
+
// .d - leaky: same inner installed elsewhere at non-satisfying version.
|
|
110
|
+
const installedInner = ctx.installedVersions.get(innerKey);
|
|
111
|
+
if (installedInner && isValidRange(innerValue)) {
|
|
112
|
+
if (!satisfiesRange(installedInner, innerValue)) {
|
|
113
|
+
return findingBase("OA005.d", "medium", "Nested override leaks: same dep installed elsewhere at non-conforming version", `Override forces ${innerKey} to ${innerValue} only when installed via ${outerKey}. Another tree path installed ${installedInner}, which does not satisfy the pin.`, "suggest");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// .e - npm object form only: valid and effective, flat form would be more durable.
|
|
117
|
+
//
|
|
118
|
+
// For pnpm flat-string selective overrides we deliberately emit NO finding here.
|
|
119
|
+
// Scoping `parent>child` to one parent is the feature, not a smell, so "could be
|
|
120
|
+
// flattened" is both noise and bad advice (flattening changes scoped to global).
|
|
121
|
+
// We only speak when a selective override is PROVEN broken: .b (parent not in the
|
|
122
|
+
// resolved tree) and .c (parent does not declare the child, requires node_modules).
|
|
123
|
+
// When node_modules is absent we cannot run .c/.d, so an unbroken-looking selective
|
|
124
|
+
// override is presumed fine - a hygiene auditor flags proven problems, not maybes.
|
|
125
|
+
if (form === "flat-pnpm")
|
|
126
|
+
return null;
|
|
127
|
+
return findingBase("OA005.e", "low", "Nested override could be flattened to top-level", `Nested override ${outerKey}.${innerKey} is valid and effective. A flat top-level "overrides": { "${innerKey}": "${innerValue}" } would apply across the whole tree.`, "suggest");
|
|
128
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { jsonPointer } from '../parsing/json-pointer.js';
|
|
2
|
+
import { compareVersions, looksLikeVersion, satisfiesRange, isValidRange } from '../../utils/version.js';
|
|
3
|
+
import { looksLikePlatformBinary } from './platform-binary.js';
|
|
4
|
+
const RULE_ID = 'OA006';
|
|
5
|
+
/**
|
|
6
|
+
* OA006 - the override target is a package that one or more INSTALLED parents
|
|
7
|
+
* declare as an exact-version dependency. The override is fighting the parent's
|
|
8
|
+
* pin: even if the user pins the binary to a newer version, npm/pnpm will either
|
|
9
|
+
* emit EOVERRIDE warnings, refuse to dedup, or install both copies (leaving the
|
|
10
|
+
* vulnerable one on disk). The right shape is a parent-level override.
|
|
11
|
+
*
|
|
12
|
+
* Common targets where this bites:
|
|
13
|
+
* - esbuild -> @esbuild/<platform>
|
|
14
|
+
* - @next/swc-* -> next
|
|
15
|
+
* - @rollup/rollup-* -> rollup
|
|
16
|
+
* - @swc/core-* -> @swc/core
|
|
17
|
+
* - sharp prebuilts
|
|
18
|
+
*/
|
|
19
|
+
export function detect(ctx) {
|
|
20
|
+
if (ctx.skippedDetectors.some(s => s.ruleId === RULE_ID))
|
|
21
|
+
return [];
|
|
22
|
+
const findings = [];
|
|
23
|
+
for (const entry of ctx.overrideEntries) {
|
|
24
|
+
if (typeof entry.value !== 'string')
|
|
25
|
+
continue; // OA005 territory
|
|
26
|
+
const pinValue = entry.value.trim();
|
|
27
|
+
const parents = ctx.parentDeclarations.get(entry.packageName) ?? [];
|
|
28
|
+
// Only flag when at least one INSTALLED parent declares this as exact.
|
|
29
|
+
const exactParents = parents.filter(p => p.exactVersion);
|
|
30
|
+
if (exactParents.length === 0)
|
|
31
|
+
continue;
|
|
32
|
+
// If the pin equals every parent's exact version, the override is a no-op
|
|
33
|
+
// (coincides with the parent) - don't flag here. OA001/OA004 may catch the
|
|
34
|
+
// staleness from another angle.
|
|
35
|
+
const allParentsAgree = exactParents.every(p => p.declaredValue === pinValue);
|
|
36
|
+
if (allParentsAgree)
|
|
37
|
+
continue;
|
|
38
|
+
// Consult the materialized tree before firing, like OA008 (issue #37). If the
|
|
39
|
+
// override target is installed at a version that satisfies the override pin, the
|
|
40
|
+
// override demonstrably won resolution on disk - it is effective, not fragile,
|
|
41
|
+
// and the relocate-to-parent fix would be harmful (it force-pins the framework
|
|
42
|
+
// to clear a non-problem). This is the documented "every Next project needs a
|
|
43
|
+
// flat postcss override" pattern. Suppress. The genuine coupling case - parent's
|
|
44
|
+
// exact pin wins, leaving a below-floor copy on disk - is not satisfied here, so
|
|
45
|
+
// it still fires (and OA008 fires in parallel; the composite pass escalates).
|
|
46
|
+
if (overrideWonOnDisk(ctx, entry.packageName, pinValue))
|
|
47
|
+
continue;
|
|
48
|
+
// Pick the most-cited parent to suggest as the override target. Ties broken
|
|
49
|
+
// by first declared version (deterministic across runs).
|
|
50
|
+
const parentChoice = chooseParent(exactParents);
|
|
51
|
+
const suggestedFloor = suggestParentFloor(pinValue, parentChoice);
|
|
52
|
+
// Severity tiers (refined in v0.1.2 per issue #8):
|
|
53
|
+
// - Platform-binary target -> high (binary-coupling failure mode is severe)
|
|
54
|
+
// - Non-platform target -> medium (often works; scanner may escalate
|
|
55
|
+
// to high in post-processing if OA008 also
|
|
56
|
+
// fires for the same target)
|
|
57
|
+
const isPlatform = looksLikePlatformBinary(entry.packageName);
|
|
58
|
+
const severity = isPlatform ? 'high' : 'medium';
|
|
59
|
+
// The override on the binary cannot win against the parent's exact pin, so the
|
|
60
|
+
// durable fix carries the constraint up to the parent. Two shapes:
|
|
61
|
+
// - parent already has an override: repin that existing override to the floor.
|
|
62
|
+
// - parent has no override: relocate - retire the binary override and add a
|
|
63
|
+
// parent DEPENDENCY floor (upgrade the parent), never a new override entry.
|
|
64
|
+
// Both write an inferred floor, so the fix is tier "proposed" (surfaced, not
|
|
65
|
+
// applied by default). See docs/merge/2026-06-08-relocate-op-design.md.
|
|
66
|
+
const existingParentEntry = findExistingOverride(ctx, parentChoice.parentName);
|
|
67
|
+
let patches;
|
|
68
|
+
if (existingParentEntry) {
|
|
69
|
+
patches = [
|
|
70
|
+
{ op: 'remove', path: jsonPointer(entry.path) },
|
|
71
|
+
{ op: 'replace', path: jsonPointer(existingParentEntry.path), value: suggestedFloor },
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
patches = [
|
|
76
|
+
{
|
|
77
|
+
op: 'relocate',
|
|
78
|
+
fromChild: jsonPointer(entry.path),
|
|
79
|
+
toParent: parentChoice.parentName,
|
|
80
|
+
floor: suggestedFloor,
|
|
81
|
+
},
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
const finding = {
|
|
85
|
+
ruleId: RULE_ID,
|
|
86
|
+
severity,
|
|
87
|
+
package: { name: entry.packageName },
|
|
88
|
+
location: { file: 'package.json', jsonPath: jsonPointer(entry.path) },
|
|
89
|
+
message: isPlatform
|
|
90
|
+
? 'Override on platform binary fights an exact-pinned parent'
|
|
91
|
+
: 'Override fights an exact-pinned parent (effect not confirmed on disk)',
|
|
92
|
+
details: `${entry.packageName} is overridden to "${pinValue}", but its installed parent ` +
|
|
93
|
+
`${parentChoice.parentName}@${parentChoice.parentVersion} declares it as exact ` +
|
|
94
|
+
`(${parentChoice.declaredIn}: "${parentChoice.declaredValue}"). ` +
|
|
95
|
+
`No installed copy confirms the override took; if the parent's exact pin wins ` +
|
|
96
|
+
`resolution, npm/pnpm keep that version on disk and the override does nothing. ` +
|
|
97
|
+
`Override the parent instead.`,
|
|
98
|
+
fix: {
|
|
99
|
+
type: 'rfc6902',
|
|
100
|
+
patch: patches,
|
|
101
|
+
runnableCommand: `cve-lite overrides --fix --rule OA006`,
|
|
102
|
+
tier: 'proposed',
|
|
103
|
+
},
|
|
104
|
+
references: ['https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA006.md'],
|
|
105
|
+
};
|
|
106
|
+
findings.push(finding);
|
|
107
|
+
}
|
|
108
|
+
return findings;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* True when the override target has at least one materialized copy and EVERY
|
|
112
|
+
* materialized copy satisfies the override pin - i.e. the override won resolution
|
|
113
|
+
* on disk. Mirrors OA008's materialization check. Returns false when there is no
|
|
114
|
+
* installed evidence (cannot prove the override won) or the pin is not a
|
|
115
|
+
* comparable range/version (floating tags are OA002's territory).
|
|
116
|
+
*/
|
|
117
|
+
function overrideWonOnDisk(ctx, packageName, pinValue) {
|
|
118
|
+
if (!isCheckableFloor(pinValue))
|
|
119
|
+
return false;
|
|
120
|
+
const copies = ctx.installedCopies.get(packageName) ?? [];
|
|
121
|
+
if (copies.length === 0)
|
|
122
|
+
return false;
|
|
123
|
+
return copies.every(c => copySatisfiesPin(c.version, pinValue));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A single installed copy is consistent with the override pin. Unlike OA008 (which
|
|
127
|
+
* treats the pin as a security FLOOR), OA006 asks "did the override take?" - so a
|
|
128
|
+
* concrete pin is a degenerate exact range. If the parent forces a different version
|
|
129
|
+
* (even a higher one), the override did not win and OA006 should still fire.
|
|
130
|
+
*/
|
|
131
|
+
function copySatisfiesPin(version, pinValue) {
|
|
132
|
+
return looksLikeVersion(version) && satisfiesRange(version, pinValue);
|
|
133
|
+
}
|
|
134
|
+
/** The pin is a comparable semver range/version (excludes tags and workspace/file/link). */
|
|
135
|
+
function isCheckableFloor(value) {
|
|
136
|
+
if (value.startsWith('workspace:') || value.startsWith('file:') || value.startsWith('link:'))
|
|
137
|
+
return false;
|
|
138
|
+
return isValidRange(value);
|
|
139
|
+
}
|
|
140
|
+
function chooseParent(parents) {
|
|
141
|
+
// Sort by parent name then by parentVersion (semver-desc when possible) for stability.
|
|
142
|
+
const sorted = [...parents].sort((a, b) => {
|
|
143
|
+
if (a.parentName !== b.parentName)
|
|
144
|
+
return a.parentName.localeCompare(b.parentName);
|
|
145
|
+
if (looksLikeVersion(a.parentVersion) && looksLikeVersion(b.parentVersion)) {
|
|
146
|
+
return compareVersions(b.parentVersion, a.parentVersion);
|
|
147
|
+
}
|
|
148
|
+
return 0;
|
|
149
|
+
});
|
|
150
|
+
return sorted[0];
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Suggest a floor for the parent override. We don't know what the user's
|
|
154
|
+
* "safe" version is; the best guess is the latest parent version present in
|
|
155
|
+
* the installed tree (>=-floor form so the resolver can pick newer too).
|
|
156
|
+
*/
|
|
157
|
+
function suggestParentFloor(_pin, parent) {
|
|
158
|
+
const cleaned = looksLikeVersion(parent.parentVersion) ? parent.parentVersion : null;
|
|
159
|
+
return cleaned ? `>=${cleaned}` : `>=${parent.parentVersion}`;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Build the path where the parent-level override should go, mirroring the
|
|
163
|
+
* container the original binary override lived in.
|
|
164
|
+
* ['overrides', '@esbuild/linux-x64'] -> ['overrides', 'esbuild']
|
|
165
|
+
* ['pnpm', 'overrides', '@esbuild/linux-x64'] -> ['pnpm', 'overrides', 'esbuild']
|
|
166
|
+
*/
|
|
167
|
+
/** Find an existing override entry by package name across all containers. */
|
|
168
|
+
function findExistingOverride(ctx, packageName) {
|
|
169
|
+
return ctx.overrideEntries.find(e => e.packageName === packageName);
|
|
170
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { looksLikeVersion, compareVersions } from "../../utils/version.js";
|
|
2
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
3
|
+
const RULE_ID = "OA007";
|
|
4
|
+
const FLOATING_TAGS = new Set(["latest", "next"]);
|
|
5
|
+
/**
|
|
6
|
+
* OA007 - the override pin is a floating tag (`latest` or `next`) AND the
|
|
7
|
+
* installed version doesn't match what the registry currently advertises for
|
|
8
|
+
* that tag. Indicates the override resolved to a version long ago and has
|
|
9
|
+
* been frozen by the lockfile while the registry has moved on.
|
|
10
|
+
*
|
|
11
|
+
* Requires registry data: skipped when `--check-network` was not passed, when
|
|
12
|
+
* the network call failed, or when the registry has no entry for the package.
|
|
13
|
+
*
|
|
14
|
+
* Note: This detector only consumes ctx.registryDistTags. It does NOT make
|
|
15
|
+
* HTTP calls. The actual registry data is populated by the context builder
|
|
16
|
+
* when checkNetwork: true.
|
|
17
|
+
*/
|
|
18
|
+
export function detect(ctx) {
|
|
19
|
+
if (ctx.skippedDetectors.some(s => s.ruleId === RULE_ID))
|
|
20
|
+
return [];
|
|
21
|
+
// No registry data - caller didn't ask for it or fetch failed. Nothing to
|
|
22
|
+
// report here; absence is signalled via skippedDetectors elsewhere.
|
|
23
|
+
if (ctx.registryDistTags.size === 0)
|
|
24
|
+
return [];
|
|
25
|
+
const findings = [];
|
|
26
|
+
for (const entry of ctx.overrideEntries) {
|
|
27
|
+
if (typeof entry.value !== "string")
|
|
28
|
+
continue;
|
|
29
|
+
const tag = entry.value.trim().toLowerCase();
|
|
30
|
+
if (!FLOATING_TAGS.has(tag))
|
|
31
|
+
continue;
|
|
32
|
+
const installed = ctx.installedVersions.get(entry.packageName);
|
|
33
|
+
if (!installed)
|
|
34
|
+
continue;
|
|
35
|
+
const tags = ctx.registryDistTags.get(entry.packageName);
|
|
36
|
+
if (!tags)
|
|
37
|
+
continue;
|
|
38
|
+
const registryVersion = tags[tag];
|
|
39
|
+
if (!registryVersion)
|
|
40
|
+
continue;
|
|
41
|
+
const installedValid = looksLikeVersion(installed);
|
|
42
|
+
const registryValid = looksLikeVersion(registryVersion);
|
|
43
|
+
if (!installedValid || !registryValid)
|
|
44
|
+
continue;
|
|
45
|
+
if (installed === registryVersion)
|
|
46
|
+
continue;
|
|
47
|
+
// Only flag if registry is *newer* than what's installed - that's the
|
|
48
|
+
// "you're stuck behind the registry" failure mode.
|
|
49
|
+
if (!(compareVersions(registryVersion, installed) > 0))
|
|
50
|
+
continue;
|
|
51
|
+
findings.push({
|
|
52
|
+
ruleId: RULE_ID,
|
|
53
|
+
severity: "low",
|
|
54
|
+
package: { name: entry.packageName },
|
|
55
|
+
location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
|
|
56
|
+
message: "Floating-tag override is frozen behind the registry",
|
|
57
|
+
details: `${entry.packageName} is pinned to "${tag}", which resolved to ${installed} at install ` +
|
|
58
|
+
`time and has been frozen there by the lockfile. The registry currently advertises ` +
|
|
59
|
+
`${tag}=${registryVersion}. Your security-shaped pin is stale.`,
|
|
60
|
+
fix: {
|
|
61
|
+
type: "rfc6902",
|
|
62
|
+
patch: [{ op: "replace", path: jsonPointer(entry.path), value: `>=${registryVersion}` }],
|
|
63
|
+
runnableCommand: `cve-lite overrides --fix --rule OA007`,
|
|
64
|
+
},
|
|
65
|
+
references: ["https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA007.md"],
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return findings;
|
|
69
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { satisfiesRange, coerceVersion, compareVersions, looksLikeVersion, isValidRange } from "../../utils/version.js";
|
|
2
|
+
import { jsonPointer } from "../parsing/json-pointer.js";
|
|
3
|
+
const RULE_ID = "OA008";
|
|
4
|
+
/**
|
|
5
|
+
* OA008 - the override declared a floor (range or exact-version pin) but an
|
|
6
|
+
* installed copy somewhere in the tree is BELOW that floor. Most common cause
|
|
7
|
+
* is a parent declaring an exact-pinned dep that wins over the override
|
|
8
|
+
* (OA006's territory), but it also surfaces stale-lockfile and dedup-failure
|
|
9
|
+
* scenarios. This is the post-install verification rule: "did the floor I
|
|
10
|
+
* asked for actually get applied everywhere?"
|
|
11
|
+
*
|
|
12
|
+
* Considers every installed copy under node_modules, including nested ones.
|
|
13
|
+
* Skips overrides whose value isn't a clean range/version (floating tags are
|
|
14
|
+
* OA002's territory).
|
|
15
|
+
*/
|
|
16
|
+
export function detect(ctx) {
|
|
17
|
+
if (ctx.skippedDetectors.some(s => s.ruleId === RULE_ID))
|
|
18
|
+
return [];
|
|
19
|
+
const findings = [];
|
|
20
|
+
for (const entry of ctx.overrideEntries) {
|
|
21
|
+
if (typeof entry.value !== "string")
|
|
22
|
+
continue;
|
|
23
|
+
const pinValue = entry.value.trim();
|
|
24
|
+
if (!isCheckableFloor(pinValue))
|
|
25
|
+
continue;
|
|
26
|
+
const copies = ctx.installedCopies.get(entry.packageName) ?? [];
|
|
27
|
+
if (copies.length === 0)
|
|
28
|
+
continue;
|
|
29
|
+
const vulnerable = copies.filter(c => {
|
|
30
|
+
const v = looksLikeVersion(c.version);
|
|
31
|
+
if (!v)
|
|
32
|
+
return false;
|
|
33
|
+
// For range pins, check `satisfiesRange`. For exact pins, the floor is the pin itself.
|
|
34
|
+
if (isValidRange(pinValue) && !isConcrete(pinValue)) {
|
|
35
|
+
return !satisfiesRange(c.version, pinValue);
|
|
36
|
+
}
|
|
37
|
+
// Concrete pin: floor IS the pin; below it is vulnerable.
|
|
38
|
+
const floor = coerceVersion(pinValue);
|
|
39
|
+
return floor ? compareVersions(c.version, floor) < 0 : false;
|
|
40
|
+
});
|
|
41
|
+
if (vulnerable.length === 0)
|
|
42
|
+
continue;
|
|
43
|
+
const versions = vulnerable.map(c => c.version);
|
|
44
|
+
const distinct = Array.from(new Set(versions)).sort();
|
|
45
|
+
findings.push({
|
|
46
|
+
ruleId: RULE_ID,
|
|
47
|
+
severity: "critical",
|
|
48
|
+
package: { name: entry.packageName },
|
|
49
|
+
location: { file: "package.json", jsonPath: jsonPointer(entry.path) },
|
|
50
|
+
message: "Override floor not applied - vulnerable copy still on disk",
|
|
51
|
+
details: `Override demands ${entry.packageName} ${pinValue}, but ${vulnerable.length} ` +
|
|
52
|
+
`installed copy${vulnerable.length === 1 ? "" : "ies"} (${distinct.join(", ")}) ` +
|
|
53
|
+
`${vulnerable.length === 1 ? "is" : "are"} below the floor. ` +
|
|
54
|
+
`The override is not effective everywhere - likely a parent declares this dep ` +
|
|
55
|
+
`as exact and wins resolution.`,
|
|
56
|
+
references: ["https://github.com/OWASP/cve-lite-cli/blob/main/docs/rules/OA008.md"],
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return findings;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* True if the pin value is something we can compare against a concrete version:
|
|
63
|
+
* a valid semver range OR a concrete version. Excludes floating tags and
|
|
64
|
+
* workspace/file/link protocols (those are OA002 or out of scope).
|
|
65
|
+
*/
|
|
66
|
+
function isCheckableFloor(value) {
|
|
67
|
+
if (value.startsWith("workspace:") || value.startsWith("file:") || value.startsWith("link:"))
|
|
68
|
+
return false;
|
|
69
|
+
if (!isValidRange(value))
|
|
70
|
+
return false;
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
function isConcrete(value) {
|
|
74
|
+
return looksLikeVersion(value);
|
|
75
|
+
}
|