fix(npm): download tarballs from the configured registry instead of registry.npmjs.org#36187
fix(npm): download tarballs from the configured registry instead of registry.npmjs.org#36187nathanwhit wants to merge 3 commits into
Conversation
…ured registry When a private registry is configured (via .npmrc or NPM_CONFIG_REGISTRY) but a tarball URL still points at registry.npmjs.org -- because a proxy does not rewrite tarball URLs in its packuments, or because the URL was reconstructed from a lockfile that omitted it -- Deno downloaded the package bytes from registry.npmjs.org, bypassing the configured registry entirely. Deno now mirrors npm replace-registry-host=npmjs: tarballs served by the public npm registry are relocated to the configured registry, preserving its base path (e.g. an Artifactory repo under /api/npm/npm-remote/). Closes denoland#36183
The tarball relocation fix routes registry.npmjs.org tarball downloads to the configured registry. lock_file_lock_write uses a portable lockfile (tarball URLs omitted, so they reconstruct to registry.npmjs.org) with real npm packages that the test registry does not serve, so it relied on those downloads reaching the public registry. Point NPM_CONFIG_REGISTRY at the real npm registry for this test so the reconstructed tarballs are not relocated to the test registry.
|
Nice fix, and the no-op guards / base-path preservation / scoped-auth handling all check out. One thing worth addressing: Failure messages report the pre-relocation
So a user behind, say, an Artifactory proxy that 404s a given package gets Two smaller non-blocking notes for the description:
|
After relocating a registry.npmjs.org tarball to the configured registry, the 401/404/not-found error paths still interpolated the original `dist.tarball` URL. A user behind a proxy that 404s a package would be told the tarball couldn't be found at registry.npmjs.org, even though Deno requested it from their configured registry. Report the post-relocation URL that was actually contacted instead. Addresses review feedback.
|
Thanks for the review!
Good catch — fixed in d9387b5. All three error paths (the 401 and 404
Added a "Behavior change" section to the PR description spelling this out.
Confirmed — ran the full npm integration suite ( |
Closes #36183
Problem
When a private registry is configured (via
.npmrcorNPM_CONFIG_REGISTRY), Deno correctly fetches manifests from it but could still download tarballs fromregistry.npmjs.org, bypassing the configured registry. In regulated/enterprise setups that route npm traffic through a proxy for security scanning, this means the actual package bytes (the supply-chain risk) skip the filter entirely.A tarball URL ends up pointing at
registry.npmjs.orgeven with a private registry configured in two ways:dist.tarballin the packument, so Deno readsregistry.npmjs.orgURLs straight from the manifest.https://registry.npmjs.org/.... A lockfile generated against npmjs.org and then reused behind a proxy sends every tarball to npmjs.org.Fix
Deno now mirrors npm's
replace-registry-hostdefault (npmjs): at the single tarball-download chokepoint, whendist.tarball's host isregistry.npmjs.organd a different registry is configured for that package's scope, the download is relocated to the configured registry.Unlike npm — whose implementation drops the registry's base path — this preserves the base path (e.g. an Artifactory repo under
/api/npm/npm-remote/), which is where such proxies actually serve tarballs. It is a no-op when the configured registry is already npmjs.org or when the proxy already rewrote the tarball host. As a bonus, the relocated URL now matches the private registry's configured auth, so scoped credentials are applied to the tarball request.Behavior change
This is an intentional behavior change worth calling out: a user who has a private registry configured but genuinely wants tarballs served from
registry.npmjs.org(e.g. a manifest-only mirror that intentionally leavesdist.tarballpointing at npm) will now have those tarball downloads relocated to their configured registry. This matches npm'sreplace-registry-host=npmjsdefault, and is a no-op when the configured registry is already npmjs.org or when the proxy already rewrote the tarball host, but it may surprise a manifest-only-mirror setup.Tests
tests/specs/npm/tarball_relocate_to_registry) with a fixture package whose packument pointsdist.tarballatregistry.npmjs.org; it asserts the tarball is downloaded from the configured registry and runs end-to-end. Verified that the spec test fails without the fix (tarball stays onregistry.npmjs.org).