Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Harrison <[email protected]>
  • Loading branch information
feelepxyz committed Nov 30, 2023
1 parent f3723d4 commit c1bddd3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const sigstore = require('sigstore')
const corgiDoc = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'
const fullDoc = 'application/json'

// Some really old packages have no time field in their packument so we need to
// fallback to a time that is before we could have a registry rotate keys. This
// is snapped to just before we shipped `npm audit signatures` in 8.14.0.
const NO_TIME_CUTOFF_TIME = '2022-07-12T00:00:00.000Z'
// Some really old packages have no time field in their packument so we need a
// cutoff date.
const MISSING_TIME_CUTOFF = '2015-01-01T00:00:00.000Z'

const fetch = require('npm-registry-fetch')

Expand Down Expand Up @@ -120,6 +119,13 @@ class RegistryFetcher extends Fetcher {
return this.package
}

// When verifying signatures, we need to fetch the full/uncompressed
// packument to get publish time as this is not included in the
// corgi/compressed packument.
if (this.opts.verifySignatures) {
this.fullMetadata = true
}

const packument = await this.packument()
let mani = await pickManifest(packument, this.spec.fetchSpec, {
...this.opts,
Expand Down Expand Up @@ -184,7 +190,7 @@ class RegistryFetcher extends Fetcher {
), { code: 'EMISSINGSIGNATUREKEY' })
}

const publishedTime = Date.parse(mani._time || NO_TIME_CUTOFF_TIME)
const publishedTime = Date.parse(mani._time || MISSING_TIME_CUTOFF)
const validPublicKey = !publicKey.expires ||
publishedTime < Date.parse(publicKey.expires)
if (!validPublicKey) {
Expand Down

0 comments on commit c1bddd3

Please sign in to comment.