@preventive/upstream 1.12.0 → 1.13.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.
- package/advisories.d.ts +125 -89
- package/cargo.d.ts +59 -35
- package/cocoapods.d.ts +44 -57
- package/electron.d.ts +35 -25
- package/git.d.ts +25 -16
- package/github/write.d.ts +60 -29
- package/github.d.ts +207 -193
- package/npm.d.ts +151 -87
- package/package.d.ts +30 -16
- package/package.json +1 -1
- package/rubygems.d.ts +22 -9
- package/semver.d.ts +40 -19
- package/soldeer.d.ts +21 -12
- package/src/advisories/actions.js +13 -38
- package/src/advisories/common.js +29 -1
- package/src/advisories/github.js +5 -19
- package/src/advisories/index.js +3 -10
- package/src/advisories/npm.js +4 -19
- package/src/advisories/osv.js +19 -41
- package/src/advisories/packagist.js +1 -4
- package/src/advisories/patched.js +6 -18
- package/src/advisories/repos.js +8 -13
- package/src/advisories/rubysec.js +2 -7
- package/src/args.js +5 -10
- package/src/attributes.js +3 -4
- package/src/cache.js +9 -22
- package/src/cargo/crate.js +4 -7
- package/src/cargo/repos.js +1 -7
- package/src/cocoapods.js +3 -19
- package/src/download.js +4 -12
- package/src/electron.js +6 -8
- package/src/github/commit.js +1 -13
- package/src/github/read.js +19 -68
- package/src/github/write.js +0 -1
- package/src/http.js +2 -7
- package/src/lockfiles.js +3 -11
- package/src/npm/cacache.js +3 -8
- package/src/npm/registry.js +12 -4
- package/src/npm/repos.js +3 -15
- package/src/npm/tarball.js +5 -20
- package/src/npm/versions.js +7 -21
- package/src/package.js +1 -7
- package/src/pool.js +0 -1
- package/src/pypi/version.js +1 -5
- package/src/remote.js +4 -6
- package/src/rubygems/gem.js +2 -2
- package/src/rubygems/version.js +2 -10
- package/src/semver.js +3 -9
- package/src/soldeer.js +0 -4
- package/src/tree.js +14 -44
- package/src/weak-edges.js +0 -2
- package/weak-edges.d.ts +36 -24
package/src/advisories/github.js
CHANGED
|
@@ -6,7 +6,7 @@ import { isGone } from '../github/client.js'
|
|
|
6
6
|
import { HttpError, recover } from '../http.js'
|
|
7
7
|
import { pool } from '../pool.js'
|
|
8
8
|
import { compareVersions, readRange } from '../rubygems/version.js'
|
|
9
|
-
import { advisoryUrl, covered, detailsOf, isText, mayBeInRange, metrics, order } from './common.js'
|
|
9
|
+
import { advisoryUrl, covered, coveredBy, detailsOf, isText, mayBeInRange, metrics, npmRange, order } from './common.js'
|
|
10
10
|
import { boundGemRange, boundSemverRange } from './patched.js'
|
|
11
11
|
import { podRepos, soldeerRepos } from './repos.js'
|
|
12
12
|
|
|
@@ -23,8 +23,7 @@ const isRepoAdvisory = (advisory) => advisory && typeof advisory === 'object' &&
|
|
|
23
23
|
|
|
24
24
|
export const assertClient = assertion('a GitHub client from createClient', (value) => typeof value?.listRepoAdvisories === 'function' && typeof value.getRepo === 'function')
|
|
25
25
|
|
|
26
|
-
//
|
|
27
|
-
// answered but not kept.
|
|
26
|
+
// One whose only fault is a description is answered but not kept.
|
|
28
27
|
function digest(repo, list) {
|
|
29
28
|
return list.flatMap((advisory) => {
|
|
30
29
|
assert.ok(isRepoAdvisory(advisory), `advisories: malformed advisory from ${repo}`)
|
|
@@ -64,8 +63,6 @@ async function listingOf(github, repo) {
|
|
|
64
63
|
return { repo: moved, list: await github.listRepoAdvisories({ repo: moved }) }
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
// A repository's listing and the name it has now, one cache entry for every
|
|
68
|
-
// spelling; none for one gone, blocked or redirected elsewhere, and not kept.
|
|
69
66
|
async function listAdvisories(github, repo, cache) {
|
|
70
67
|
const name = repo.toLowerCase()
|
|
71
68
|
const entry = await readRecord(DIR, name, cache, LISTING_TTL_MS)
|
|
@@ -79,9 +76,7 @@ async function listAdvisories(github, repo, cache) {
|
|
|
79
76
|
return { repo: found.repo, advisories }
|
|
80
77
|
}
|
|
81
78
|
|
|
82
|
-
|
|
83
|
-
// can't read, or none, covers every version.
|
|
84
|
-
export const bySemver = (covers) => (asked, range) => covered(asked, range.replaceAll(',', ' '), covers)
|
|
79
|
+
export const bySemver = (covers) => (asked, range) => covered(asked, npmRange(range), covers)
|
|
85
80
|
|
|
86
81
|
function fromRepository(repo, name, advisory, range, versions, details) {
|
|
87
82
|
return {
|
|
@@ -99,8 +94,6 @@ function fromRepository(repo, name, advisory, range, versions, details) {
|
|
|
99
94
|
}
|
|
100
95
|
}
|
|
101
96
|
|
|
102
|
-
// A row per advisory, range and asked name `takes` it for, a range with no
|
|
103
|
-
// end of its own one per line its patched versions end (see patched.js).
|
|
104
97
|
export async function repositoryAdvisories(github, asked, { repoOf, takes = () => true, versionsIn = bySemver(), bound = boundSemverRange, details, cache }) {
|
|
105
98
|
const namesOf = Map.groupBy([...asked.keys()].filter(repoOf), (name) => repoOf(name).toLowerCase())
|
|
106
99
|
const listed = await pool([...namesOf.values()], REPOS_AT_ONCE, async (names) => ({ names, ...(await listAdvisories(github, repoOf(names[0]), cache)) }))
|
|
@@ -124,8 +117,7 @@ async function reposOf(asked, known, lookUp, cache) {
|
|
|
124
117
|
return (name) => known.get(name) ?? found.get(name)
|
|
125
118
|
}
|
|
126
119
|
|
|
127
|
-
//
|
|
128
|
-
// in versions `rows` don't already report under that GHSA.
|
|
120
|
+
// What each package's repository publishes for it, in versions `rows` don't already report under that GHSA.
|
|
129
121
|
export async function withRepositories(rows, asked, { github, repoAdvisories, known, details, cache }, { github: ecosystem, lookUp, versionsIn, bound, nameKey = (name) => name }) {
|
|
130
122
|
if (!repoAdvisories) return rows
|
|
131
123
|
const reported = new Set(rows.flatMap((row) => [row.id, row.ghsa, ...row.aliases].filter(isGhsa).flatMap((id) => row.versions.map((version) => `${row.name} ${id} ${version}`))))
|
|
@@ -151,12 +143,6 @@ export const SOLDEER = {
|
|
|
151
143
|
// Pod::Version is a Gem::Version, ordered without build metadata.
|
|
152
144
|
const podRelease = (version) => version.split('+')[0]
|
|
153
145
|
|
|
154
|
-
// A range Gem::Requirement can't read covers every version.
|
|
155
|
-
function podsIn(versions, range) {
|
|
156
|
-
const test = readRange(range)
|
|
157
|
-
return test === undefined ? [...versions] : versions.filter((version) => test(podRelease(version)))
|
|
158
|
-
}
|
|
159
|
-
|
|
160
146
|
// No database has pods: the repository their podspec names is the only
|
|
161
147
|
// source, every range counting.
|
|
162
148
|
export const COCOAPODS = {
|
|
@@ -164,5 +150,5 @@ export const COCOAPODS = {
|
|
|
164
150
|
assertName: assertPodName,
|
|
165
151
|
assertVersion: assertPodVersion,
|
|
166
152
|
compare: (a, b) => compareVersions(podRelease(a), podRelease(b)) || order(a, b),
|
|
167
|
-
advisories: async (asked, { github, known, details, cache }) => await repositoryAdvisories(github, asked, { repoOf: await reposOf(asked, known, podRepos, cache), versionsIn:
|
|
153
|
+
advisories: async (asked, { github, known, details, cache }) => await repositoryAdvisories(github, asked, { repoOf: await reposOf(asked, known, podRepos, cache), versionsIn: coveredBy(readRange, podRelease), bound: boundGemRange, details, cache }),
|
|
168
154
|
}
|
package/src/advisories/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
|
|
3
|
-
import { assertArgs, assertBoolean, assertRepo,
|
|
3
|
+
import { assertArgs, assertBoolean, assertOneOf, assertRepo, assertVersions, isIterable, optional, sameName } from '../args.js'
|
|
4
4
|
import { assertCache } from '../cache.js'
|
|
5
5
|
import { SEVERITIES, isMalware, order } from './common.js'
|
|
6
6
|
import { GITHUB } from './actions.js'
|
|
@@ -11,11 +11,8 @@ import { RUBY } from './rubysec.js'
|
|
|
11
11
|
|
|
12
12
|
const ECOSYSTEMS = { npm: NPM, cargo: CARGO, composer: COMPOSER, gem: GEM, ruby: RUBY, pypi: PYPI, swift: SWIFT, cocoapods: COCOAPODS, soldeer: SOLDEER, github: GITHUB }
|
|
13
13
|
const byNumbers = new Intl.Collator('en', { numeric: true }).compare
|
|
14
|
-
const assertEcosystem =
|
|
15
|
-
const assertVersions = assertion('a non-empty array', (value) => Array.isArray(value) && value.length > 0)
|
|
14
|
+
const assertEcosystem = assertOneOf(new Set(Object.keys(ECOSYSTEMS)))
|
|
16
15
|
|
|
17
|
-
// Ecosystem -> name -> { versions, github?, internal? }, every package
|
|
18
|
-
// checked first. A name is internal where any of its spellings is.
|
|
19
16
|
function collect(packages) {
|
|
20
17
|
assert.ok(isIterable(packages), 'advisories: packages must be an iterable of { ecosystem, name, github?, versions }')
|
|
21
18
|
const byEcosystem = new Map()
|
|
@@ -45,9 +42,6 @@ function collect(packages) {
|
|
|
45
42
|
const SOURCES = ['registry', 'osv', 'packagist', 'rubysec', 'repository']
|
|
46
43
|
const worse = (a, b) => (b === undefined || (a !== undefined && SEVERITIES.indexOf(a) < SEVERITIES.indexOf(b)) ? a : b)
|
|
47
44
|
|
|
48
|
-
// An advisory's rows as one: the first by source, filled from the rest,
|
|
49
|
-
// with the worst severity, the highest CVSS, and every range, CWE and
|
|
50
|
-
// version. `informational` only where every row has it.
|
|
51
45
|
function joinRows(rows, asked) {
|
|
52
46
|
const all = rows.toSorted((a, b) => SOURCES.indexOf(a.source) - SOURCES.indexOf(b.source))
|
|
53
47
|
const [head, ...rest] = all
|
|
@@ -78,8 +72,7 @@ function joinRows(rows, asked) {
|
|
|
78
72
|
return joined
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
//
|
|
82
|
-
// stay rows of their own.
|
|
75
|
+
// Records of other ids that name one as an alias stay rows of their own.
|
|
83
76
|
function oneRowPerAdvisory(rows, asked) {
|
|
84
77
|
const byId = Map.groupBy(rows, (row) => `${row.name}\0${row.id}`)
|
|
85
78
|
return [...byId.values()].map((same) => (same.length === 1 ? same[0] : joinRows(same, asked.get(same[0].name))))
|
package/src/advisories/npm.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
|
|
3
3
|
import { assertPackageName, assertPackageVersion, isGhsa, isStrings, show } from '../args.js'
|
|
4
|
-
import { readRecord, writeRecord } from '../cache.js'
|
|
5
4
|
import { NPM_REGISTRY, answersHead, buildUrl, isNotFound, recover, request } from '../http.js'
|
|
6
5
|
import { chunks, pool } from '../pool.js'
|
|
7
6
|
import { compareVersions } from '../semver.js'
|
|
8
|
-
import { advisoryUrl, covered, detailsOf, isText, metrics } from './common.js'
|
|
7
|
+
import { advisoryUrl, covered, detailsOf, isText, metrics, publicOnly } from './common.js'
|
|
9
8
|
import { withRepositories } from './github.js'
|
|
10
9
|
import { RECORDS_AT_ONCE, getVuln, osvRows } from './osv.js'
|
|
11
10
|
import { npmRepos } from './repos.js'
|
|
@@ -101,27 +100,13 @@ async function servesAnyone(name) {
|
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
|
|
104
|
-
//
|
|
105
|
-
//
|
|
106
|
-
async function publicOnly(asked, cache) {
|
|
107
|
-
const names = [...asked.keys()]
|
|
108
|
-
const kept = await pool(names, NAMES_AT_ONCE, (name) => readRecord('npm/public', name, cache))
|
|
109
|
-
const serving = new Set(names.filter((name, i) => kept[i]?.public === true))
|
|
110
|
-
const missing = names.filter((name) => !serving.has(name))
|
|
111
|
-
const found = await pool(missing, NAMES_AT_ONCE, servesAnyone)
|
|
112
|
-
const added = missing.filter((name, i) => found[i])
|
|
113
|
-
await pool(added, NAMES_AT_ONCE, (name) => writeRecord('npm/public', name, { public: true }, cache))
|
|
114
|
-
for (const name of added) serving.add(name)
|
|
115
|
-
return new Map([...asked].filter(([name]) => serving.has(name)))
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// No request to OSV names a private package.
|
|
103
|
+
// No request to OSV names a private package. The name decides, not the
|
|
104
|
+
// version: npm takes down malicious versions but keeps their name.
|
|
119
105
|
async function osvOfPublic(asked, options) {
|
|
120
|
-
const told = await publicOnly(asked, options.cache)
|
|
106
|
+
const told = await publicOnly(asked, options.cache, { dir: 'npm/public', atOnce: NAMES_AT_ONCE, serves: servesAnyone })
|
|
121
107
|
return told.size > 0 ? await osvRows({ osv: 'npm' }, told, options) : []
|
|
122
108
|
}
|
|
123
109
|
|
|
124
|
-
// What `npm audit` asks, and with `osv`, OSV's records of public packages.
|
|
125
110
|
export const NPM = {
|
|
126
111
|
github: 'npm',
|
|
127
112
|
lookUp: npmRepos,
|
package/src/advisories/osv.js
CHANGED
|
@@ -9,7 +9,7 @@ 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'
|
|
11
11
|
import { compareVersions as compareSemver, isExactVersion } from '../semver.js'
|
|
12
|
-
import { advisoryUrl, detailsOf, inRange, isText, metrics, order } from './common.js'
|
|
12
|
+
import { advisoryUrl, coveredBy, detailsOf, inRange, isCve, isId, isText, metrics, order } from './common.js'
|
|
13
13
|
import { bySemver, withRepositories } from './github.js'
|
|
14
14
|
import { boundGemRange, boundPypiRange } from './patched.js'
|
|
15
15
|
import { packagistRows } from './packagist.js'
|
|
@@ -19,7 +19,6 @@ import { rubysecRows, sameIds } from './rubysec.js'
|
|
|
19
19
|
const QUERY_URL = buildUrl(OSV_API, ['v1', 'querybatch'])
|
|
20
20
|
const QUERIES_PER_REQUEST = 1000
|
|
21
21
|
export const RECORDS_AT_ONCE = 8
|
|
22
|
-
const isOsvId = matches(/^(?=.{1,128}$)[A-Z][\dA-Z]*(?:-[\dA-Za-z]+)+$/u)
|
|
23
22
|
// An id that is only another's alias (PKSA-...) has no page of its own.
|
|
24
23
|
const osvPage = (id) => `https://osv.dev/vulnerability/${id}`
|
|
25
24
|
const INFORMATIONAL = new Set(['unmaintained', 'unsound', 'notice'])
|
|
@@ -28,7 +27,6 @@ const INFORMATIONAL = new Set(['unmaintained', 'unsound', 'notice'])
|
|
|
28
27
|
const rank = (id) => (id.startsWith('RUSTSEC-') ? 0 : (isGhsa(id) ? 1 : 2))
|
|
29
28
|
const first = (a, b) => rank(a.id) - rank(b.id) || order(a.id, b.id)
|
|
30
29
|
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
30
|
// GitHub's advisory database, its records by whether GitHub reviewed them,
|
|
33
31
|
// then the year and month each was published:
|
|
34
32
|
// advisories/github-reviewed/2026/03/GHSA-37ch-88jc-xwx2/GHSA-37ch-88jc-xwx2.json.
|
|
@@ -71,10 +69,7 @@ export const GEM = {
|
|
|
71
69
|
// `1.0` and `1.0.0` are equal, so are ordered by their text.
|
|
72
70
|
compare: (a, b) => compareGemVersions(a, b) || order(a, b),
|
|
73
71
|
bound: boundGemRange,
|
|
74
|
-
versionsIn: (
|
|
75
|
-
const test = readGemRange(range)
|
|
76
|
-
return test === undefined ? [...asked] : asked.filter(test)
|
|
77
|
-
},
|
|
72
|
+
versionsIn: coveredBy(readGemRange),
|
|
78
73
|
advisories: async (asked, options) => {
|
|
79
74
|
const [osv, rubysec] = await Promise.all([osvRows(GEM, asked, options), options.github ? rubysecRows(options.github, asked, options) : []])
|
|
80
75
|
return await withRepositories([...osv, ...sameIds(rubysec, osv)], asked, options, GEM)
|
|
@@ -99,15 +94,14 @@ const namesIn = (record, ecosystem) => (Array.isArray(record.affected) ? record.
|
|
|
99
94
|
const isKept = (value) => value && typeof value === 'object' && typeof value.at === 'number' && value.records && typeof value.records === 'object'
|
|
100
95
|
&& Object.values(value.records).every((record) => typeof record?.modified === 'string' && isStrings(record.names))
|
|
101
96
|
|
|
102
|
-
//
|
|
103
|
-
// record read again only once it is modified.
|
|
97
|
+
// From OSV's list of records, each record read again only once it is modified.
|
|
104
98
|
async function osvNames(ecosystem, cache) {
|
|
105
99
|
const kept = await readJSON('osv/names', ecosystem, cache)
|
|
106
100
|
const records = isKept(kept) ? kept.records : {}
|
|
107
101
|
const age = isKept(kept) ? Date.now() - kept.at : Number.NaN
|
|
108
102
|
if (!(age >= 0 && age <= NAMES_TTL_MS)) {
|
|
109
103
|
const list = (await request(buildUrl(OSV_EXPORTS, [ecosystem, 'modified_id.csv']), { as: 'text' })).split('\n').filter(Boolean).map((line) => LISTED.exec(line)?.groups)
|
|
110
|
-
assert.ok(list.every((entry) => entry &&
|
|
104
|
+
assert.ok(list.every((entry) => entry && isId(entry.id)), `advisories: malformed list of OSV's ${ecosystem} records`)
|
|
111
105
|
const changed = list.filter(({ id, modified }) => records[id]?.modified !== modified)
|
|
112
106
|
const read = new Map((await pool(changed.map(({ id }) => id), RECORDS_AT_ONCE, getVuln)).map((record) => [record.id, namesIn(record, ecosystem)]))
|
|
113
107
|
const fresh = Object.fromEntries(list.map(({ id, modified }) => [id, { modified, names: read.get(id) ?? records[id].names }]))
|
|
@@ -147,10 +141,7 @@ export const PYPI = {
|
|
|
147
141
|
// `1.0` and `1.0.0` are equal, so are ordered by their text.
|
|
148
142
|
compare: (a, b) => comparePypiVersions(a, b) || order(a, b),
|
|
149
143
|
bound: boundPypiRange,
|
|
150
|
-
versionsIn: (
|
|
151
|
-
const test = readPypiRange(range)
|
|
152
|
-
return test === undefined ? [...asked] : asked.filter(test)
|
|
153
|
-
},
|
|
144
|
+
versionsIn: coveredBy(readPypiRange),
|
|
154
145
|
advisories: (asked, options) => osvAdvisories(PYPI, asked, options),
|
|
155
146
|
}
|
|
156
147
|
|
|
@@ -162,15 +153,14 @@ async function idsOf(queries, what) {
|
|
|
162
153
|
assert.ok(Array.isArray(answer?.results) && answer.results.length === chunk.length, 'advisories: expected one OSV result per query')
|
|
163
154
|
for (const result of answer.results) {
|
|
164
155
|
const vulns = result?.vulns ?? []
|
|
165
|
-
assert.ok(result && result.next_page_token === undefined && Array.isArray(vulns) && vulns.every((vuln) =>
|
|
156
|
+
assert.ok(result && result.next_page_token === undefined && Array.isArray(vulns) && vulns.every((vuln) => isId(vuln?.id)), `advisories: malformed OSV result for ${what(ids.length)}`)
|
|
166
157
|
ids.push(vulns.map(({ id }) => id))
|
|
167
158
|
}
|
|
168
159
|
}
|
|
169
160
|
return ids
|
|
170
161
|
}
|
|
171
162
|
|
|
172
|
-
//
|
|
173
|
-
// can't match: [{ record, names }], withdrawn ones left out.
|
|
163
|
+
// For an ecosystem whose versions OSV can't match.
|
|
174
164
|
export async function packageRecords(osv, names) {
|
|
175
165
|
const byId = new Map()
|
|
176
166
|
for (const [j, ids] of (await idsOf(names.map((name) => ({ package: { name, ecosystem: osv } })), (at) => names[at])).entries()) {
|
|
@@ -185,13 +175,11 @@ export async function getVuln(id) {
|
|
|
185
175
|
assert.ok(record?.id === id, `advisories: OSV answered for ${show(record?.id)}, not ${id}`)
|
|
186
176
|
assert.ok((record.aliases === undefined || isStrings(record.aliases)) && (record.summary === undefined || isText(record.summary))
|
|
187
177
|
&& (record.withdrawn === undefined || typeof record.withdrawn === 'string'), `advisories: malformed OSV record ${id}`)
|
|
188
|
-
return { ...record, aliases: (record.aliases ?? []).filter(
|
|
178
|
+
return { ...record, aliases: (record.aliases ?? []).filter(isId) }
|
|
189
179
|
}
|
|
190
180
|
|
|
191
|
-
// The ids GitHub's own record of a GHSA names,
|
|
192
|
-
//
|
|
193
|
-
// `database_specific.github_reviewed`): kept by the record's `modified`;
|
|
194
|
-
// undefined where GitHub has no such file.
|
|
181
|
+
// The ids GitHub's own record of a GHSA names, found in its advisory database by OSV's `published` and
|
|
182
|
+
// `database_specific.github_reviewed`, kept by OSV's `modified`; undefined where GitHub has no such file.
|
|
195
183
|
async function aliasesOnGithub(record, cache) {
|
|
196
184
|
const published = PUBLISHED.exec(record.published ?? '')?.groups
|
|
197
185
|
if (!published || typeof record.modified !== 'string') return undefined
|
|
@@ -207,13 +195,9 @@ async function aliasesOnGithub(record, cache) {
|
|
|
207
195
|
return aliases
|
|
208
196
|
}
|
|
209
197
|
|
|
210
|
-
//
|
|
211
|
-
//
|
|
212
|
-
//
|
|
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.
|
|
198
|
+
// OSV gives a GHSA the ids of every record it joins it with. Where it names another GHSA, the GHSAs and CVEs
|
|
199
|
+
// GitHub's own record doesn't name are `related`, not aliases; other ids (MAL-, PYSEC-...) stay. As OSV has it
|
|
200
|
+
// where GitHub has none.
|
|
217
201
|
async function apart(record, cache) {
|
|
218
202
|
if (!isGhsa(record.id) || !record.aliases.some((id) => isGhsa(id))) return record
|
|
219
203
|
const own = await aliasesOnGithub(record, cache)
|
|
@@ -223,8 +207,6 @@ async function apart(record, cache) {
|
|
|
223
207
|
return related.length > 0 ? { ...record, aliases: record.aliases.filter((id) => !isRelated(id)), related } : record
|
|
224
208
|
}
|
|
225
209
|
|
|
226
|
-
// Whether a version is `>=`, `<` or `<=` a bound, as an ecosystem orders
|
|
227
|
-
// them; undefined where it can't read either.
|
|
228
210
|
const MEETS = { '>=': (cmp) => cmp >= 0, '<': (cmp) => cmp < 0, '<=': (cmp) => cmp <= 0 }
|
|
229
211
|
const meetsBy = (isVersion, compare) => (version, operator, bound) => (isVersion(version) && isVersion(bound) ? MEETS[operator](compare(version, bound)) : undefined)
|
|
230
212
|
const semverMeets = meetsBy(isExactVersion, compareSemver)
|
|
@@ -273,16 +255,13 @@ const intervalsOf = (entries) => entries.flatMap((entry) => (Array.isArray(entry
|
|
|
273
255
|
// As GitHub writes a range, `>= 1.0.0, < 1.2.6`; `0` is the first version.
|
|
274
256
|
const written = ({ from, end }) => (end === undefined ? `>= ${from}` : [...(from === '0' ? [] : [`>= ${from}`]), end.join(' ')].join(', '))
|
|
275
257
|
|
|
276
|
-
//
|
|
277
|
-
// tell.
|
|
258
|
+
// Where the order can't tell, it may.
|
|
278
259
|
function mayHold(ecosystem, version, { type, from, end }) {
|
|
279
260
|
const meets = type === 'SEMVER' ? semverMeets : ORDERS[ecosystem]
|
|
280
261
|
if (meets === undefined) return true
|
|
281
262
|
return (from === '0' || meets(version, '>=', from) !== false) && (end === undefined || meets(version, ...end) !== false)
|
|
282
263
|
}
|
|
283
264
|
|
|
284
|
-
// OSV's ranges of a package, those holding one of the versions it reports,
|
|
285
|
-
// else all of them.
|
|
286
265
|
function rangeOf(ecosystem, entries, versions) {
|
|
287
266
|
const intervals = intervalsOf(entries)
|
|
288
267
|
const holding = intervals.filter((interval) => versions.some((version) => mayHold(ecosystem, version, interval)))
|
|
@@ -293,7 +272,7 @@ function rangeOf(ecosystem, entries, versions) {
|
|
|
293
272
|
// An entry names a package as OSV spells it; a Python one in any spelling
|
|
294
273
|
// PEP 503 normalizes alike, as it was asked.
|
|
295
274
|
const NAME_KEYS = { __proto__: null, PyPI: normalName }
|
|
296
|
-
const
|
|
275
|
+
export const isEntryOf = (ecosystem, name) => {
|
|
297
276
|
const key = NAME_KEYS[ecosystem] ?? ((each) => each)
|
|
298
277
|
return (entry) => entry?.package?.ecosystem === ecosystem && typeof entry.package.name === 'string' && key(entry.package.name) === key(name)
|
|
299
278
|
}
|
|
@@ -303,7 +282,7 @@ export function toAdvisory(ecosystem, name, versions, record, details) {
|
|
|
303
282
|
const ghsas = aliases.filter(isGhsa)
|
|
304
283
|
const ghsa = isGhsa(record.id) ? record.id : (ghsas.length === 1 ? ghsas[0] : undefined)
|
|
305
284
|
const vector = record.severity?.find?.((entry) => /^CVSS_V[34]$/u.test(entry?.type))?.score
|
|
306
|
-
const entries = Array.isArray(record.affected) ? record.affected.filter(
|
|
285
|
+
const entries = Array.isArray(record.affected) ? record.affected.filter(isEntryOf(ecosystem, name)) : []
|
|
307
286
|
const informational = entries[0]?.database_specific?.informational
|
|
308
287
|
return {
|
|
309
288
|
name,
|
|
@@ -322,10 +301,9 @@ export function toAdvisory(ecosystem, name, versions, record, details) {
|
|
|
322
301
|
}
|
|
323
302
|
}
|
|
324
303
|
|
|
325
|
-
// OSV's batch query answers ids only, each record fetched after
|
|
326
|
-
//
|
|
327
|
-
//
|
|
328
|
-
// group: each version is reported under its first, the rest its aliases.
|
|
304
|
+
// OSV's batch query answers ids only, each record fetched after and told apart unless `githubAliases` is false.
|
|
305
|
+
// Records of one advisory, naming each other as aliases, are one group: each version is reported under its
|
|
306
|
+
// first, the rest its aliases.
|
|
329
307
|
export async function osvRows({ osv }, asked, { details, cache, githubAliases = true }) {
|
|
330
308
|
const list = [...asked].flatMap(([name, versions]) => versions.map((version) => ({ name, version })))
|
|
331
309
|
const hits = new Map() // id -> name -> versions, in `list` order
|
|
@@ -5,22 +5,19 @@ import { allows, normalize, parseConstraints } from '@preventive/lockfile/compos
|
|
|
5
5
|
import { isGhsa, isStrings, matches, show } from '../args.js'
|
|
6
6
|
import { PACKAGIST, request } from '../http.js'
|
|
7
7
|
import { chunks } from '../pool.js'
|
|
8
|
-
import { advisoryUrl, isText, metrics } from './common.js'
|
|
8
|
+
import { advisoryUrl, isCve, isText, isUrl, metrics } from './common.js'
|
|
9
9
|
|
|
10
10
|
// What `composer audit` reads. Its `/` is needed: without it, a 404.
|
|
11
11
|
const ADVISORIES_URL = `${PACKAGIST}/api/security-advisories/`
|
|
12
12
|
// POSTed, as a name can be 256 characters.
|
|
13
13
|
const NAMES_PER_REQUEST = 100
|
|
14
14
|
const isPksa = matches(/^PKSA(?:-[\da-z]{4}){3}$/u)
|
|
15
|
-
const isCve = matches(/^CVE-\d{4}-\d{4,}$/u)
|
|
16
|
-
const isUrl = (text) => /^https?:$/u.test(URL.parse(text)?.protocol)
|
|
17
15
|
|
|
18
16
|
const isAdvisory = (advisory, name) => advisory && typeof advisory === 'object' && isPksa(advisory.advisoryId) && advisory.packageName === name
|
|
19
17
|
&& isText(advisory.title) && typeof advisory.affectedVersions === 'string'
|
|
20
18
|
&& [advisory.cve, advisory.link, advisory.severity].every((value) => value == null || typeof value === 'string')
|
|
21
19
|
&& Array.isArray(advisory.sources) && isStrings(advisory.sources.map((source) => source?.remoteId))
|
|
22
20
|
|
|
23
|
-
// Its one GHSA, from its sources or its link, where it has one.
|
|
24
21
|
function ghsaOf({ sources, link }) {
|
|
25
22
|
const ghsas = new Set([...sources.map((source) => source.remoteId), /\/(GHSA[\w-]+)$/u.exec(link ?? '')?.[1]].filter(isGhsa))
|
|
26
23
|
return ghsas.size === 1 ? [...ghsas][0] : undefined
|
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import { compareVersions as comparePypiVersions, isVersion as isPypiVersion, lowerBoundsBelow as pypiBoundsBelow, releaseOf as pypiRelease, readRange as readPypiRange } from '../pypi/version.js'
|
|
2
2
|
import { compareVersions as compareGemVersions, exclusionsOf, lowerBoundsBelow as gemBoundsBelow, releaseOf as gemRelease, isVersion as isGemVersion, meetsLowerBounds } from '../rubygems/version.js'
|
|
3
3
|
import { compareVersions as compareSemver, isExactVersion } from '../semver.js'
|
|
4
|
-
import { inRange, isOpenAbove, overlap } from './common.js'
|
|
4
|
+
import { inRange, isOpenAbove, npmRange, overlap } from './common.js'
|
|
5
5
|
|
|
6
|
-
// Of two releases, the number they first differ in, the major's or the
|
|
7
|
-
// minor's; -1 where neither does, as one line.
|
|
8
6
|
function lineAt(a, b) {
|
|
9
7
|
for (const at of [0, 1]) if ((a[at] ?? 0n) !== (b[at] ?? 0n)) return at
|
|
10
8
|
return -1
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
// A range with no end of its own, ended below the versions an advisory
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
// minor where the next patched version is of the same major; the highest
|
|
17
|
-
// of a line's patched versions ends it, and a line none ends stays in. A
|
|
18
|
-
// line the range begins below keeps what the range leaves out (a gem's
|
|
19
|
-
// `!=`). Any other range, or a list it can't read all of, is as given.
|
|
20
|
-
//
|
|
21
|
-
// So Next.js's GHSA-ggv3-7p47-pfv8, `>=9.5.0` patched in `16.1.7, 15.5.13`,
|
|
22
|
-
// is `>=9.5.0, < 15.5.13` and `>= 16.0.0-0, < 16.1.7`, as GitHub reviewed it.
|
|
11
|
+
// A range with no end of its own, ended below the versions an advisory names as patched: a range per release
|
|
12
|
+
// line (a major, or a minor where the next patched one is of its major), ended by its highest, a line none ends
|
|
13
|
+
// staying in and a gem's `!=` kept. Any other range, or a list it can't read all of, is as given.
|
|
23
14
|
function endBelow({ isVersion, compare, release, lowest, opensBelow, above, kept = () => [] }) {
|
|
24
15
|
return (range, patched) => {
|
|
25
16
|
const versions = typeof patched === 'string' && patched.length <= 1024 ? patched.split(',').map((part) => part.trim()) : []
|
|
@@ -44,17 +35,14 @@ function endBelow({ isVersion, compare, release, lowest, opensBelow, above, kept
|
|
|
44
35
|
}
|
|
45
36
|
}
|
|
46
37
|
|
|
47
|
-
// GitHub's `>= 1.0.0, < 1.2.6` is npm's without the commas.
|
|
48
|
-
const npm = (range) => range.replaceAll(',', ' ')
|
|
49
|
-
|
|
50
38
|
// A line from its lowest prerelease, `-0`.
|
|
51
39
|
export const boundSemverRange = endBelow({
|
|
52
40
|
isVersion: isExactVersion,
|
|
53
41
|
compare: compareSemver,
|
|
54
42
|
release: (version) => /^\d+\.\d+\.\d+/u.exec(version)[0].split('.').map(BigInt),
|
|
55
43
|
lowest: (release) => `${[...release, 0n, 0n].slice(0, 3).join('.')}-0`,
|
|
56
|
-
opensBelow: (range, version) => isOpenAbove(
|
|
57
|
-
above: (range, version) => inRange(version,
|
|
44
|
+
opensBelow: (range, version) => isOpenAbove(npmRange(range)) && overlap(npmRange(range), `< ${version}`),
|
|
45
|
+
above: (range, version) => inRange(version, npmRange(range)),
|
|
58
46
|
})
|
|
59
47
|
|
|
60
48
|
// From `.A`, below any letters a prerelease has: Ruby orders them by byte.
|
package/src/advisories/repos.js
CHANGED
|
@@ -14,11 +14,9 @@ import { githubRepoOfUrl } from '../remote.js'
|
|
|
14
14
|
|
|
15
15
|
const PACKAGES_AT_ONCE = 8
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
// month.
|
|
19
|
-
async function cachedRepos(dir, names, fetchMissing, cache) {
|
|
17
|
+
async function cachedRepos(dir, names, fetch, cache) {
|
|
20
18
|
const repos = await readRepos(dir, names, cache)
|
|
21
|
-
await addRepos(dir, repos, await
|
|
19
|
+
await addRepos(dir, repos, await fetchEach(names.filter((name) => !repos.has(name)), fetch), cache)
|
|
22
20
|
return repos
|
|
23
21
|
}
|
|
24
22
|
|
|
@@ -45,8 +43,7 @@ async function fetchSoldeerRepo(name) {
|
|
|
45
43
|
return githubRepoOfUrl(answer.data[0]?.github_url) ?? null
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
//
|
|
49
|
-
// CDN redirects to jsDelivr.
|
|
46
|
+
// Trunk's CDN redirects to jsDelivr.
|
|
50
47
|
async function fetchPodRepo(name, version) {
|
|
51
48
|
const url = buildUrl(COCOAPODS_CDN, specPath(name, version).map(encodeSegment))
|
|
52
49
|
const podspec = await request(url, { as: 'json', redirect: 'follow' }).catch(recover(isNotFound, null))
|
|
@@ -95,17 +92,15 @@ async function fetchPypiRepo(name, version) {
|
|
|
95
92
|
return links.map(([, url]) => repoOfLink(url)).find((repo) => repo !== undefined) ?? null
|
|
96
93
|
}
|
|
97
94
|
|
|
98
|
-
// From the newest version asked's document, kept for good; null where the
|
|
99
|
-
// registry hasn't that version.
|
|
100
95
|
async function npmRepo(name, version, cache) {
|
|
101
96
|
const json = await getVersionDocument('advisories', name, version, cache)
|
|
102
97
|
return (json && getRepo(json).github) ?? null
|
|
103
98
|
}
|
|
104
99
|
|
|
105
100
|
export const crateRepos = (names, { cache }) => lookUpCrateRepos('advisories', names, { cache })
|
|
106
|
-
export const composerRepos = (names, { cache }) => cachedRepos('composer/repos', names,
|
|
107
|
-
export const gemRepos = (names, { cache }) => cachedRepos('rubygems/repos', names,
|
|
108
|
-
export const pypiRepos = (names, { asked, cache }) => cachedRepos('pypi/repos', names, (
|
|
109
|
-
export const podRepos = (names, { asked, cache }) => cachedRepos('cocoapods/repos', names, (
|
|
101
|
+
export const composerRepos = (names, { cache }) => cachedRepos('composer/repos', names, fetchComposerRepo, cache)
|
|
102
|
+
export const gemRepos = (names, { cache }) => cachedRepos('rubygems/repos', names, fetchGemRepo, cache)
|
|
103
|
+
export const pypiRepos = (names, { asked, cache }) => cachedRepos('pypi/repos', names, (name) => fetchPypiRepo(name, asked.get(name).at(-1)), cache)
|
|
104
|
+
export const podRepos = (names, { asked, cache }) => cachedRepos('cocoapods/repos', names, (name) => fetchPodRepo(name, asked.get(name).at(-1)), cache)
|
|
110
105
|
export const npmRepos = (names, { asked, cache }) => fetchEach(names, (name) => npmRepo(name, asked.get(name).at(-1), cache))
|
|
111
|
-
export const soldeerRepos = (names, { cache }) => cachedRepos('soldeer/repos', names,
|
|
106
|
+
export const soldeerRepos = (names, { cache }) => cachedRepos('soldeer/repos', names, fetchSoldeerRepo, cache)
|
|
@@ -8,7 +8,7 @@ import { readJSON, readRecord, writeJSON, writeRecord } from '../cache.js'
|
|
|
8
8
|
import { pool } from '../pool.js'
|
|
9
9
|
import { compareVersions, readRange } from '../rubygems/version.js'
|
|
10
10
|
import { objectId } from '../tree.js'
|
|
11
|
-
import { advisoryUrl, detailsOf, isText, metrics, order } from './common.js'
|
|
11
|
+
import { advisoryUrl, detailsOf, isId, isText, isUrl, metrics, order } from './common.js'
|
|
12
12
|
|
|
13
13
|
// ruby-advisory-db: `gems/<gem>/<id>.yml`, what `bundler-audit` reads, and
|
|
14
14
|
// `rubies/<engine>/<id>.yml`, what `ruby-audit` does.
|
|
@@ -19,12 +19,9 @@ const LISTING_TTL_MS = 90 * 60 * 1000
|
|
|
19
19
|
const VERSION = 2
|
|
20
20
|
const FILES_AT_ONCE = 8
|
|
21
21
|
const FILE = /^(?<dir>gems|rubies)\/(?<name>[^/]+)\/(?<id>[\w.-]+)\.yml$/u
|
|
22
|
-
const isId = matches(/^(?=.{1,128}$)[A-Z][\dA-Z]*(?:-[\dA-Za-z]+)+$/u)
|
|
23
22
|
const isFile = (entry) => Array.isArray(entry) && entry.length === 4 && ['gems', 'rubies'].includes(entry[0]) && typeof entry[1] === 'string' && typeof entry[2] === 'string' && isSha(entry[3])
|
|
24
23
|
const isDigest = (value) => value?.v === VERSION && isId(value.id) && isStrings(value.aliases) && isText(value.title) && isStrings(value.unaffected) && isStrings(value.patched)
|
|
25
24
|
|
|
26
|
-
// Each advisory file's directory, gem or engine, id and blob, from one listing
|
|
27
|
-
// of the repository.
|
|
28
25
|
async function listRepository(github, cache) {
|
|
29
26
|
const kept = await readRecord('rubysec/index', 'gems', cache, LISTING_TTL_MS)
|
|
30
27
|
if (kept?.v === VERSION && isSha(kept.oid) && Array.isArray(kept.files) && kept.files.every(isFile)) return kept
|
|
@@ -49,7 +46,6 @@ function listing(github, cache) {
|
|
|
49
46
|
|
|
50
47
|
// One value or a list of them, as Array() reads it.
|
|
51
48
|
const list = (value) => (value == null ? [] : [value].flat())
|
|
52
|
-
// `CVE-2024-1` of `2024-1` and of `CVE-2024-1` alike.
|
|
53
49
|
const ids = (prefix, values) => values.filter((value) => value !== '').map((value) => (String(value).startsWith(prefix) ? String(value) : `${prefix}${value}`))
|
|
54
50
|
const score = (value) => (typeof value === 'number' ? value : (/^(?:\d+\.?\d*|\.\d+)$/u.test(value ?? '') ? Number(value) : undefined))
|
|
55
51
|
// bundler-audit's criticality, from a v3 score (or a v4's), else a v2's.
|
|
@@ -85,7 +81,7 @@ function digest(dir, name, file, yaml) {
|
|
|
85
81
|
aliases: [...new Set(all.filter(isId))].filter((other) => other !== id),
|
|
86
82
|
title: title ?? id,
|
|
87
83
|
...(description && { description }),
|
|
88
|
-
...(
|
|
84
|
+
...(isUrl(url) && { url }),
|
|
89
85
|
...((v3 ?? v2) !== undefined && { cvss: v3 ?? v2 }),
|
|
90
86
|
...(severity && { severity }),
|
|
91
87
|
unaffected,
|
|
@@ -125,7 +121,6 @@ function toRow(name, advisory, asked, details, versionOf) {
|
|
|
125
121
|
}
|
|
126
122
|
}
|
|
127
123
|
|
|
128
|
-
// The listing first, then the files of the asked names under `dir` alone.
|
|
129
124
|
export async function rubysecRows(github, asked, { details, cache }, dir = 'gems', versionOf = (version) => version) {
|
|
130
125
|
const { oid, files } = await listing(github, cache)
|
|
131
126
|
const wanted = files.filter(([under, name]) => under === dir && asked.has(name))
|
package/src/args.js
CHANGED
|
@@ -21,8 +21,7 @@ export const isRepoPath = (value) => isString(value, 4096) && value.split('/').e
|
|
|
21
21
|
const BAD_REF = /^$|[ ~^:?*[\\]|\.\.|@\{|^\/|\/$|\/\/|(?:^|\/)\.|\.lock(?:\/|$)|\.$/u
|
|
22
22
|
const isToken = matches(/^[!-~]+$/u)
|
|
23
23
|
// npm's rules for existing names: capitals allowed (JSONStream), the
|
|
24
|
-
// legacy `~'!()*` not
|
|
25
|
-
// npm's rule: an unscoped name starts with neither `.`, `_` nor `-`.
|
|
24
|
+
// legacy `~'!()*` not, and an unscoped name starts with neither `.`, `_` nor `-`.
|
|
26
25
|
const isPackageName = matches(/^(?=.{1,214}$)(?:@[\w.-]+\/[\w-]|[\dA-Za-z])[\w.-]*$/u)
|
|
27
26
|
|
|
28
27
|
export function printable(text) {
|
|
@@ -57,8 +56,6 @@ export function assertArgs(method, options, spec, name) {
|
|
|
57
56
|
for (const [key, check] of Object.entries(spec)) check?.(method, label(key), options[key])
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
// The names a resolve*Repos call is given, each checked and given once,
|
|
61
|
-
// and its options.
|
|
62
59
|
export function assertNames(method, what, names, options, assertName) {
|
|
63
60
|
assert.ok(isIterable(names), `${method}: ${what} must be an iterable of names`)
|
|
64
61
|
assertArgs(method, options, { cachedOnly: optional(assertBoolean) })
|
|
@@ -70,6 +67,8 @@ export function assertNames(method, what, names, options, assertName) {
|
|
|
70
67
|
export const assertBoolean = assertion('a boolean', (value) => typeof value === 'boolean')
|
|
71
68
|
export const assertNumber = assertion('a positive integer', (value) => Number.isSafeInteger(value) && value > 0)
|
|
72
69
|
export const assertLevels = assertion('a whole number of levels', (value) => Number.isSafeInteger(value) && value >= 0)
|
|
70
|
+
export const assertVersions = assertion('a non-empty array', (value) => Array.isArray(value) && value.length > 0)
|
|
71
|
+
export const assertOneOf = (values) => assertion(`one of ${[...values].join(', ')}`, (value) => values.has(value))
|
|
73
72
|
export const assertLine = assertion('a non-empty single line', (value) => isString(value, 1024) && value.trim() !== '')
|
|
74
73
|
// 65,536 is GitHub's own limit on a body.
|
|
75
74
|
export const assertText = assertion('text with no control characters', (value) => isString(value, 65_536, '\t\n\r'))
|
|
@@ -94,15 +93,12 @@ export const assertPackageVersion = assertion('an exact semver version', isExact
|
|
|
94
93
|
export const assertGhsa = assertion('a GHSA id', isGhsa)
|
|
95
94
|
export const assertCrateName = assertion('a crate name', matches(/^[A-Za-z][\w-]{0,63}$/u))
|
|
96
95
|
export const assertCrateVersion = assertion('a semver version', matches(/^(?=.{5,256}$)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][\dA-Za-z-]*))*)?(?:\+[\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*)?$/u))
|
|
97
|
-
// Soldeer's own rule for a name
|
|
98
|
-
// `-`, starting with one of them or `@`, ending with a letter or digit.
|
|
96
|
+
// Soldeer's own rule for a name.
|
|
99
97
|
export const assertSoldeerName = assertion('a Soldeer package name', matches(/^(?=.{3,100}$)[@\da-z][\da-z-]*[\da-z]$/u))
|
|
100
98
|
// Soldeer takes any version but an empty one. Its registry has semver
|
|
101
99
|
// (`5.7.0-rc.0`, `1.0.2-solc-0.8-simulate`), bare numbers and commit hashes.
|
|
102
100
|
export const assertSoldeerVersion = assertion('letters, digits, `.`, `_`, `+` and `-`', matches(/^(?=.{1,128}$)[\dA-Za-z][\w.+-]*$/u))
|
|
103
|
-
// A root's name as Podfile.lock has it, and @preventive/lockfile reads it
|
|
104
|
-
// printable ASCII but for spaces, parentheses, slashes and backslashes, no
|
|
105
|
-
// `.` first, which the spec linter refuses, and 1024 characters at most.
|
|
101
|
+
// A root's name as Podfile.lock has it, and @preventive/lockfile reads it; the spec linter refuses a `.` first.
|
|
106
102
|
export const assertPodName = assertion('a pod\'s root name', matches(/^(?=.{1,1024}$)(?!\.)[!-'*-.0-[\]-~]+$/u))
|
|
107
103
|
// Pod::Version's pattern, as Podfile.lock writes a version.
|
|
108
104
|
export const assertPodVersion = assertion('a CocoaPods version', matches(/^(?=.{1,256}$)\d+(?:\.[\dA-Za-z-]+)*(?:\+[\dA-Za-z.-]+)?$/u))
|
|
@@ -111,7 +107,6 @@ export const assertGemName = assertion('a gem name', matches(/^(?=.{1,256}$)(?=[
|
|
|
111
107
|
// As Gemfile.lock writes one: no `-`, which Bundler reads as the start of a
|
|
112
108
|
// platform.
|
|
113
109
|
export const assertGemVersion = assertion('a RubyGems version', (value) => isGemVersion(value) && !value.includes('-'))
|
|
114
|
-
// A package's name and version, as a registry's getters take them.
|
|
115
110
|
const assertNameVersion = (assertName, assertVersion) => (method, name, version) => {
|
|
116
111
|
assertName(method, 'name', name)
|
|
117
112
|
assertVersion(method, 'version', version)
|
package/src/attributes.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer'
|
|
2
2
|
|
|
3
|
-
// Whether git writes a file out with CRLF, from
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
// attribute line endings depend on refuses its file, and all below it.
|
|
3
|
+
// Whether git writes a file out with CRLF, from its tree's .gitattributes alone, as `git archive` and a checkout
|
|
4
|
+
// with no config read them. Only `*`, `*.ext`, name and path rules are read: any other that sets an attribute
|
|
5
|
+
// line endings depend on refuses its file, and all below it.
|
|
7
6
|
|
|
8
7
|
const RELEVANT = new Set(['text', 'crlf', 'eol', 'binary', 'ident', 'filter', 'working-tree-encoding'])
|
|
9
8
|
const BINARY = [['diff', false], ['merge', false], ['text', false]]
|