Skip to content

Don't fetch npm tarballs whose packument can't be read - #582

Merged
andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/npm-tarball-unverified
Oct 24, 2026
Merged

andrew merged 1 commit into
git-pkgs:mainfrom
simonchrz:fix/npm-tarball-unverified

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

An uncached npm tarball is verified against the dist.integrity (or dist.shasum) its packument declares. When the packument couldn't be read — the registry failed, or the document is over metadata_max_size — the tarball was fetched from the conventional URL with no expected digest and cached unverified, so every later client got that copy.

Now a download without a readable packument fails the same way a Composer download without metadata does: 502, or 404 when the registry says the package doesn't exist. Nothing is fetched or cached.

  • Tarballs already in the cache are unaffected; they were verified when stored.
  • A packument that lists the version without a usable checksum still falls back to an unverified fetch, as before.
  • Packages whose packument is over metadata_max_size can no longer be downloaded uncached; raise the limit for those.
  • For routed packages the route's metadata decides, as before; there is still no fallback to the default registry.

Tests: new TestNPMTarballWithoutMetadataIsNotFetched (registry 503, packument over metadata_max_size); TestNPMTarballMetadataFallback and TestNPMRoutedDownloadWithoutMetadataStaysOnRoute updated for the new behaviour; a few download tests that never served a packument now get an empty one.

An uncached tarball is checked against the integrity its packument
declares. When the packument couldn't be fetched or was refused, for
example because it is larger than metadata_max_size or the registry
answered 503, the download went ahead with no integrity at all, and
the unverified tarball was cached and served to every later client.

Without the packument the download now fails like the Composer one
does: 502, or 404 when the registry says the package doesn't exist.
Nothing is fetched or cached. Tarballs already in the cache are still
served, since they were verified when they were stored, and a packument
that lists the version without a usable checksum still falls back to
an unverified fetch as before.
@andrew
andrew merged commit cefdbe6 into git-pkgs:main Oct 24, 2026
6 checks passed
@simonchrz simonchrz added the breaking Changes behaviour users rely on; needs a minor release label Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Changes behaviour users rely on; needs a minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants