fix(security): replace npx with npm exec in pre-commit hook #79
fix(security): replace npx with npm exec in pre-commit hook #79frankieyan merged 1 commit intomainfrom
Conversation
`npx` can fetch and execute unverified packages from the registry if a local install is missing or typosquatted. `npm exec` with an already installed devDependency avoids that risk. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
doistbot
left a comment
There was a problem hiding this comment.
This PR updates the pre-commit hook to use npm exec instead of npx when running lint-staged, which is a great step toward securing our tooling against potential supply-chain attacks. However, since modern npm versions still fetch missing packages with npm exec, an explicit --no flag is needed to fully enforce using only the locally installed version.
| @@ -1 +1 @@ | |||
| npx lint-staged | |||
| npm exec lint-staged | |||
There was a problem hiding this comment.
[P1] npm exec without --no still fetches missing packages
The PR description states that switching to npm exec ensures only the locally installed version is run. However, in modern npm (v7+), npm exec and npx share the same underlying behavior: if the package is missing locally, both will attempt to fetch it or prompt the user to install it.
To effectively close this supply-chain attack vector and strictly enforce using only the local installation, you must explicitly pass the --no flag to disable fetching. You can use either npm exec --no -- lint-staged or npx --no lint-staged.
| npm exec lint-staged | |
| npm exec --no -- lint-staged |
#79 replaced npx with npm exec, but npm exec without --no still allows fetching uninstalled packages from the registry. The --no flag ensures only locally installed packages can run. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
#79 replaced npx with npm exec, but npm exec without --no still allows fetching uninstalled packages from the registry. The --no flag ensures only locally installed packages can run. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Overview
npxcan silently fetch and execute packages from the npm registry if a matching local install is missing or if a package name is typosquatted. Sincelint-stagedis already an explicit devDependency, usingnpm execinstead ensures we only run the locally installed version, closing a potential supply-chain attack vector.Test plan
lint-stagedruns and catches the issue🤖 Generated with Claude Code