Skip to content

fix: forward git auth to hosted CDN tarball downloads - #515

Open
dyk1454683243-sudo wants to merge 1 commit into
npm:mainfrom
dyk1454683243-sudo:cursor/fix-codeload-authorization-d838
Open

dyk1454683243-sudo wants to merge 1 commit into
npm:mainfrom
dyk1454683243-sudo:cursor/fix-codeload-authorization-d838

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

Fixes #331

Cause

When installing a hosted git dependency (git+https://oauth2:TOKEN@github.com/org/private.git), pacote prefers the provider CDN tarball (https://codeload.github.com/.../tar.gz/<sha>) over git clone.

hosted-git-info's tarball() URL does not include git URL userinfo. npm-registry-fetch then looks up credentials by the request host (codeload.github.com), so neither:

  • credentials embedded in the git URL (oauth2:TOKEN@github.com), nor
  • credential-store entries for the git host (//github.com/:_authToken)

are sent. GitHub returns 404 for the private archive, and pacote falls back to git+ssh.

Fix

When GitFetcher shells out to RemoteFetcher for a hosted tarball, compute forceAuth the same way other authenticated pacote fetches do:

  1. Translate git URL userinfo (hosted.auth) to HTTP Basic (percent-decoding first).
  2. Otherwise, if the CDN host has no stored credentials, reuse //<git-host>/ credential-store auth (_authToken → Bearer, _auth / username+password → Basic).
  3. Leave an explicit Authorization header or a CDN-specific token (//codeload.github.com/:_authToken) alone.

npm-registry-fetch then sets Authorization on the CDN request.

Tests

  • Unit tests for URL userinfo, percent-encoding, //github.com/:_authToken, Basic store entries, and CDN-host precedence.
  • Integration tests mock https://codeload.github.com and assert the Authorization header on the tarball GET.

This is distinct from #285 / #514 (hardlink extract filter).

Hosted-git-info tarball URLs (codeload.github.com) omit git URL
userinfo, and npm-registry-fetch looks up credentials by request host.
Pass URL credentials and //<git-host>/ credential-store entries as
forceAuth so the CDN request gets an Authorization header.

Fixes: npm#331

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
@dyk1454683243-sudo
dyk1454683243-sudo requested a review from a team as a code owner September 20, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] CDN download doesn't use provided HTTP Authorization token (even if it's provided hardcoded in the URL)

2 participants