Skip to content

Commit 804f9ba

Browse files
author
Michael Smith
committed
1 parent aaeb2f1 commit 804f9ba

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

‎node_modules/npm-profile/lib/index.js‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ const isValidUrl = u => {
4949
}
5050
}
5151

52+
// npm's web-login response names the canonical npmjs registry in `doneUrl`, which a proxy/mirror forwards verbatim.
53+
// The poll would then hit npmjs.org instead of the proxy that holds the session, so rewrite only that npmjs host to the configured registry origin, preserving the path prefix and query string.
54+
// Any other done host is left untouched, since a non-npmjs canonical host cannot be inferred here and may be served intentionally.
55+
const CANONICAL_REGISTRY_HOST = 'registry.npmjs.org'
56+
57+
// doneUrl is already validated by isValidUrl and registry is the origin a prior
58+
// POST /-/v1/login succeeded against, so both parse cleanly here.
59+
const replaceDoneUrlOrigin = (doneUrl, registry) => {
60+
if (!registry) {
61+
return doneUrl
62+
}
63+
const done = new URL(doneUrl)
64+
if (done.hostname !== CANONICAL_REGISTRY_HOST) {
65+
return doneUrl
66+
}
67+
const reg = new URL(registry)
68+
done.protocol = reg.protocol
69+
done.host = reg.host
70+
const prefix = reg.pathname.replace(/\/$/, '')
71+
if (prefix && prefix !== '/' &&
72+
done.pathname !== prefix &&
73+
!done.pathname.startsWith(prefix + '/')) {
74+
done.pathname = prefix + done.pathname
75+
}
76+
return done.href
77+
}
78+
5279
const webAuth = async (opener, opts, body) => {
5380
try {
5481
const res = await fetch('/-/v1/login', {
@@ -65,7 +92,7 @@ const webAuth = async (opener, opts, body) => {
6592
throw new WebLoginInvalidResponse('POST', res, content)
6693
}
6794

68-
return await webAuthOpener(opener, loginUrl, doneUrl, opts)
95+
return await webAuthOpener(opener, loginUrl, replaceDoneUrlOrigin(doneUrl, opts.registry), opts)
6996
} catch (er) {
7097
if ((er.statusCode >= 400 && er.statusCode <= 499) || er.statusCode === 500) {
7198
throw new WebLoginNotSupported('POST', {

‎node_modules/npm-profile/package.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "npm-profile",
3-
"version": "12.0.1",
3+
"version": "12.0.2",
44
"description": "Library for updating an npmjs.com profile",
55
"keywords": [],
66
"author": "GitHub Inc.",
77
"license": "ISC",
88
"dependencies": {
99
"npm-registry-fetch": "^19.0.0",
10-
"proc-log": "^6.0.0"
10+
"proc-log": "^6.1.0"
1111
},
1212
"main": "./lib/index.js",
1313
"repository": {
@@ -19,8 +19,8 @@
1919
"lib/"
2020
],
2121
"devDependencies": {
22-
"@npmcli/eslint-config": "^5.0.0",
23-
"@npmcli/template-oss": "4.27.1",
22+
"@npmcli/eslint-config": "^7.0.0",
23+
"@npmcli/template-oss": "5.1.1",
2424
"nock": "^13.5.6",
2525
"tap": "^16.0.1"
2626
},
@@ -46,7 +46,7 @@
4646
},
4747
"templateOSS": {
4848
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
49-
"version": "4.27.1",
49+
"version": "5.1.1",
5050
"publish": true
5151
}
5252
}

‎package-lock.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"npm-install-checks": "^8.0.0",
130130
"npm-package-arg": "^13.0.2",
131131
"npm-pick-manifest": "^11.0.3",
132-
"npm-profile": "^12.0.1",
132+
"npm-profile": "^12.0.2",
133133
"npm-registry-fetch": "^19.1.1",
134134
"npm-user-validate": "^4.0.0",
135135
"p-map": "^7.0.4",
@@ -8443,14 +8443,14 @@
84438443
}
84448444
},
84458445
"node_modules/npm-profile": {
8446-
"version": "12.0.1",
8447-
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-12.0.1.tgz",
8448-
"integrity": "sha512-Xs1mejJ1/9IKucCxdFMkiBJUre0xaxfCpbsO7DB7CadITuT4k68eI05HBlw4kj+Em1rsFMgeFNljFPYvPETbVQ==",
8446+
"version": "12.0.2",
8447+
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-12.0.2.tgz",
8448+
"integrity": "sha512-+OKkPvqvx83vRG8aIetzABI99e5uzZZ6HIS5zCr+oRPSuDL0Buk1KJh/LqyR0BuiWmLeDWGI77igNYipztLm1w==",
84498449
"inBundle": true,
84508450
"license": "ISC",
84518451
"dependencies": {
84528452
"npm-registry-fetch": "^19.0.0",
8453-
"proc-log": "^6.0.0"
8453+
"proc-log": "^6.1.0"
84548454
},
84558455
"engines": {
84568456
"node": "^20.17.0 || >=22.9.0"

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"npm-install-checks": "^8.0.0",
9898
"npm-package-arg": "^13.0.2",
9999
"npm-pick-manifest": "^11.0.3",
100-
"npm-profile": "^12.0.1",
100+
"npm-profile": "^12.0.2",
101101
"npm-registry-fetch": "^19.1.1",
102102
"npm-user-validate": "^4.0.0",
103103
"p-map": "^7.0.4",

0 commit comments

Comments
 (0)