@preventive/upstream 1.11.0 → 1.12.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/advisories.d.ts +7 -1
- package/package.json +1 -1
- package/src/advisories/index.js +2 -2
- package/src/advisories/osv.js +7 -7
package/advisories.d.ts
CHANGED
|
@@ -44,6 +44,11 @@ export interface AdvisoryOptions {
|
|
|
44
44
|
// Also asks OSV about public npm packages: malware and taken-down
|
|
45
45
|
// releases, which npm's registry has no advisories of.
|
|
46
46
|
osv?: boolean
|
|
47
|
+
// false: OSV's ids as OSV tells them, GitHub's own record of a GHSA read
|
|
48
|
+
// never (raw.githubusercontent.com asked nothing). No row has `related`,
|
|
49
|
+
// and a GHSA OSV joins with another is grouped with it, as its alias, a
|
|
50
|
+
// version of both reported under one. Default true.
|
|
51
|
+
githubAliases?: boolean
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
// One advisory on one package, one row per id, however many sources have it.
|
|
@@ -63,7 +68,8 @@ export interface Advisory {
|
|
|
63
68
|
// Those of other advisories OSV joins with a GHSA, its GitHub record telling
|
|
64
69
|
// them apart: another GHSA, and its CVE, as GHSA-37ch-88jc-xwx2 (of
|
|
65
70
|
// CVE-2026-4867 alone) has GHSA-9wv6-86v2-598j and its CVE-2024-45296.
|
|
66
|
-
// Each is an advisory of its own, which these versions may not be of.
|
|
71
|
+
// Each is an advisory of its own, which these versions may not be of. None
|
|
72
|
+
// with `githubAliases: false`.
|
|
67
73
|
related?: string[]
|
|
68
74
|
title?: string
|
|
69
75
|
// With `details`: its full text, in Markdown.
|
package/package.json
CHANGED
package/src/advisories/index.js
CHANGED
|
@@ -86,7 +86,7 @@ function oneRowPerAdvisory(rows, asked) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
export async function advisories(packages, options = {}) {
|
|
89
|
-
assertArgs('advisories', options, { github: optional(assertClient), repoAdvisories: optional(assertBoolean), details: optional(assertBoolean), osv: optional(assertBoolean), cache: optional(assertCache) })
|
|
89
|
+
assertArgs('advisories', options, { github: optional(assertClient), repoAdvisories: optional(assertBoolean), details: optional(assertBoolean), osv: optional(assertBoolean), githubAliases: optional(assertBoolean), cache: optional(assertCache) })
|
|
90
90
|
assert.ok(!options.repoAdvisories || options.github, 'advisories: repoAdvisories needs a github client')
|
|
91
91
|
const byEcosystem = collect(packages)
|
|
92
92
|
for (const ecosystem of byEcosystem.keys()) assert.ok(!ECOSYSTEMS[ecosystem].repositoryOnly || options.github, `advisories: ${ecosystem} packages need a github client`)
|
|
@@ -96,7 +96,7 @@ export async function advisories(packages, options = {}) {
|
|
|
96
96
|
const asked = new Map(names.map((name) => [name, [...named.get(name).versions].toSorted(compare)]))
|
|
97
97
|
const known = new Map(names.filter((name) => named.get(name).github).map((name) => [name, named.get(name).github]))
|
|
98
98
|
const internal = new Set(names.filter((name) => named.get(name).internal))
|
|
99
|
-
const rows = await find(asked, { github: options.github, repoAdvisories: options.repoAdvisories === true, details: options.details === true, osv: options.osv === true, known, internal, cache: options.cache })
|
|
99
|
+
const rows = await find(asked, { github: options.github, repoAdvisories: options.repoAdvisories === true, details: options.details === true, osv: options.osv === true, githubAliases: options.githubAliases !== false, known, internal, cache: options.cache })
|
|
100
100
|
return oneRowPerAdvisory(rows.filter((row) => row.versions.length > 0), asked).map((row) => ({ ecosystem, ...row, ...(isMalware(row) && { malware: true }) }))
|
|
101
101
|
}))
|
|
102
102
|
return found.flat().toSorted((a, b) => order(a.ecosystem, b.ecosystem) || order(a.name, b.name))
|
package/src/advisories/osv.js
CHANGED
|
@@ -192,7 +192,7 @@ export async function getVuln(id) {
|
|
|
192
192
|
// keeps it, where OSV's record of it says where that is (`published`,
|
|
193
193
|
// `database_specific.github_reviewed`): kept by the record's `modified`;
|
|
194
194
|
// undefined where GitHub has no such file.
|
|
195
|
-
async function
|
|
195
|
+
async function aliasesOnGithub(record, cache) {
|
|
196
196
|
const published = PUBLISHED.exec(record.published ?? '')?.groups
|
|
197
197
|
if (!published || typeof record.modified !== 'string') return undefined
|
|
198
198
|
const kept = await readJSON('osv/github-aliases', record.id, cache)
|
|
@@ -216,7 +216,7 @@ async function githubAliases(record, cache) {
|
|
|
216
216
|
// GitHub has no record of it.
|
|
217
217
|
async function apart(record, cache) {
|
|
218
218
|
if (!isGhsa(record.id) || !record.aliases.some((id) => isGhsa(id))) return record
|
|
219
|
-
const own = await
|
|
219
|
+
const own = await aliasesOnGithub(record, cache)
|
|
220
220
|
if (own === undefined) return record
|
|
221
221
|
const isRelated = (id) => (isGhsa(id) || isCve(id)) && !own.includes(id)
|
|
222
222
|
const related = record.aliases.filter(isRelated)
|
|
@@ -323,10 +323,10 @@ export function toAdvisory(ecosystem, name, versions, record, details) {
|
|
|
323
323
|
}
|
|
324
324
|
|
|
325
325
|
// OSV's batch query answers ids only, each record fetched after, a GHSA's
|
|
326
|
-
// told apart from those OSV joins it with (apart)
|
|
327
|
-
// naming each other as aliases, are one
|
|
328
|
-
// under its first, the rest its aliases.
|
|
329
|
-
export async function osvRows({ osv }, asked, { details, cache }) {
|
|
326
|
+
// told apart from those OSV joins it with (apart) unless `githubAliases` is
|
|
327
|
+
// false. Records of one advisory, naming each other as aliases, are one
|
|
328
|
+
// group: each version is reported under its first, the rest its aliases.
|
|
329
|
+
export async function osvRows({ osv }, asked, { details, cache, githubAliases = true }) {
|
|
330
330
|
const list = [...asked].flatMap(([name, versions]) => versions.map((version) => ({ name, version })))
|
|
331
331
|
const hits = new Map() // id -> name -> versions, in `list` order
|
|
332
332
|
const found = await idsOf(list.map(({ name, version }) => ({ package: { name, ecosystem: osv }, version })), (j) => `${list[j].name}@${list[j].version}`)
|
|
@@ -338,7 +338,7 @@ export async function osvRows({ osv }, asked, { details, cache }) {
|
|
|
338
338
|
}
|
|
339
339
|
}
|
|
340
340
|
const fetched = (await pool([...hits.keys()], RECORDS_AT_ONCE, getVuln)).filter((record) => !record.withdrawn)
|
|
341
|
-
const records = await pool(fetched, RECORDS_AT_ONCE, (record) => apart(record, cache))
|
|
341
|
+
const records = githubAliases ? await pool(fetched, RECORDS_AT_ONCE, (record) => apart(record, cache)) : fetched
|
|
342
342
|
const groups = new Map()
|
|
343
343
|
for (const record of records) {
|
|
344
344
|
if (groups.has(record)) continue
|