fix(npm): retain authorization header on http->https redirect#29878
Merged
bartlomieju merged 3 commits intodenoland:mainfrom Mar 12, 2026
Merged
fix(npm): retain authorization header on http->https redirect#29878bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju merged 3 commits intodenoland:mainfrom
Conversation
anonhostpi
reviewed
Jun 27, 2025
Extract redirect auth logic into `should_strip_auth_on_redirect` helper. Auth headers are now stripped when the host or port changes, or on an https->http downgrade. Same-host http->https upgrades retain auth. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
kajukitli
approved these changes
Mar 12, 2026
Contributor
kajukitli
left a comment
There was a problem hiding this comment.
lgtm
the old origin() comparison was too blunt here because it treated a same-host http -> https redirect as cross-origin and dropped auth. the new helper has the right policy: keep auth on same-host upgrades, drop it on host/port changes and on https -> http downgrades.
tests cover the important cases too.
bartlomieju
approved these changes
Mar 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #29869.
Summary
When an npm registry is configured with
http://in.npmrcand the serverredirects to
https://, the authorization header was being stripped. Thishappened because the previous origin-based check (
url.origin() != new_url.origin())treated scheme changes as cross-origin, since
url::Originincludes the scheme.This caused 401 errors for private registries like GitHub Packages when
configured with
http://URLs.Changes
should_strip_auth_on_redirecthelper function with clear semantics:
https->http) to avoid leakingcredentials over plaintext
http->https), which aresafe redirects
host, different port, scheme downgrade)