@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 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 (a
62
- // HEAD, unscoped names too) go to OSV; the rest, private ones above all,
63
- // go to the registry alone. The name decides, not the version: npm takes
64
- // down malicious versions but keeps their name. Public names are cached
65
- // for a month.
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 answer a HEAD for is taken as private (see `osv`). A repository renamed or
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preventive/upstream",
3
- "version": "1.5.0",
3
+ "version": "1.5.1",
4
4
  "description": "Minimal npm, crates.io, Soldeer, CocoaPods trunk, GitHub and git checkout clients",
5
5
  "type": "module",
6
6
  "exports": {
@@ -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
- const NAMES_AT_ONCE = 8
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: a HEAD with no token,
91
- // answered 2xx. Private packages and other registries' answer 404; any
92
- // other answer, or none, counts as private too, as in triage.
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 {