@preventive/upstream 1.5.0 → 1.5.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 +7 -6
- package/package.json +1 -1
- package/src/advisories/npm.js +17 -4
package/advisories.d.ts
CHANGED
|
@@ -58,11 +58,12 @@ export interface AdvisoryOptions {
|
|
|
58
58
|
// its id among an OSV record's id and aliases, is left to that row,
|
|
59
59
|
// which takes the record's ids among its aliases; the versions a record
|
|
60
60
|
// of the row's own id covers beyond the registry's range join it too.
|
|
61
|
-
// Only packages whose name npm's registry serves without a token (
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
61
|
+
// Only packages whose name npm's registry serves without a token (its
|
|
62
|
+
// latest version's document, else, where it has no `latest` tag, a HEAD
|
|
63
|
+
// of the package's; unscoped names too, 32 names at a time) go to OSV;
|
|
64
|
+
// the rest, private ones above all, go to the registry alone.
|
|
65
|
+
// The name decides, not the version: npm takes down malicious versions
|
|
66
|
+
// but keeps their name. Public names are cached for a month.
|
|
66
67
|
osv?: boolean
|
|
67
68
|
}
|
|
68
69
|
|
|
@@ -149,7 +150,7 @@ export interface Advisory {
|
|
|
149
150
|
// no GitHub repository, a repository gone or blocked, and one GitHub
|
|
150
151
|
// redirects anywhere but to a repository by its id, add nothing, and a
|
|
151
152
|
// GHSA OSV does not have adds no `details`. With `osv`, a name npm's
|
|
152
|
-
// registry doesn't
|
|
153
|
+
// registry doesn't serve without a token is taken as private (see `osv`). A repository renamed or
|
|
153
154
|
// transferred, which GitHub redirects to it by its id, is listed by the
|
|
154
155
|
// name it has now, as getRepo's `followRedirect` (github.js) finds it, its
|
|
155
156
|
// rows' `url` on it. Any other failure, a malformed answer, or one about
|
package/package.json
CHANGED
package/src/advisories/npm.js
CHANGED
|
@@ -13,7 +13,9 @@ import { npmRepos } from './repos.js'
|
|
|
13
13
|
const BULK_URL = buildUrl(NPM_REGISTRY, ['-', 'npm', 'v1', 'security', 'advisories', 'bulk'])
|
|
14
14
|
const NAMES_PER_REQUEST = 250
|
|
15
15
|
const GHSA_PAGE = 'https://github.com/advisories/'
|
|
16
|
-
|
|
16
|
+
// Names checked at once for whether they are public: each a small document,
|
|
17
|
+
// answered in about a tenth of a second.
|
|
18
|
+
const NAMES_AT_ONCE = 32
|
|
17
19
|
|
|
18
20
|
const isRow = (row) => row && typeof row === 'object' && Number.isSafeInteger(row.id)
|
|
19
21
|
&& ['url', 'severity', 'vulnerable_versions'].every((key) => typeof row[key] === 'string') && isText(row.title)
|
|
@@ -87,10 +89,21 @@ function withOsv(registry, osv) {
|
|
|
87
89
|
return [...rows, ...added]
|
|
88
90
|
}
|
|
89
91
|
|
|
90
|
-
// Whether npm's registry serves `name` to anyone:
|
|
91
|
-
//
|
|
92
|
-
// other answer, or none, counts as private too,
|
|
92
|
+
// Whether npm's registry serves `name` to anyone: its latest version's
|
|
93
|
+
// document, for that name, read with no token. Private packages and other
|
|
94
|
+
// registries' answer 404; any other answer, or none, counts as private too,
|
|
95
|
+
// as in triage. That document first, as npm answers a HEAD of the package's
|
|
96
|
+
// in two seconds or more about one time in ten; but a 404 for it may only
|
|
97
|
+
// mean no `latest` tag (a package published with `--tag` alone, or one
|
|
98
|
+
// unpublished whole, its name kept), so then the package's document, a HEAD
|
|
99
|
+
// with no token, decides.
|
|
93
100
|
async function servesAnyone(name) {
|
|
101
|
+
try {
|
|
102
|
+
const json = await request(buildUrl(NPM_REGISTRY, [...name.split('/'), 'latest']), { as: 'json' })
|
|
103
|
+
return json?.name === name
|
|
104
|
+
} catch (err) {
|
|
105
|
+
if (!isNotFound(err)) return false
|
|
106
|
+
}
|
|
94
107
|
try {
|
|
95
108
|
return await answersHead(buildUrl(NPM_REGISTRY, name.split('/')))
|
|
96
109
|
} catch {
|