@preventive/upstream 1.10.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/electron.d.ts +29 -0
- package/electron.js +2 -0
- package/package.json +9 -2
- package/src/advisories/index.js +2 -2
- package/src/advisories/osv.js +7 -7
- package/src/cache.js +1 -1
- package/src/electron.js +42 -0
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/electron.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The version is asserted to be an Electron one (`45.5.0`,
|
|
2
|
+
// `45.0.0-alpha.16`, `36.0.0-nightly.20250101`), the platform and arch
|
|
3
|
+
// ones Electron builds for, and the checksum 64 lowercase hex digits,
|
|
4
|
+
// before any request or cache path. The cache is setCacheDir's (npm.js).
|
|
5
|
+
|
|
6
|
+
import type { CacheOptions } from './npm.js'
|
|
7
|
+
|
|
8
|
+
export { HttpError } from './npm.js'
|
|
9
|
+
|
|
10
|
+
export type ElectronPlatform = 'darwin' | 'linux' | 'mas' | 'win32'
|
|
11
|
+
export type ElectronArch = 'arm64' | 'armv7l' | 'ia32' | 'x64'
|
|
12
|
+
|
|
13
|
+
// `electron-v<version>-<platform>-<arch>.zip`, whole, in memory, from the
|
|
14
|
+
// GitHub release `v<version>` of electron/electron (electron/nightlies
|
|
15
|
+
// for a version naming a nightly), through GitHub's redirect to its asset
|
|
16
|
+
// host. The release says nothing a lockfile holds of what the zip hashes
|
|
17
|
+
// to, so `checksum` is required: its sha256, as the `electron` package's
|
|
18
|
+
// checksums.json gives it. The bytes are checked against it, whether
|
|
19
|
+
// downloaded (before they are kept) or read from upstream's or stasis's
|
|
20
|
+
// default cache, setCacheDir's, or a `cache` store in its place, where one
|
|
21
|
+
// that does not match throws. A kept zip that matches is answered with no
|
|
22
|
+
// request at all.
|
|
23
|
+
//
|
|
24
|
+
// @electron/get's cache is read first, and never written: the zip under
|
|
25
|
+
// $electron_config_cache where install.js is told to keep it there, else
|
|
26
|
+
// under the platform's cache directory for electron (~/.cache/electron on
|
|
27
|
+
// Linux), in the directory named for the sha256 of the release's URL. A
|
|
28
|
+
// file there that does not match is passed over.
|
|
29
|
+
export function getElectronZip(version: string, platform: ElectronPlatform, arch: ElectronArch, checksum: string, options?: CacheOptions): Promise<Uint8Array>
|
package/electron.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/upstream",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Minimal npm, crates.io, RubyGems, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
|
|
3
|
+
"version": "1.12.0",
|
|
4
|
+
"description": "Minimal npm, crates.io, RubyGems, Soldeer, CocoaPods trunk, GitHub, Electron release and git checkout clients",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./advisories.js": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"types": "./cocoapods.d.ts",
|
|
17
17
|
"default": "./cocoapods.js"
|
|
18
18
|
},
|
|
19
|
+
"./electron.js": {
|
|
20
|
+
"types": "./electron.d.ts",
|
|
21
|
+
"default": "./electron.js"
|
|
22
|
+
},
|
|
19
23
|
"./github.js": {
|
|
20
24
|
"types": "./github.d.ts",
|
|
21
25
|
"default": "./github.js"
|
|
@@ -62,6 +66,8 @@
|
|
|
62
66
|
"cargo.js",
|
|
63
67
|
"cocoapods.d.ts",
|
|
64
68
|
"cocoapods.js",
|
|
69
|
+
"electron.d.ts",
|
|
70
|
+
"electron.js",
|
|
65
71
|
"github.d.ts",
|
|
66
72
|
"github.js",
|
|
67
73
|
"git.d.ts",
|
|
@@ -97,6 +103,7 @@
|
|
|
97
103
|
"src/cargo/repos.js",
|
|
98
104
|
"src/cocoapods.js",
|
|
99
105
|
"src/download.js",
|
|
106
|
+
"src/electron.js",
|
|
100
107
|
"src/git.js",
|
|
101
108
|
"src/github/client.js",
|
|
102
109
|
"src/github/commit.js",
|
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
|
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', 'osv/github-aliases', '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', 'electron/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/electron.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { join, posix } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { assertArgs, assertSha256, assertion, matches, optional } from './args.js'
|
|
5
|
+
import { absolute, assertCache, cacheDirFor } from './cache.js'
|
|
6
|
+
import { verifiedDownload } from './download.js'
|
|
7
|
+
import { GITHUB_WEB, buildUrl } from './http.js'
|
|
8
|
+
|
|
9
|
+
const DIR = 'electron/zips' // No expiry: a zip is held to its checksum.
|
|
10
|
+
|
|
11
|
+
// As @electron/get names the builds Electron publishes.
|
|
12
|
+
const PLATFORMS = new Set(['darwin', 'linux', 'mas', 'win32'])
|
|
13
|
+
const ARCHES = new Set(['arm64', 'armv7l', 'ia32', 'x64'])
|
|
14
|
+
// No build metadata: the version is a URL segment and a file name.
|
|
15
|
+
const assertElectronVersion = assertion('an Electron version', matches(/^(?=.{1,128}$)\d+\.\d+\.\d+(?:-[\dA-Za-z][\dA-Za-z.-]*)?$/u))
|
|
16
|
+
const assertOneOf = (set, must) => assertion(must, (value) => set.has(value))
|
|
17
|
+
const assertPlatform = assertOneOf(PLATFORMS, `one of ${[...PLATFORMS].join(', ')}`)
|
|
18
|
+
const assertArch = assertOneOf(ARCHES, `one of ${[...ARCHES].join(', ')}`)
|
|
19
|
+
|
|
20
|
+
// Where @electron/get keeps `url`: <root>/<sha256 of its directory's URL>/<file>,
|
|
21
|
+
// the root install.js's electron_config_cache, else the platform's cache for electron.
|
|
22
|
+
function electronGetPaths(url) {
|
|
23
|
+
const parsed = new URL(url)
|
|
24
|
+
parsed.pathname = posix.dirname(parsed.pathname)
|
|
25
|
+
const dir = createHash('sha256').update(parsed.toString()).digest('hex')
|
|
26
|
+
return [absolute(process.env.electron_config_cache), cacheDirFor('electron')].filter(Boolean).map((root) => join(root, dir, posix.basename(url)))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// As @electron/get downloads it for install.js. The redirect to GitHub's asset
|
|
30
|
+
// host is followed: the bytes are held to `checksum` wherever they come from.
|
|
31
|
+
export async function getElectronZip(version, platform, arch, checksum, options = {}) {
|
|
32
|
+
const method = 'getElectronZip'
|
|
33
|
+
assertElectronVersion(method, 'version', version)
|
|
34
|
+
assertPlatform(method, 'platform', platform)
|
|
35
|
+
assertArch(method, 'arch', arch)
|
|
36
|
+
assertSha256(method, 'checksum', checksum)
|
|
37
|
+
assertArgs(method, options, { cache: optional(assertCache) })
|
|
38
|
+
const name = `electron-v${version}-${platform}-${arch}`
|
|
39
|
+
const repo = version.includes('nightly') ? 'nightlies' : 'electron'
|
|
40
|
+
const url = buildUrl(GITHUB_WEB, ['electron', repo, 'releases', 'download', `v${version}`, `${name}.zip`])
|
|
41
|
+
return await verifiedDownload({ method, dir: DIR, what: `${name}.zip`, entry: name, ext: 'zip', algorithm: 'sha256', expected: checksum, local: electronGetPaths(url), ours: true, cache: options.cache, locate: () => url, options: { redirect: 'follow' } })
|
|
42
|
+
}
|