This action checks all installed NPM dependencies for lifecycle scripts (like
postinstall) that would be run on installation. If any such script is found,
the action fails with a list of offenders.
| Input Name | Description | Required | Default |
|---|---|---|---|
ignore |
List of packages to ignore (JSON) | No | "" |
ignoreNative |
Whether to ignore the default node-gyp install step | No | false |
You can specify dependencies you would like to ignore when scanning for
lifecycle scripts (ideally because you manually vetted them and consider them to
be secure). This can be helpful if you have dependencies that need a
postinstall script to be run.
This parameter expects a JSON array of package names or an object as string.
"PKGNAME": {
"version": VERSION_LIST,
"script": SCRIPT_LIST,
"native": IGNORE_NATIVE,
}PKGNAME: the name of the package to ignoreVERSION_LIST: a version string or array of version strings (combined via logical or) in the semver format. Only packages that match this version will be ignored. NPM rules apply (e.g.^1.2.3also matches1.2.5and1.3.0but not1.2.2or2.0.0, use=1.2.3for fixed versions).SCRIPT_LIST: a string or array of strings of specific scripts to ignore. Possible values areprepare,preinstall,install, andpostinstallIGNORE_NATIVE: whentrue, ignore implicit runs ofnode-gypfor packages that generate native bindings
If "script" is present without "version", the specified script(s) will be
ignored in all versions. If only "version" is present, everything will be
ignored for the specified version.
Example: Ignore esbuild
- name: Validate step
uses: cryptool-org/npm-no-scripts@v1
with:
ignore: |
["esbuild"]or
- name: Validate step
uses: cryptool-org/npm-no-scripts@v1
with:
ignore: |
{"esbuild": true}Example: Ignore only postinstall script for esbuild
- name: Validate step
uses: cryptool-org/npm-no-scripts@v1
with:
ignore: |
{
"esbuild": {
"script": "postinstall"
}
}Example: Ignore all scripts in version '0.22.3' of esbuild
- name: Validate step
uses: cryptool-org/npm-no-scripts@v1
with:
ignore: |
{
"esbuild": {
"version": "=0.22.3"
}
}Example: Ignore preinstall script in version '0.22.3' and patch releases of
esbuild
- name: Validate step
uses: cryptool-org/npm-no-scripts@v1
with:
ignore: |
{
"esbuild": {
"version": "~0.22.3",
"script": "preinstall"
}
}This action does not produce outputs. It will only succeed if no lifecycle script is found.
- Install your dependencies without running any potential scripts:
- name: Install dependencies
run: npm ci --ignore-scripts- Run this action to verify no scripts would have been run:
- name: Validate step
uses: cryptool-org/npm-no-scripts@v1- (optional) Run all scripts (in your package and the ignored ones):
- name: Configure dependencies
run: npm rebuildTo limit trivial supply-chain attacks, never run untrusted scripts. Use
npm clean-install --ignore-scripts when installing the dependencies. This will
use the lockfile with pinned versions and not execute any lifecycle scripts.
If any of your dependencies needs such a script (like postinstall) to function
properly, you can explicitly run them using npm rebuild <PACKAGE>.
Please note that --ignore-scripts wont execute any of your own scripts defined
in package.json either. You either have to run them manually with
npm run <SCRIPTNAME> or -- only if you are certain no malicious scripts exist
in your dependencies -- with npm rebuild.
This GitHub Action is available under the MIT License