@preventive/upstream 1.12.0 → 1.13.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 +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 +150 -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 +10 -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/npm.d.ts
CHANGED
|
@@ -1,110 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/**
|
|
2
|
+
* npm's registry: versions' documents and tarballs, held to their integrity, and packages' GitHub repos
|
|
3
|
+
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { getMeta, getTarball, resolvePackageRepos, setCacheDir } from '@preventive/upstream/npm.js'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* `setCacheDir()` sets where every module of this package caches: nothing is written to a cache until it is called.
|
|
9
|
+
* Names and versions are checked before any request. A scoped package is read with its scope's own token where it
|
|
10
|
+
* is set, `ACME_CORP_NPM_TOKEN` for `@acme-corp/x` (`.` and `-` read as `_`; `@stasis` has none, as `STASIS_NPM_TOKEN`
|
|
11
|
+
* is for every scope), else with `PREVENTIVE_MEASURES_NPM_TOKEN`, `STASIS_NPM_TOKEN` or `NPM_TOKEN`, the first set.
|
|
12
|
+
*
|
|
13
|
+
* @module @preventive/upstream/npm.js
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A caller's store in place of `setCacheDir()`'s directory, and as trusted
|
|
18
|
+
*
|
|
19
|
+
* `read` answers what `write` last stored under `type` and `key`, or null. Values are JSON values, a download's a
|
|
20
|
+
* `Uint8Array`.
|
|
21
|
+
*/
|
|
20
22
|
export interface CacheStore {
|
|
21
|
-
read(type: string, key: string): Promise<unknown
|
|
22
|
-
write(type: string, key: string, value: unknown): Promise<void
|
|
23
|
+
read(type: string, key: string): Promise<unknown>;
|
|
24
|
+
write(type: string, key: string, value: unknown): Promise<void>;
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
// place, or `false` for none.
|
|
27
|
+
/** Where a call caches */
|
|
27
28
|
export interface CacheOptions {
|
|
28
|
-
cache
|
|
29
|
+
/** Default: `setCacheDir()`'s cache. A store takes its place; `false` still reads it, but writes nothing. */
|
|
30
|
+
cache?: CacheStore | false;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
/** A version's tarball and its integrity, as a lockfile records them */
|
|
34
|
+
export interface Dist {
|
|
35
|
+
/** Exactly the registry's own URL for the version's tarball */
|
|
36
|
+
tarball: string;
|
|
37
|
+
/** One `sha512-<base64>` */
|
|
38
|
+
integrity: string;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
directory?: string
|
|
44
|
-
url: string
|
|
41
|
+
/** What `getMeta()` may answer from, and where it caches */
|
|
42
|
+
export interface MetaOptions extends CacheOptions {
|
|
43
|
+
/** One the caller already has, as a lockfile gives it */
|
|
44
|
+
dist?: Dist;
|
|
45
45
|
}
|
|
46
|
-
export function getGitHub(name: string): Promise<GitHubLink>
|
|
47
46
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
/** `repository` given as an object */
|
|
48
|
+
export interface PackageRepository {
|
|
49
|
+
type: string | undefined;
|
|
50
|
+
url: string | undefined;
|
|
51
|
+
directory: string | undefined;
|
|
51
52
|
}
|
|
52
|
-
// A name that resolves to no repo is left out. `cachedOnly` never fetches.
|
|
53
|
-
export function resolvePackageRepos(packageNames: Iterable<string>, options?: { cachedOnly?: boolean }): Promise<Map<string, PackageRepo>>
|
|
54
|
-
|
|
55
|
-
// resolvePackageRepos' disk cache, a month an entry: a read answers null for
|
|
56
|
-
// nothing usable, a write false where it couldn't write.
|
|
57
|
-
export function readPackageRepoCache(name: string): Promise<PackageRepo | null>
|
|
58
|
-
export function writePackageRepoCache(name: string, github: string, directory?: string): Promise<boolean>
|
|
59
53
|
|
|
60
|
-
|
|
61
|
-
export interface
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
/** `bugs` given as an object */
|
|
55
|
+
export interface PackageBugs {
|
|
56
|
+
url: string | undefined;
|
|
57
|
+
email: string | undefined;
|
|
64
58
|
}
|
|
65
59
|
|
|
66
|
-
|
|
67
|
-
|
|
60
|
+
/**
|
|
61
|
+
* A version's registry document, as far as it is read here
|
|
62
|
+
*
|
|
63
|
+
* All of it the publisher's word, held to no repository or tarball. A field missing or not of its shape is absent.
|
|
64
|
+
*/
|
|
68
65
|
export interface PackageMeta {
|
|
69
|
-
name: string
|
|
70
|
-
version: string
|
|
71
|
-
dist: Dist
|
|
72
|
-
gitHead?: string
|
|
73
|
-
repository?: string | PackageRepository
|
|
74
|
-
homepage?: string
|
|
75
|
-
bugs?: string | PackageBugs
|
|
76
|
-
unpackedSize?: number
|
|
66
|
+
name: string;
|
|
67
|
+
version: string;
|
|
68
|
+
dist: Dist;
|
|
69
|
+
gitHead?: string;
|
|
70
|
+
repository?: string | PackageRepository;
|
|
71
|
+
homepage?: string;
|
|
72
|
+
bugs?: string | PackageBugs;
|
|
73
|
+
unpackedSize?: number;
|
|
77
74
|
}
|
|
78
75
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
/** Where a package's GitHub repo is */
|
|
77
|
+
export interface GitHubLink {
|
|
78
|
+
/** `owner/name` */
|
|
79
|
+
github: string;
|
|
80
|
+
/** Where in the repo the package sits, `''` at its root; absent where unknown */
|
|
81
|
+
directory?: string;
|
|
82
|
+
/** `https://github.com/<github>` */
|
|
83
|
+
url: string;
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
/** Where a package's GitHub repo is, as `resolvePackageRepos()` finds it */
|
|
87
|
+
export interface PackageRepo {
|
|
88
|
+
/** `owner/name` */
|
|
89
|
+
github: string;
|
|
90
|
+
/** Where in the repo the package sits, `''` at its root; absent where unknown */
|
|
91
|
+
directory?: string;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
|
-
|
|
91
|
-
export
|
|
92
|
-
|
|
94
|
+
/** A failed request: `status` is the HTTP status, 404 for a package or version the registry hasn't */
|
|
95
|
+
export class HttpError extends Error {
|
|
96
|
+
name: 'HttpError';
|
|
97
|
+
status: number;
|
|
98
|
+
headers?: Headers;
|
|
93
99
|
}
|
|
94
100
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
export function
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
export
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
101
|
+
/**
|
|
102
|
+
* The platform's cache directory for a program called `name`, or undefined without an absolute home
|
|
103
|
+
*
|
|
104
|
+
* Nothing is made.
|
|
105
|
+
*
|
|
106
|
+
* @param name - 6 to 32 of a-z, A-Z, 0-9, `_` and `-`
|
|
107
|
+
*/
|
|
108
|
+
export function cacheDirFor(name: string): string | undefined;
|
|
109
|
+
|
|
110
|
+
/** `cacheDirFor('PreventiveMeasures')`, where `setCacheDir()` caches by default */
|
|
111
|
+
export const defaultCacheDir: string | undefined;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Set where this package caches, `false` for nowhere
|
|
115
|
+
*
|
|
116
|
+
* What is cached is trusted, so point it only at storage nothing less trusted can write.
|
|
117
|
+
*
|
|
118
|
+
* @param dir - Default: `defaultCacheDir`, which throws where there is none
|
|
119
|
+
*/
|
|
120
|
+
export function setCacheDir(dir?: string | false): void;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* A version's registry document, refused unless it is that version's and, where `dist` is given, has that `dist`
|
|
124
|
+
*
|
|
125
|
+
* With `dist`, npm's own cache or ours may answer with no request; without, the registry is always asked. Cached
|
|
126
|
+
* for good.
|
|
127
|
+
*/
|
|
128
|
+
export function getMeta(name: string, version: string, options?: MetaOptions): Promise<PackageMeta>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* When each version was published, as `Date#toISOString` writes it; versions without a valid time are left out
|
|
132
|
+
*
|
|
133
|
+
* Reads the whole package's document, megabytes for some, on every call.
|
|
134
|
+
*/
|
|
135
|
+
export function getPublishTimes(name: string): Promise<Map<string, string>>;
|
|
136
|
+
|
|
137
|
+
/** Throw unless `dist` is that version's on the registry; a cached document may confirm it with no request */
|
|
138
|
+
export function verifyDist(name: string, version: string, dist: Dist, options?: CacheOptions): Promise<void>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A published version's gzipped tarball, held to its integrity
|
|
142
|
+
*
|
|
143
|
+
* npm's own caches, and this package's and stasis's default ones, are read first and never written: one there that
|
|
144
|
+
* does not match is passed over. One in `setCacheDir()`'s cache (or `cache`) that does not match throws. Without
|
|
145
|
+
* `dist`, the registry is asked for it on every call, tarball cached or not.
|
|
146
|
+
*/
|
|
147
|
+
export function getTarball(name: string, version: string, dist?: Dist, options?: CacheOptions): Promise<Uint8Array>;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The GitHub repo a package's `latest` version names, and where in it the package sits
|
|
151
|
+
*
|
|
152
|
+
* Read as `getRepo()` (package.js) reads it, on every call.
|
|
153
|
+
*
|
|
154
|
+
* @throws Where it names none
|
|
155
|
+
*/
|
|
156
|
+
export function getGitHub(name: string): Promise<GitHubLink>;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Each package's GitHub repo, as `getGitHub()` finds it, cached a month in `setCacheDir()`'s cache
|
|
160
|
+
*
|
|
161
|
+
* A name that resolves to no repo, or whose lookup fails, is left out. `cachedOnly` answers from the cache alone
|
|
162
|
+
* and never fetches.
|
|
163
|
+
*/
|
|
164
|
+
export function resolvePackageRepos(
|
|
165
|
+
packageNames: Iterable<string>,
|
|
166
|
+
options?: { cachedOnly?: boolean }
|
|
167
|
+
): Promise<Map<string, PackageRepo>>;
|
|
168
|
+
|
|
169
|
+
/** Read `resolvePackageRepos()`'s cache: null where it holds nothing usable, as for an entry over a month old */
|
|
170
|
+
export function readPackageRepoCache(name: string): Promise<PackageRepo | null>;
|
|
171
|
+
|
|
172
|
+
/** Write `resolvePackageRepos()`'s cache: false where it could not, as without `setCacheDir()` */
|
|
173
|
+
export function writePackageRepoCache(name: string, github: string, directory?: string): Promise<boolean>;
|
package/package.d.ts
CHANGED
|
@@ -1,19 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A package's GitHub repo, read off its package.json or a registry document of a version
|
|
3
|
+
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { getRepo } from '@preventive/upstream/package.js'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* @module @preventive/upstream/package.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Where a package's GitHub repo is */
|
|
1
12
|
export interface PackageRepoLink {
|
|
2
|
-
|
|
3
|
-
github?: string
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
directory?: string
|
|
11
|
-
|
|
12
|
-
url?: string
|
|
13
|
+
/** `owner/name`, by GitHub's own rules */
|
|
14
|
+
github?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Where in the repo the package sits, as a tree path: `/`-separated, decoded, `''` at its root
|
|
17
|
+
*
|
|
18
|
+
* From `repository.directory`, else a homepage's `tree/<ref>/` path; absent where neither names one in the repo
|
|
19
|
+
* (a `..` names none).
|
|
20
|
+
*/
|
|
21
|
+
directory?: string;
|
|
22
|
+
/** `https://github.com/<github>` */
|
|
23
|
+
url?: string;
|
|
13
24
|
}
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The GitHub repo `pkg` names in `repository`, `bugs` or `homepage`, the first that does
|
|
28
|
+
*
|
|
29
|
+
* Empty where none does.
|
|
30
|
+
*
|
|
31
|
+
* @throws Unless `pkg` is an object, and not an array
|
|
32
|
+
*/
|
|
33
|
+
export function getRepo(pkg: object): PackageRepoLink;
|
package/package.json
CHANGED
package/rubygems.d.ts
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* rubygems.org: .gem files held to their checksums
|
|
3
|
+
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { getGem, verifyChecksum } from '@preventive/upstream/rubygems.js'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Names, versions, platforms (`ruby` for none) and checksums are checked before any request, and pass as
|
|
9
|
+
* `@preventive/lockfile`'s `BundlerSpec` has them. A checksum is a sha256 in lowercase hex, bare or after `sha256=`.
|
|
10
|
+
*
|
|
11
|
+
* @module @preventive/upstream/rubygems.js
|
|
12
|
+
*/
|
|
4
13
|
|
|
5
|
-
export { HttpError } from './npm.js'
|
|
14
|
+
export { HttpError } from './npm.js';
|
|
6
15
|
|
|
7
|
-
|
|
8
|
-
export function verifyChecksum(name: string, version: string, platform: string, checksum: string): Promise<void
|
|
16
|
+
/** Throw unless the compact index has `checksum` for that version and platform; nothing is cached */
|
|
17
|
+
export function verifyChecksum(name: string, version: string, platform: string, checksum: string): Promise<void>;
|
|
9
18
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* A published .gem, held to `checksum`, else to the compact index's
|
|
21
|
+
*
|
|
22
|
+
* RubyGems' own caches (each gem directory's `cache/`) are read first and never written; `setCacheDir()`'s (npm.js)
|
|
23
|
+
* is written.
|
|
24
|
+
*/
|
|
25
|
+
export function getGem(name: string, version: string, platform: string, checksum?: string): Promise<Uint8Array>;
|
package/semver.d.ts
CHANGED
|
@@ -1,19 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
/**
|
|
2
|
+
* npm's own semver, borrowed from the npm beside node and passed through as it is
|
|
3
|
+
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { compareVersions, satisfies, valid } from '@preventive/upstream/semver.js'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* Where there is no npm, the `semver` package, an optional peer dependency. Without either, every call throws, but
|
|
9
|
+
* `valid()` and `isExactVersion()` on a plain `MAJOR.MINOR.PATCH` with no options.
|
|
10
|
+
*
|
|
11
|
+
* @module @preventive/upstream/semver.js
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** Whether `version` is in `range` */
|
|
15
|
+
export function satisfies(
|
|
16
|
+
version: string,
|
|
17
|
+
range: string,
|
|
18
|
+
options?: { includePrerelease?: boolean; loose?: boolean }
|
|
19
|
+
): boolean;
|
|
20
|
+
|
|
21
|
+
/** -1, 0 or 1 as `a` is below, equal to or above `b`; throws for one that is not a version */
|
|
22
|
+
export function compareVersions(a: string, b: string, options?: { loose?: boolean }): -1 | 0 | 1;
|
|
23
|
+
|
|
24
|
+
/** The version as semver spells it, or null: `v1.2.3` answers `1.2.3` */
|
|
25
|
+
export function valid(version: unknown, options?: { loose?: boolean }): string | null;
|
|
26
|
+
|
|
27
|
+
/** Whether `version` is a string `valid()` answers unchanged */
|
|
28
|
+
export function isExactVersion(version: unknown): version is string;
|
|
29
|
+
|
|
30
|
+
/** The range as semver normalizes it, or null where it is not one */
|
|
31
|
+
export function validRange(range: unknown, options?: { loose?: boolean; includePrerelease?: boolean }): string | null;
|
|
32
|
+
|
|
33
|
+
/** Whether some version is in both ranges; throws for one that is not a range */
|
|
34
|
+
export function intersects(a: string, b: string, options?: { loose?: boolean; includePrerelease?: boolean }): boolean;
|
|
35
|
+
|
|
36
|
+
/** The version as semver cleans it, spaces and a leading `=` or `v` dropped, or null: ` =v1.2.3 ` answers `1.2.3` */
|
|
37
|
+
export function clean(version: string, options?: { loose?: boolean } | boolean): string | null;
|
|
38
|
+
|
|
39
|
+
/** The version's major; throws for one that is not a version */
|
|
40
|
+
export function major(version: string, options?: { loose?: boolean } | boolean): number;
|
package/soldeer.d.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Soldeer's registry: a version's zip, held to its checksum
|
|
3
|
+
*
|
|
4
|
+
* ```js
|
|
5
|
+
* import { getZip } from '@preventive/upstream/soldeer.js'
|
|
6
|
+
* ```
|
|
7
|
+
*
|
|
8
|
+
* @module @preventive/upstream/soldeer.js
|
|
9
|
+
*/
|
|
5
10
|
|
|
6
|
-
export { HttpError } from './npm.js'
|
|
11
|
+
export { HttpError } from './npm.js';
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* A version's zip from Soldeer's registry, held to `checksum`
|
|
15
|
+
*
|
|
16
|
+
* Cached in `setCacheDir()`'s cache (npm.js), where a zip that does not match throws and one that matches is
|
|
17
|
+
* answered with no request at all.
|
|
18
|
+
*
|
|
19
|
+
* @param name - A name Soldeer takes
|
|
20
|
+
* @param version - Letters, digits, `.`, `_`, `+` and `-`
|
|
21
|
+
* @param checksum - The zip's sha256 in lowercase hex, as soldeer.lock records it
|
|
22
|
+
*/
|
|
23
|
+
export function getZip(name: string, version: string, checksum: string): Promise<Uint8Array>;
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { assertRepo, assertion, isRefName, isSha } from '../args.js'
|
|
2
|
-
import { readRecord, writeRecord } from '../cache.js'
|
|
3
2
|
import { GITHUB_WEB, HttpError, buildUrl, send } from '../http.js'
|
|
4
|
-
import { pool } from '../pool.js'
|
|
5
3
|
import { valid, validRange } from '../semver.js'
|
|
6
|
-
import { inRange, overlap } from './common.js'
|
|
4
|
+
import { inRange, overlap, publicOnly } from './common.js'
|
|
7
5
|
import { bySemver, coversPlaceholder, repositoryAdvisories } from './github.js'
|
|
8
|
-
import { RECORDS_AT_ONCE, packageRecords, toAdvisory } from './osv.js'
|
|
6
|
+
import { RECORDS_AT_ONCE, isEntryOf, packageRecords, toAdvisory } from './osv.js'
|
|
9
7
|
|
|
10
8
|
const ACTIONS = 'GitHub Actions'
|
|
11
9
|
|
|
10
|
+
const isPartial = (tag) => /^\d+(?:\.\d+)?$/u.test(tag)
|
|
12
11
|
// OSV's `1.2` is 1.2.0, not semver's 1.2.x.
|
|
13
|
-
const full = (version) => (
|
|
12
|
+
const full = (version) => (isPartial(version) ? `${version}.0.0`.split('.').slice(0, 3).join('.') : version)
|
|
14
13
|
|
|
15
14
|
// OSV can't match these versions itself: its records' ECOSYSTEM ranges, as
|
|
16
15
|
// semver's, and whether one is still open, no release having fixed it.
|
|
@@ -38,8 +37,6 @@ function readAffected(entry) {
|
|
|
38
37
|
return { listed, range, open, all: validRange(range, { loose: true }) === null }
|
|
39
38
|
}
|
|
40
39
|
|
|
41
|
-
const isPartial = (tag) => /^\d+(?:\.\d+)?$/u.test(tag)
|
|
42
|
-
|
|
43
40
|
// A commit may be of any release. A branch, or stasis's 0.0.0, is at its
|
|
44
41
|
// newest, so only what no release has fixed covers it. A moving tag, `v4`
|
|
45
42
|
// or `v4.1`, may be anywhere in its line.
|
|
@@ -56,7 +53,7 @@ async function actionRows(asked, details) {
|
|
|
56
53
|
const rows = []
|
|
57
54
|
for (const { record, names } of await packageRecords(ACTIONS, [...asked.keys()])) {
|
|
58
55
|
for (const name of names) {
|
|
59
|
-
const entries = (record.affected ?? []).filter((
|
|
56
|
+
const entries = (record.affected ?? []).filter(isEntryOf(ACTIONS, name)).map(readAffected)
|
|
60
57
|
const versions = asked.get(name).filter((version) => entries.some((entry) => covers(version, entry)))
|
|
61
58
|
if (versions.length > 0) rows.push(toAdvisory(ACTIONS, name, versions, record, details))
|
|
62
59
|
}
|
|
@@ -64,17 +61,12 @@ async function actionRows(asked, details) {
|
|
|
64
61
|
return rows
|
|
65
62
|
}
|
|
66
63
|
|
|
67
|
-
// What github.com answers for a repository it serves to
|
|
68
|
-
//
|
|
69
|
-
// one's redirect, which is not followed. 404 too.
|
|
64
|
+
// What github.com answers without credentials for a repository it serves to
|
|
65
|
+
// no one: a private, internal or gone one (401, 404), or a moved one's redirect.
|
|
70
66
|
const NOT_SERVED = new Set([301, 302, 307, 308, 401, 404])
|
|
71
67
|
|
|
72
|
-
//
|
|
73
|
-
//
|
|
74
|
-
// which answers with its capabilities alone, a few hundred bytes, not every
|
|
75
|
-
// ref. Any other answer (a 403 or 429 of a rate limit, a 5xx) or a failure
|
|
76
|
-
// throws, before OSV is asked anything. A HEAD is refused (403): a GET, its
|
|
77
|
-
// body left unread.
|
|
68
|
+
// Asked as `git ls-remote` asks over protocol v2, whose ref advertisement is its capabilities alone: by a GET
|
|
69
|
+
// left unread, as a HEAD is refused (403).
|
|
78
70
|
async function servesAnyone(repo) {
|
|
79
71
|
const [owner, name] = repo.split('/')
|
|
80
72
|
const url = buildUrl(GITHUB_WEB, [owner, `${name}.git`, 'info', 'refs'], { service: 'git-upload-pack' })
|
|
@@ -85,27 +77,10 @@ async function servesAnyone(repo) {
|
|
|
85
77
|
throw new HttpError(res.status, `GET ${url} ${res.status}`, res.headers)
|
|
86
78
|
}
|
|
87
79
|
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
// ones are kept, a month, by the name in lowercase, as GitHub takes it in
|
|
91
|
-
// any case; one not public is asked again each time, so one made public is
|
|
92
|
-
// asked of OSV as soon as it is.
|
|
93
|
-
async function publicOnly(asked, cache) {
|
|
94
|
-
const names = [...asked.keys()]
|
|
95
|
-
const kept = await pool(names, RECORDS_AT_ONCE, (name) => readRecord('github/public', name.toLowerCase(), cache))
|
|
96
|
-
const serving = new Set(names.filter((name, i) => kept[i]?.public === true))
|
|
97
|
-
const missing = names.filter((name) => !serving.has(name))
|
|
98
|
-
const found = await pool(missing, RECORDS_AT_ONCE, servesAnyone)
|
|
99
|
-
const added = missing.filter((name, i) => found[i])
|
|
100
|
-
await pool(added, RECORDS_AT_ONCE, (name) => writeRecord('github/public', name.toLowerCase(), { public: true }, cache))
|
|
101
|
-
for (const name of added) serving.add(name)
|
|
102
|
-
return new Map([...asked].filter(([name]) => serving.has(name)))
|
|
103
|
-
}
|
|
80
|
+
// Kept by the name in lowercase, as GitHub takes it in any case.
|
|
81
|
+
const PUBLIC = { dir: 'github/public', atOnce: RECORDS_AT_ONCE, serves: servesAnyone, key: (name) => name.toLowerCase() }
|
|
104
82
|
|
|
105
|
-
//
|
|
106
|
-
// those github.com serves to anyone (publicOnly) but those `internal`, which
|
|
107
|
-
// are not asked of it either; and every range their own advisories list,
|
|
108
|
-
// whichever package it names.
|
|
83
|
+
// A repository's own advisories count every range they list, whichever package it names.
|
|
109
84
|
export const GITHUB = {
|
|
110
85
|
repositoryOnly: true,
|
|
111
86
|
assertName: assertRepo,
|
|
@@ -115,7 +90,7 @@ export const GITHUB = {
|
|
|
115
90
|
const external = new Map(asked)
|
|
116
91
|
for (const name of internal) external.delete(name)
|
|
117
92
|
return (await Promise.all([
|
|
118
|
-
publicOnly(external, cache).then((open) => actionRows(open, details)),
|
|
93
|
+
publicOnly(external, cache, PUBLIC).then((open) => actionRows(open, details)),
|
|
119
94
|
repositoryAdvisories(github, asked, { repoOf: (repo) => repo, versionsIn: bySemver(coversPlaceholder), details, cache }),
|
|
120
95
|
])).flat()
|
|
121
96
|
},
|
package/src/advisories/common.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import assert from 'node:assert/strict'
|
|
2
2
|
|
|
3
3
|
import { isGhsa, isRepo, isStrings, matches, show } from '../args.js'
|
|
4
|
+
import { readRecord, writeRecord } from '../cache.js'
|
|
5
|
+
import { pool } from '../pool.js'
|
|
4
6
|
import { intersects, satisfies, valid, validRange } from '../semver.js'
|
|
5
7
|
|
|
6
8
|
export const order = (a, b) => (a > b) - (a < b)
|
|
9
|
+
// An id as OSV and ruby-advisory-db write one.
|
|
10
|
+
export const isId = matches(/^(?=.{1,128}$)[A-Z][\dA-Z]*(?:-[\dA-Za-z]+)+$/u)
|
|
11
|
+
export const isCve = matches(/^CVE-\d{4}-\d{4,}$/u)
|
|
12
|
+
export const isUrl = (text) => /^https?:$/u.test(URL.parse(text)?.protocol)
|
|
7
13
|
|
|
8
|
-
// The repository's page for a GHSA where `repo` is given, else the database's.
|
|
9
14
|
export function advisoryUrl(ghsa, repo) {
|
|
10
15
|
assert.ok(isGhsa(ghsa) && (repo === undefined || isRepo(repo)), `advisories: no GitHub advisory page for ${show(ghsa)} on ${show(repo)}`)
|
|
11
16
|
return repo === undefined ? `https://github.com/advisories/${ghsa}` : `https://github.com/${repo}/security/advisories/${ghsa}`
|
|
@@ -29,6 +34,16 @@ export const isOpenAbove = (range) => !range.includes('|') && inRange(HIGHEST, r
|
|
|
29
34
|
// advisory is worse than a spare one.
|
|
30
35
|
export const covered = (asked, range, covers = mayBeInRange) => (validRange(range, SEMVER) === null ? [...asked] : asked.filter((version) => covers(version, range)))
|
|
31
36
|
|
|
37
|
+
// The same by an ecosystem's own readRange, undefined for a range it can't
|
|
38
|
+
// read, each version tested as `of` reads it.
|
|
39
|
+
export const coveredBy = (readRange, of = (version) => version) => (asked, range) => {
|
|
40
|
+
const test = readRange(range)
|
|
41
|
+
return test === undefined ? [...asked] : asked.filter((version) => test(of(version)))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// GitHub's `>= 1.0.0, < 1.2.6` is npm's without the commas.
|
|
45
|
+
export const npmRange = (range) => range.replaceAll(',', ' ')
|
|
46
|
+
|
|
32
47
|
export const isText = (value) => typeof value === 'string' && value.isWellFormed()
|
|
33
48
|
|
|
34
49
|
export function detailsOf(text, id) {
|
|
@@ -56,3 +71,16 @@ export function metrics({ severity, score, vector, cwe }) {
|
|
|
56
71
|
cwe: isStrings(cwe) ? cwe.filter(isCwe) : [],
|
|
57
72
|
}
|
|
58
73
|
}
|
|
74
|
+
|
|
75
|
+
// Only public ones are kept: one not public is asked again each time, so one made public is asked of OSV at once.
|
|
76
|
+
export async function publicOnly(asked, cache, { dir, atOnce, serves, key = (name) => name }) {
|
|
77
|
+
const names = [...asked.keys()]
|
|
78
|
+
const kept = await pool(names, atOnce, (name) => readRecord(dir, key(name), cache))
|
|
79
|
+
const serving = new Set(names.filter((name, i) => kept[i]?.public === true))
|
|
80
|
+
const missing = names.filter((name) => !serving.has(name))
|
|
81
|
+
const found = await pool(missing, atOnce, serves)
|
|
82
|
+
const added = missing.filter((name, i) => found[i])
|
|
83
|
+
await pool(added, atOnce, (name) => writeRecord(dir, key(name), { public: true }, cache))
|
|
84
|
+
for (const name of added) serving.add(name)
|
|
85
|
+
return new Map([...asked].filter(([name]) => serving.has(name)))
|
|
86
|
+
}
|