-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: Phase 1 of allowScripts opt-in install-script policy
#9360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
JamieMagee
wants to merge
9
commits into
npm:latest
Choose a base branch
from
JamieMagee:jamiemagee/install-scripts-phase-1
base: latest
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
73b2839
feat(config): add allow-scripts, strict-script-builds, dangerously-al…
JamieMagee 61d5bd3
feat(install): read allowScripts policy from root package.json and CL…
JamieMagee 20c2c81
feat(arborist): add identity matcher for allowScripts policy
JamieMagee 4410eb4
feat(install): walk tree and emit advisory warning for unreviewed ins…
JamieMagee 1aa1426
feat: add npm approve-scripts and npm deny-scripts commands
JamieMagee 6768ec7
feat(install): warn on allowScripts in non-root workspaces
JamieMagee a76d554
chore: add coverage tests and istanbul ignores for defensive branches
JamieMagee 632f932
feat(allow-scripts): enforce false/true entries, add strict pre-fligh…
JamieMagee d885072
refactor(allow-scripts): address review feedback (rename pin/pending,…
JamieMagee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| --- | ||
| title: npm-approve-scripts | ||
| section: 1 | ||
| description: Approve install scripts for specific dependencies | ||
| --- | ||
|
|
||
| ### Synopsis | ||
|
|
||
| <!-- AUTOGENERATED USAGE DESCRIPTIONS --> | ||
|
|
||
| ### Description | ||
|
|
||
| Manages the `allowScripts` field in your project's `package.json`, which | ||
| records which of your dependencies are permitted to run install scripts | ||
| (`preinstall`, `install`, `postinstall`, and `prepare` for non-registry | ||
| sources). This command is the recommended way to maintain that field. | ||
|
|
||
| In the current release, this field is advisory: install scripts still run | ||
| by default, but installs print a list of packages whose scripts have not | ||
| been reviewed. A future release will block unreviewed install scripts. | ||
|
|
||
| There are three modes: | ||
|
|
||
| ```bash | ||
| npm approve-scripts <pkg> [<pkg> ...] | ||
| npm approve-scripts --all | ||
| npm approve-scripts --allow-scripts-pending | ||
| ``` | ||
|
|
||
| `<pkg>` matches every installed version of that package. By default the | ||
| command writes pinned entries (`pkg@1.2.3`), which keep their approval | ||
| narrowed to the specific version you reviewed. Pass `--no-allow-scripts-pin` to write | ||
| name-only entries that allow any future version. | ||
|
|
||
| `--all` approves every package with unreviewed install scripts in one go. | ||
|
|
||
| `--allow-scripts-pending` is read-only: it lists every package whose install scripts | ||
| are not yet covered by `allowScripts`, without modifying `package.json`. | ||
|
|
||
| `approve-scripts` honours the asymmetric pin rule: if you re-approve a | ||
| package whose installed version has changed, the existing pin is rewritten | ||
| to track the new installed version. Multi-version statements | ||
| (`pkg@1 || 2`) are left alone, since they likely capture intent that | ||
| the command cannot infer. Existing `false` entries always win; | ||
| `approve-scripts` will not silently re-allow a package you previously | ||
| denied. | ||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
| # Approve all currently-installed install scripts after reviewing them | ||
| npm approve-scripts --all | ||
|
|
||
| # Approve specific packages, pinned to their installed version | ||
| npm approve-scripts canvas sharp | ||
|
|
||
| # Approve name-only (any version of this package is allowed) | ||
| npm approve-scripts --no-allow-scripts-pin canvas | ||
|
|
||
| # Preview which packages still need review | ||
| npm approve-scripts --allow-scripts-pending | ||
| ``` | ||
|
|
||
| ### Configuration | ||
|
|
||
| <!-- AUTOGENERATED CONFIG DESCRIPTIONS --> | ||
|
|
||
| ### See Also | ||
|
|
||
| * [npm deny-scripts](/commands/npm-deny-scripts) | ||
| * [npm install](/commands/npm-install) | ||
| * [npm rebuild](/commands/npm-rebuild) | ||
| * [package.json](/configuring-npm/package-json) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| title: npm-deny-scripts | ||
| section: 1 | ||
| description: Deny install scripts for specific dependencies | ||
| --- | ||
|
|
||
| ### Synopsis | ||
|
|
||
| <!-- AUTOGENERATED USAGE DESCRIPTIONS --> | ||
|
|
||
| ### Description | ||
|
|
||
| The companion command to [`npm approve-scripts`](/commands/npm-approve-scripts). | ||
| Writes `false` entries into the `allowScripts` field of your project's | ||
| `package.json`, recording that a dependency must not run install scripts | ||
| even if a future version would otherwise be eligible. | ||
|
|
||
| In the current release, install scripts still run by default, so `deny-scripts` | ||
| only affects how installs of denied packages are reported. A future release | ||
| will block unreviewed install scripts and respect deny entries at install | ||
| time. | ||
|
|
||
| ```bash | ||
| npm deny-scripts <pkg> [<pkg> ...] | ||
| npm deny-scripts --all | ||
| ``` | ||
|
|
||
| `<pkg>` matches every installed version of that package. Denies are always | ||
| written name-only (`"pkg": false`), regardless of `--allow-scripts-pin`. Pinning a deny | ||
| to a specific version would silently re-allow scripts for any other version | ||
| of the same package, which defeats the purpose; the command picks the | ||
| safer default for you. | ||
|
|
||
| `--all` denies every package with unreviewed install scripts. | ||
|
|
||
| If a `true` (pinned or name-only) entry exists for a package and you then | ||
| deny it, the existing allow entries are removed so the name-only deny is | ||
| unambiguous. | ||
|
|
||
| ### Examples | ||
|
|
||
| ```bash | ||
| # Deny a specific package outright | ||
| npm deny-scripts telemetry-pkg | ||
|
|
||
| # Deny everything that has install scripts and isn't already approved | ||
| npm deny-scripts --all | ||
| ``` | ||
|
|
||
| ### Configuration | ||
|
|
||
| <!-- AUTOGENERATED CONFIG DESCRIPTIONS --> | ||
|
|
||
| ### See Also | ||
|
|
||
| * [npm approve-scripts](/commands/npm-approve-scripts) | ||
| * [npm install](/commands/npm-install) | ||
| * [package.json](/configuring-npm/package-json) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const AllowScriptsCmd = require('../utils/allow-scripts-cmd.js') | ||
|
|
||
| class ApproveScripts extends AllowScriptsCmd { | ||
| static description = 'Approve install scripts for specific dependencies' | ||
| static name = 'approve-scripts' | ||
| static usage = ['<pkg> [<pkg> ...]', '--all', '--allow-scripts-pending'] | ||
| static verb = 'approve' | ||
| } | ||
|
|
||
| module.exports = ApproveScripts |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| const AllowScriptsCmd = require('../utils/allow-scripts-cmd.js') | ||
|
|
||
| class DenyScripts extends AllowScriptsCmd { | ||
| static description = 'Deny install scripts for specific dependencies' | ||
| static name = 'deny-scripts' | ||
| static usage = ['<pkg> [<pkg> ...]', '--all'] | ||
| static verb = 'deny' | ||
| } | ||
|
|
||
| module.exports = DenyScripts |
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.