[BUG] allowScripts doesn't stop a git dependency's prepare script
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 56/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
Direzione di ricerca
Start with the cited allowScripts check in workspaces/arborist/lib/arborist/rebuild.js and trace how git dependencies reach pacote's prepare step in pacote/lib/dir.js. Compare the existing isScriptAllowed() and ignoreScripts handling, then add or update tests for a disallowed git dependency and an allowed one. Done means a disallowed prepare script never runs during npm install, while allowed scripts retain their expected behavior.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Is there an existing issue for this?
- I have searched the existing issues
This issue exists in the latest npm version
- I am using the latest npm
This is not just a request to bump a dependency for a CVE
- This is not solely a request to bump a dependency for a CVE
Current Behavior
With allow-git on, a git dependency's prepare runs during a plain npm install even though the package isn't in allowScripts. npm then warns that it blocked the script, after it has already run.
The allowScripts check is in Arborist's rebuild queue, which runs after extraction:
https://github.com/npm/cli/blob/60e11343e61316d966c86805d803df5a0eb99230/workspaces/arborist/lib/arborist/rebuild.js#L212-L215
A git dependency's prepare runs before that, while pacote packs the clone, and the only gate there is ignoreScripts:
https://github.com/npm/pacote/blob/453a0adac3592e5f93c8f782fb1b1b320ac95009/lib/dir.js#L38-L40
--strict-allow-scripts checks the tree before extraction, so it does stop it (ESTRICTALLOWSCRIPTS, the script never starts).
Expected Behavior
A git dependency that allowScripts doesn't allow doesn't run prepare, e.g. by extracting it with ignoreScripts: true when isScriptAllowed() isn't true for that node.
Steps To Reproduce
$ mkdir evil-gitdep && cd evil-gitdep
$ echo '{ "name": "evil-gitdep", "version": "1.0.0", "scripts": { "prepare": "node evil.js" } }' > package.json
$ echo 'require("fs").writeFileSync("/tmp/pwned", "pwned"); console.log("PREPARE_RAN")' > evil.js
$ git init -q && git add -A && git commit -qm init && cd ..
$ mkdir app && cd app
$ printf '{ "name": "app", "version": "1.0.0", "dependencies": { "evil-gitdep": "git+file://%s/evil-gitdep" } }\n' "$(cd .. && pwd)" > package.json
$ echo 'allow-git=all' > .npmrc
$ npm install --foreground-scripts
npm notice run [email protected] prepare
npm notice run node evil.js
PREPARE_RAN
added 1 package in 989ms
npm warn install-scripts 1 package had install scripts blocked because they are not covered by allowScripts:
npm warn install-scripts [email protected] (prepare: node evil.js)
[..]
$ cat /tmp/pwned
pwned
--foreground-scripts only makes the order visible; the script runs without it too.
Environment
- npm: 12.2.2
- Node.js: 24.22.1
- OS Name: macOS 26
- npm config:
allow-git=all(project.npmrc)
- Lingua principale
- JavaScript
- Stelle
- 10.3k
- Fork
- 5k
- Merge medio
- 4g 11h
- PR unite (30g)
- 26
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di npm/cli
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsForse già presa @saruk-vedant l’ha presa 7 giorni fa. ApertaBug Needs Triage Triage Requested
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 2 giorni
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyForse già presa @drawliin l’ha presa 42 giorni fa. Apertacmd:delete Priority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
I maintainer di solito rispondono entro 2 giorni
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. ApertaEngineering Priority 1
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
I maintainer di solito rispondono entro 2 giorni
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysForse già presa @greenlincoln05 l’ha presa 63 giorni fa. ApertaPriority 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 2 giorni
Issue simili
-
docs: add SECURITY.md vulnerability reporting policyForse già presa @AK-Lmn l’ha presa oggi. Aperta
Difficoltà 1/5 1-3 ore Idoneità per principianti 72/100
flisk-sh/linux2wasm#12 ·
I maintainer di solito rispondono entro 1 giorno
-
possible bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
Mintplex-Labs/anything-llm#7388 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
I maintainer di solito rispondono entro 1 giorno
-
v6: Minified bootstrap.min.css is missing header infoForse già presa @lazerg l’ha presa oggi. Apertabug build confirmed has-pr v6
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
githubnext/gh-aw-workshop#6332 ·
I maintainer di solito rispondono entro 1 giorno