cve-lite-cli 1.24.0 → 1.26.0-beta.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.
Files changed (77) hide show
  1. package/README.md +83 -2
  2. package/assets/OWASP_Logo_Black_TM.png +0 -0
  3. package/assets/logo-with-title-removebg-preview.png +0 -0
  4. package/dist/advisory/local-db.js +7 -1
  5. package/dist/advisory/osv-advisory-source.js +2 -1
  6. package/dist/audit-log/events.js +3 -0
  7. package/dist/audit-log/handle.js +20 -0
  8. package/dist/audit-log/index.js +16 -0
  9. package/dist/audit-log/ndjson-writer.js +28 -0
  10. package/dist/cli/args.js +75 -0
  11. package/dist/cli/fix-overrides-hook.js +64 -0
  12. package/dist/cli/help.js +24 -1
  13. package/dist/cli/overrides.js +67 -0
  14. package/dist/cli/validate.js +9 -1
  15. package/dist/index.js +310 -21
  16. package/dist/osv/cache.js +28 -4
  17. package/dist/output/formatters.js +22 -18
  18. package/dist/output/html-reporter.js +37 -8
  19. package/dist/output/logos.js +18 -0
  20. package/dist/output/multi-folder-html-reporter.js +3 -4
  21. package/dist/output/override-findings-html.js +63 -0
  22. package/dist/output/override-findings-json.js +3 -0
  23. package/dist/output/override-findings-sarif.js +52 -0
  24. package/dist/output/override-findings-terminal.js +106 -0
  25. package/dist/output/printers.js +66 -23
  26. package/dist/output/sarif.js +77 -8
  27. package/dist/output/write-outputs.js +7 -3
  28. package/dist/overrides/api.js +79 -0
  29. package/dist/overrides/composite.js +23 -0
  30. package/dist/overrides/context-builder.js +150 -0
  31. package/dist/overrides/context.js +3 -0
  32. package/dist/overrides/detectors/index.js +23 -0
  33. package/dist/overrides/detectors/oa001-orphaned-target.js +36 -0
  34. package/dist/overrides/detectors/oa002-floating-tag.js +40 -0
  35. package/dist/overrides/detectors/oa003-wrong-section.js +48 -0
  36. package/dist/overrides/detectors/oa004-surpassed-pin.js +49 -0
  37. package/dist/overrides/detectors/oa005-nested-ineffective.js +128 -0
  38. package/dist/overrides/detectors/oa006-coupled-platform-binary.js +170 -0
  39. package/dist/overrides/detectors/oa007-frozen-latest.js +69 -0
  40. package/dist/overrides/detectors/oa008-materialized.js +75 -0
  41. package/dist/overrides/detectors/platform-binary.js +37 -0
  42. package/dist/overrides/fixer.js +199 -0
  43. package/dist/overrides/index.js +5 -0
  44. package/dist/overrides/parsing/installed-tree.js +164 -0
  45. package/dist/overrides/parsing/json-pointer.js +8 -0
  46. package/dist/overrides/parsing/node-modules.js +19 -0
  47. package/dist/overrides/parsing/package-json.js +139 -0
  48. package/dist/overrides/parsing/registry.js +66 -0
  49. package/dist/overrides/types.js +2 -0
  50. package/dist/parsers/pnpm-lock.js +46 -3
  51. package/dist/parsers/yarn-lock.js +2 -2
  52. package/dist/remediation/fix-commands.js +59 -5
  53. package/dist/remediation/npm-registry.js +55 -43
  54. package/dist/remediation/npm-transitive-resolution.js +2 -2
  55. package/dist/remediation/transitive-chain-resolver.js +100 -0
  56. package/dist/scan/multi-folder-scan.js +37 -1
  57. package/dist/scanner.js +122 -46
  58. package/dist/types.js +13 -1
  59. package/dist/utils/baseline.js +16 -0
  60. package/dist/utils/create-pr.js +19 -4
  61. package/dist/utils/fix-runner.js +6 -0
  62. package/dist/utils/package-json.js +21 -0
  63. package/dist/utils/severity.js +16 -0
  64. package/dist/utils/string.js +34 -0
  65. package/dist/utils/validate-url.js +223 -0
  66. package/dist/utils/version.js +135 -2
  67. package/package.json +8 -2
  68. package/dist/learn/keypress.js +0 -50
  69. package/dist/learn/runner.js +0 -96
  70. package/dist/learn/scenario.js +0 -47
  71. package/dist/learn/session.js +0 -36
  72. package/dist/learn/types.js +0 -1
  73. package/dist/llm/client.js +0 -40
  74. package/dist/llm/config.js +0 -48
  75. package/dist/llm/explainer.js +0 -31
  76. package/dist/output/logo-base64.js +0 -1
  77. package/dist/output/owasp-logo-base64.js +0 -1
@@ -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
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Heuristic: does this package name look like a platform-specific native binary?
3
+ *
4
+ * Used by OA006 to distinguish the genuinely-coupled case (override fights an
5
+ * exact-pinned parent that ships a native binary, like @esbuild/linux-x64)
6
+ * from the range-bumps-exact case (override on postcss against next's
7
+ * exact pin - risky but commonly intentional and usually works).
8
+ *
9
+ * Hits:
10
+ * @esbuild/linux-x64
11
+ * @next/swc-linux-x64-gnu
12
+ * @rollup/rollup-linux-x64-musl
13
+ * @swc/core-linux-x64-gnu
14
+ * @biomejs/cli-linux-x64
15
+ * @img/sharp-linux-x64
16
+ * @parcel/watcher-linux-x64-glibc
17
+ * @oxc-project/runtime-linux-x64-musl
18
+ * lightningcss-linux-x64-musl
19
+ * sharp-linux-x64
20
+ * esbuild-linux-x64
21
+ *
22
+ * Misses (correctly - these aren't platform binaries):
23
+ * postcss, react, next, esbuild (the JS parent itself), @scope/anything-not-platform
24
+ */
25
+ export function looksLikePlatformBinary(name) {
26
+ return PLATFORM_TOKEN_RE.test(name);
27
+ }
28
+ /**
29
+ * Matches a platform/OS token that appears as its own segment in the name:
30
+ * - at the start (e.g. "linux-x64")
31
+ * - after a slash (e.g. "@esbuild/linux-x64")
32
+ * - after a hyphen (e.g. "sharp-linux-x64", "swc-linux-x64-gnu")
33
+ *
34
+ * Followed by another segment boundary (slash, hyphen, underscore, end-of-string).
35
+ * Anchoring to segment boundaries avoids false positives like "android-base-utils".
36
+ */
37
+ const PLATFORM_TOKEN_RE = /(?:^|[-/])(linux|darwin|win32|windows|wasi|freebsd|openbsd|netbsd|sunos|android|cygwin)(?:[-/_]|$)/i;