Skip to content

Commit 66408d7

Browse files
fix(arborist): apply registry-tarball allow-remote exemption in linked strategy (#9500)
Backport of #9495 to `release/v11`. Co-authored-by: Manzoor Wani <manzoorwani.jk@gmail.com>
1 parent 351a309 commit 66408d7

4 files changed

Lines changed: 59 additions & 0 deletions

File tree

workspaces/arborist/lib/arborist/isolated-reifier.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = cls => class IsolatedReifier extends cls {
4444
const newChild = new IsolatedNode({
4545
isInStore,
4646
inBundle,
47+
isRegistryDependency: node.isRegistryDependency,
4748
location,
4849
name: node.packageName || node.name,
4950
optional: node.optional,
@@ -194,6 +195,9 @@ module.exports = cls => class IsolatedReifier extends cls {
194195
result.optional = node.optional
195196
result.resolved = node.resolved
196197
result.version = node.version
198+
// Carry the source node's registry-dependency flag so the store node retains it.
199+
// IsolatedNode has no edges to recompute it from, and reify's registry-tarball allow-remote exemption depends on it.
200+
result.isRegistryDependency = node.isRegistryDependency
197201
return result
198202
}
199203

workspaces/arborist/lib/isolated-classes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class IsolatedNode {
2121
inventory = new IsolatedInventory()
2222
isInStore = false
2323
inBundle = false
24+
isRegistryDependency = false
2425
linksIn = new Set()
2526
meta = { loadedFromDisk: false }
2627
optional = false
@@ -51,6 +52,9 @@ class IsolatedNode {
5152
if (options.inBundle) {
5253
this.inBundle = true
5354
}
55+
if (options.isRegistryDependency) {
56+
this.isRegistryDependency = true
57+
}
5458
if (options.optional) {
5559
this.optional = true
5660
}

workspaces/arborist/test/arborist/reify.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3977,6 +3977,56 @@ t.test('should preserve exact ranges, missing actual tree', async (t) => {
39773977
await t.resolves(arb.reify(), 'same-origin tarball is allowed for registry root')
39783978
})
39793979

3980+
t.test('allowRemote=none allows registry tarball under linked install strategy', async t => {
3981+
// The linked strategy extracts store nodes as IsolatedNode, which has no edges to recompute isRegistryDependency from.
3982+
// The flag must be carried from the source tree node so the registry-tarball allow-remote exemption still applies.
3983+
const abbrevPackument5 = JSON.stringify({
3984+
_id: 'abbrev',
3985+
_rev: 'lkjadflkjasdf',
3986+
name: 'abbrev',
3987+
'dist-tags': { latest: '1.1.1' },
3988+
versions: {
3989+
'1.1.1': {
3990+
name: 'abbrev',
3991+
version: '1.1.1',
3992+
dist: {
3993+
tarball: 'https://registry.example.com/npm/abbrev/-/abbrev-1.1.1.tgz',
3994+
},
3995+
},
3996+
},
3997+
})
3998+
3999+
const testdir = t.testdir({
4000+
project: {
4001+
'package.json': JSON.stringify({
4002+
name: 'myproject',
4003+
version: '1.0.0',
4004+
dependencies: {
4005+
abbrev: '1.1.1',
4006+
},
4007+
}),
4008+
},
4009+
})
4010+
4011+
tnock(t, 'https://registry.example.com')
4012+
.get('/npm/abbrev')
4013+
.reply(200, abbrevPackument5)
4014+
4015+
tnock(t, 'https://registry.example.com')
4016+
.get('/npm/abbrev/-/abbrev-1.1.1.tgz')
4017+
.reply(200, abbrevTGZ)
4018+
4019+
const arb = new Arborist({
4020+
path: resolve(testdir, 'project'),
4021+
registry: 'https://registry.example.com/npm',
4022+
cache: resolve(testdir, 'cache'),
4023+
allowRemote: 'none',
4024+
installStrategy: 'linked',
4025+
})
4026+
4027+
await t.resolves(arb.reify(), 'registry tarball is allowed under linked strategy')
4028+
})
4029+
39804030
t.test('registry with different protocol should swap protocol', async (t) => {
39814031
const abbrevPackument4 = JSON.stringify({
39824032
_id: 'abbrev',

workspaces/arborist/test/script-allowed.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ t.test('isolated mode (linked): bundled IsolatedNode is blocked', async t => {
452452

453453
const store = new IsolatedNode({
454454
isInStore: true,
455+
isRegistryDependency: true, // carried from the source node by #externalProxy
455456
location: 'node_modules/.store/store-pkg@1.0.0/node_modules/store-pkg',
456457
name: 'store-pkg',
457458
package: { name: 'store-pkg', version: '1.0.0' },

0 commit comments

Comments
 (0)