@preventive/upstream 1.9.1 → 1.10.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 +5 -0
- package/package.json +1 -1
- package/src/advisories/index.js +2 -0
- package/src/advisories/npm.js +3 -1
- package/src/advisories/osv.js +50 -6
- package/src/cache.js +1 -1
- package/src/http.js +3 -1
package/advisories.d.ts
CHANGED
|
@@ -60,6 +60,11 @@ export interface Advisory {
|
|
|
60
60
|
url?: string
|
|
61
61
|
// Its other ids.
|
|
62
62
|
aliases: string[]
|
|
63
|
+
// Those of other advisories OSV joins with a GHSA, its GitHub record telling
|
|
64
|
+
// them apart: another GHSA, and its CVE, as GHSA-37ch-88jc-xwx2 (of
|
|
65
|
+
// 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.
|
|
67
|
+
related?: string[]
|
|
63
68
|
title?: string
|
|
64
69
|
// With `details`: its full text, in Markdown.
|
|
65
70
|
details?: string
|
package/package.json
CHANGED
package/src/advisories/index.js
CHANGED
|
@@ -56,9 +56,11 @@ function joinRows(rows, asked) {
|
|
|
56
56
|
const joined = {
|
|
57
57
|
...head,
|
|
58
58
|
aliases: [...new Set(all.flatMap((row) => row.aliases))].filter((id) => id !== head.id),
|
|
59
|
+
related: [...new Set(all.flatMap((row) => row.related ?? []))].filter((id) => id !== head.id && !all.some((row) => row.aliases.includes(id))),
|
|
59
60
|
cwe: [...new Set(all.flatMap((row) => row.cwe))],
|
|
60
61
|
versions: asked.filter((version) => versions.has(version)),
|
|
61
62
|
}
|
|
63
|
+
if (joined.related.length === 0) delete joined.related
|
|
62
64
|
if (rest.some((row) => row.informational !== head.informational)) delete joined.informational
|
|
63
65
|
for (const key of ['title', 'details']) {
|
|
64
66
|
const from = joined[key] === undefined && rest.find((row) => row[key] !== undefined)
|
package/src/advisories/npm.js
CHANGED
|
@@ -65,7 +65,7 @@ async function withDetails(rows) {
|
|
|
65
65
|
|
|
66
66
|
// With `osv`, OSV's records too, malware's among them. A version a registry
|
|
67
67
|
// row reports under the same advisory is left to that row, which takes the
|
|
68
|
-
// record's ids as aliases.
|
|
68
|
+
// record's ids as aliases, and those it is related to (osv.js apart).
|
|
69
69
|
function withOsv(registry, osv) {
|
|
70
70
|
const rows = registry.map((row) => ({ ...row }))
|
|
71
71
|
const added = []
|
|
@@ -74,6 +74,8 @@ function withOsv(registry, osv) {
|
|
|
74
74
|
const same = rows.filter((row) => row.name === record.name && ids.includes(row.id) && row.versions.some((version) => record.versions.includes(version)))
|
|
75
75
|
for (const row of same) {
|
|
76
76
|
row.aliases = [...new Set([...row.aliases, ...ids])].filter((id) => id !== row.id)
|
|
77
|
+
const related = [...new Set([...row.related ?? [], ...record.related ?? []])].filter((id) => id !== row.id && !row.aliases.includes(id))
|
|
78
|
+
if (related.length > 0) row.related = related
|
|
77
79
|
if (record.id === row.id && record.details !== undefined) row.details = record.details
|
|
78
80
|
}
|
|
79
81
|
const versions = record.versions.filter((version) => !same.some((row) => row.versions.includes(version)))
|
package/src/advisories/osv.js
CHANGED
|
@@ -4,7 +4,7 @@ import { allows, normalize } from '@preventive/lockfile/composer-semver.js'
|
|
|
4
4
|
|
|
5
5
|
import { assertCrateName, assertCrateVersion, assertGemName, assertGemVersion, assertion, isGhsa, isRepo, isStrings, matches, show } from '../args.js'
|
|
6
6
|
import { readJSON, writeJSON } from '../cache.js'
|
|
7
|
-
import { OSV_API, OSV_EXPORTS, buildUrl, request } from '../http.js'
|
|
7
|
+
import { GITHUB_RAW, OSV_API, OSV_EXPORTS, buildUrl, isNotFound, recover, request } from '../http.js'
|
|
8
8
|
import { chunks, pool } from '../pool.js'
|
|
9
9
|
import { assertPypiName, assertPypiVersion, compareVersions as comparePypiVersions, isVersion as isPypiVersion, normalName, readRange as readPypiRange } from '../pypi/version.js'
|
|
10
10
|
import { compareVersions as compareGemVersions, isVersion as isGemVersion, readRange as readGemRange } from '../rubygems/version.js'
|
|
@@ -28,6 +28,12 @@ const INFORMATIONAL = new Set(['unmaintained', 'unsound', 'notice'])
|
|
|
28
28
|
const rank = (id) => (id.startsWith('RUSTSEC-') ? 0 : (isGhsa(id) ? 1 : 2))
|
|
29
29
|
const first = (a, b) => rank(a.id) - rank(b.id) || order(a.id, b.id)
|
|
30
30
|
const named = (a, b) => a.aliases.includes(b.id) || b.aliases.includes(a.id)
|
|
31
|
+
const isCve = matches(/^CVE-\d{4}-\d{4,}$/u)
|
|
32
|
+
// GitHub's advisory database, its records by whether GitHub reviewed them,
|
|
33
|
+
// then the year and month each was published:
|
|
34
|
+
// advisories/github-reviewed/2026/03/GHSA-37ch-88jc-xwx2/GHSA-37ch-88jc-xwx2.json.
|
|
35
|
+
const GITHUB_ADVISORIES = ['github', 'advisory-database', 'main', 'advisories']
|
|
36
|
+
const PUBLISHED = /^(?<year>\d{4})-(?<month>\d{2})-\d{2}T/u
|
|
31
37
|
|
|
32
38
|
export const CARGO = {
|
|
33
39
|
osv: 'crates.io',
|
|
@@ -182,6 +188,41 @@ export async function getVuln(id) {
|
|
|
182
188
|
return { ...record, aliases: (record.aliases ?? []).filter(isOsvId) }
|
|
183
189
|
}
|
|
184
190
|
|
|
191
|
+
// The ids GitHub's own record of a GHSA names, as its advisory database
|
|
192
|
+
// keeps it, where OSV's record of it says where that is (`published`,
|
|
193
|
+
// `database_specific.github_reviewed`): kept by the record's `modified`;
|
|
194
|
+
// undefined where GitHub has no such file.
|
|
195
|
+
async function githubAliases(record, cache) {
|
|
196
|
+
const published = PUBLISHED.exec(record.published ?? '')?.groups
|
|
197
|
+
if (!published || typeof record.modified !== 'string') return undefined
|
|
198
|
+
const kept = await readJSON('osv/github-aliases', record.id, cache)
|
|
199
|
+
if (kept?.modified === record.modified && isStrings(kept.aliases)) return kept.aliases
|
|
200
|
+
const reviewed = record.database_specific?.github_reviewed === true ? 'github-reviewed' : 'unreviewed'
|
|
201
|
+
const url = buildUrl(GITHUB_RAW, [...GITHUB_ADVISORIES, reviewed, published.year, published.month, record.id, `${record.id}.json`])
|
|
202
|
+
const github = await request(url, { as: 'json' }).catch(recover(isNotFound, undefined))
|
|
203
|
+
if (github === undefined) return undefined
|
|
204
|
+
assert.ok(github?.id === record.id && (github.aliases === undefined || isStrings(github.aliases)), `advisories: malformed GitHub record of ${record.id}`)
|
|
205
|
+
const aliases = github.aliases ?? []
|
|
206
|
+
await writeJSON('osv/github-aliases', record.id, { modified: record.modified, aliases }, cache)
|
|
207
|
+
return aliases
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// A GHSA's record as OSV tells it, its ids those of every record OSV joins
|
|
211
|
+
// it with: another GHSA's among them, and that one's CVE, as
|
|
212
|
+
// GHSA-37ch-88jc-xwx2 (CVE-2026-4867 on GitHub) has GHSA-9wv6-86v2-598j's
|
|
213
|
+
// CVE-2024-45296. Where it names another GHSA, the GHSAs and CVEs GitHub's
|
|
214
|
+
// own record of it doesn't name are those it is `related` to, not its
|
|
215
|
+
// aliases; any other id (MAL-, PYSEC-...) stays one. As OSV tells it where
|
|
216
|
+
// GitHub has no record of it.
|
|
217
|
+
async function apart(record, cache) {
|
|
218
|
+
if (!isGhsa(record.id) || !record.aliases.some((id) => isGhsa(id))) return record
|
|
219
|
+
const own = await githubAliases(record, cache)
|
|
220
|
+
if (own === undefined) return record
|
|
221
|
+
const isRelated = (id) => (isGhsa(id) || isCve(id)) && !own.includes(id)
|
|
222
|
+
const related = record.aliases.filter(isRelated)
|
|
223
|
+
return related.length > 0 ? { ...record, aliases: record.aliases.filter((id) => !isRelated(id)), related } : record
|
|
224
|
+
}
|
|
225
|
+
|
|
185
226
|
// Whether a version is `>=`, `<` or `<=` a bound, as an ecosystem orders
|
|
186
227
|
// them; undefined where it can't read either.
|
|
187
228
|
const MEETS = { '>=': (cmp) => cmp >= 0, '<': (cmp) => cmp < 0, '<=': (cmp) => cmp <= 0 }
|
|
@@ -271,6 +312,7 @@ export function toAdvisory(ecosystem, name, versions, record, details) {
|
|
|
271
312
|
...(ghsa && { ghsa }),
|
|
272
313
|
url: ghsa ? advisoryUrl(ghsa) : osvPage(record.id),
|
|
273
314
|
aliases,
|
|
315
|
+
...(record.related && { related: record.related }),
|
|
274
316
|
...(record.summary && { title: record.summary }),
|
|
275
317
|
...(details && detailsOf(record.details, record.id)),
|
|
276
318
|
...metrics({ severity: record.database_specific?.severity, vector, cwe: record.database_specific?.cwe_ids }),
|
|
@@ -280,10 +322,11 @@ export function toAdvisory(ecosystem, name, versions, record, details) {
|
|
|
280
322
|
}
|
|
281
323
|
}
|
|
282
324
|
|
|
283
|
-
// OSV's batch query answers ids only, each record fetched after
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
|
|
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). Records of one advisory,
|
|
327
|
+
// naming each other as aliases, are one group: each version is reported
|
|
328
|
+
// under its first, the rest its aliases.
|
|
329
|
+
export async function osvRows({ osv }, asked, { details, cache }) {
|
|
287
330
|
const list = [...asked].flatMap(([name, versions]) => versions.map((version) => ({ name, version })))
|
|
288
331
|
const hits = new Map() // id -> name -> versions, in `list` order
|
|
289
332
|
const found = await idsOf(list.map(({ name, version }) => ({ package: { name, ecosystem: osv }, version })), (j) => `${list[j].name}@${list[j].version}`)
|
|
@@ -294,7 +337,8 @@ export async function osvRows({ osv }, asked, { details }) {
|
|
|
294
337
|
byName.set(name, (byName.get(name) ?? new Set()).add(version))
|
|
295
338
|
}
|
|
296
339
|
}
|
|
297
|
-
const
|
|
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))
|
|
298
342
|
const groups = new Map()
|
|
299
343
|
for (const record of records) {
|
|
300
344
|
if (groups.has(record)) continue
|
package/src/cache.js
CHANGED
|
@@ -10,7 +10,7 @@ import { assertCacheName, assertDirectoryPath, assertion, isRepo } from './args.
|
|
|
10
10
|
import { MAX_BYTES, decode } from './http.js'
|
|
11
11
|
import { pool } from './pool.js'
|
|
12
12
|
|
|
13
|
-
const DIRS = new Set(['npm/repos', 'npm/public', 'npm/tarballs', 'npm/versions', 'cargo/repos', 'cargo/crates', 'cargo/index', 'composer/repos', 'soldeer/repos', 'soldeer/zips', 'rubygems/repos', 'rubygems/gems', 'pypi/repos', 'cocoapods/podspecs', 'cocoapods/archives', 'cocoapods/repos', 'github/trees', 'github/advisories', 'github/public', 'osv/names', 'rubysec/index', 'rubysec/advisories'])
|
|
13
|
+
const DIRS = new Set(['npm/repos', 'npm/public', 'npm/tarballs', 'npm/versions', 'cargo/repos', 'cargo/crates', 'cargo/index', 'composer/repos', 'soldeer/repos', 'soldeer/zips', 'rubygems/repos', 'rubygems/gems', 'pypi/repos', 'cocoapods/podspecs', 'cocoapods/archives', 'cocoapods/repos', 'github/trees', 'github/advisories', 'github/public', 'osv/names', 'osv/github-aliases', 'rubysec/index', 'rubysec/advisories'])
|
|
14
14
|
const RECORD_TTL_MS = 30 * 24 * 60 * 60 * 1000 // A link only moves on a transfer or rename, and GitHub redirects those.
|
|
15
15
|
const RECORDS_AT_ONCE = 8
|
|
16
16
|
// JSON filed gzipped, as `<name>.json.gz`: a listing carries each
|
package/src/http.js
CHANGED
|
@@ -22,10 +22,12 @@ export const RUBYGEMS = 'https://rubygems.org'
|
|
|
22
22
|
export const RUBYGEMS_INDEX = 'https://index.rubygems.org'
|
|
23
23
|
export const PYPI = 'https://pypi.org'
|
|
24
24
|
export const GITHUB_WEB = 'https://github.com'
|
|
25
|
+
// GitHub's repositories' files as committed: its advisory database's records.
|
|
26
|
+
export const GITHUB_RAW = 'https://raw.githubusercontent.com'
|
|
25
27
|
export const MAVEN_CENTRAL = 'https://repo1.maven.org'
|
|
26
28
|
export const MAX_BYTES = 512 * 1024 * 1024
|
|
27
29
|
|
|
28
|
-
const ORIGINS = new Set([NPM_REGISTRY, GITHUB_API, OSV_API, OSV_EXPORTS, CRATES_API, PACKAGIST_REPO, PACKAGIST, CRATES_INDEX, CRATES_STATIC, SOLDEER_API, SOLDEER_REVISIONS, COCOAPODS_CDN, RUBYGEMS, RUBYGEMS_INDEX, PYPI, GITHUB_WEB, MAVEN_CENTRAL])
|
|
30
|
+
const ORIGINS = new Set([NPM_REGISTRY, GITHUB_API, OSV_API, OSV_EXPORTS, CRATES_API, PACKAGIST_REPO, PACKAGIST, CRATES_INDEX, CRATES_STATIC, SOLDEER_API, SOLDEER_REVISIONS, COCOAPODS_CDN, RUBYGEMS, RUBYGEMS_INDEX, PYPI, GITHUB_WEB, GITHUB_RAW, MAVEN_CENTRAL])
|
|
29
31
|
const isSegment = matches(/^(?!\.\.?$)(?:[\w.~@-]|%[\dA-F]{2})+$/u)
|
|
30
32
|
const isQueryKey = matches(/^[a-z_]+(?:\[\])?$/u)
|
|
31
33
|
const isQueryValue = (value) => (typeof value === 'string' && value !== '') || (Number.isSafeInteger(value) && value >= 0)
|