fix(config): avoid exporting persistent allow-scripts (#9937) · npm/cli@64d4b4b · GitHub
Skip to content

Commit 64d4b4b

Browse files
fix(config): avoid exporting persistent allow-scripts (#9937)
Backport of #9913 to `release/v11`. Co-authored-by: Fnine59 <fnine59@163.com>
1 parent afdc5bd commit 64d4b4b

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

‎tap-snapshots/test/lib/docs.js.test.cjs‎

Lines changed: 1 addition & 1 deletion

‎test/lib/utils/resolve-allow-scripts.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,22 @@ t.test('--allow-scripts CLI flag is rejected in project-scoped installs', async
8686
)
8787
})
8888

89+
t.test('allow-scripts environment policy is rejected in project-scoped installs', async t => {
90+
const mock = await mockNpm(t, {
91+
prefixDir: {
92+
'package.json': JSON.stringify({ name: 'p' }),
93+
},
94+
globals: {
95+
'process.env.npm_config_allow_scripts': 'canvas',
96+
},
97+
})
98+
const resolveAllowScripts = loadResolver(t)
99+
await t.rejects(
100+
resolveAllowScripts(mock.npm),
101+
{ code: 'EALLOWSCRIPTS', message: /--allow-scripts is not allowed/ }
102+
)
103+
})
104+
89105
t.test('--allow-scripts CLI flag is accepted in global installs (RFC layer 1 wins)', async t => {
90106
const mock = await mockNpm(t, {
91107
prefixDir: {

‎workspaces/config/lib/definitions/definitions.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ const definitions = {
258258
default: '',
259259
type: [String, Array],
260260
hint: '<package-list>',
261+
envExport: false,
261262
description: `
262263
Comma-separated list of packages whose install-time lifecycle scripts
263264
(\`preinstall\`, \`install\`, \`postinstall\`, and \`prepare\` for

‎workspaces/config/test/set-envs.js‎

Lines changed: 36 additions & 0 deletions

0 commit comments

Comments
 (0)