[BUG] npm pack/publish --ignore-scripts runs .npm-extension, and so does installing a git dependency
Los mantenedores suelen responder en 2 días
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, node.js
Línea de trabajo
Start with pacote's DirFetcher in lib/dir.js and Arborist's extension loading guard in workspaces/arborist/lib/arborist/load-actual.js; trace how ignoreExtension reaches the Arborist created during packing. Then inspect GitFetcher in lib/git.js to see how git dependencies use DirFetcher. Done means the listed pack, publish, and git install commands no longer load .npm-extension when the relevant ignore behavior applies.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
npm pack --ignore-scripts and npm publish --ignore-scripts import the package's .npm-extension.cjs/.mjs, and --ignore-extension doesn't stop it either. That undoes what #7211 was after, a publish job that can't be made to run code from the repo it's publishing.
pacote's DirFetcher builds its own Arborist to get the file list, and only gives it { path }:
https://github.com/npm/pacote/blob/453a0adac3592e5f93c8f782fb1b1b320ac95009/lib/dir.js#L79-L80
So ignoreExtension (which ignore-scripts also sets, here) never reaches the only guard in front of ext.load():
https://github.com/npm/cli/blob/60e11343e61316d966c86805d803df5a0eb99230/workspaces/arborist/lib/arborist/load-actual.js#L452-L463
GitFetcher packs every git dependency through the same DirFetcher (git.js#L217-L222), so with allow-git on, npm install --ignore-scripts also imports a git dependency's own .npm-extension, even though .npm-extension is meant to be the root project's file.
Expected Behavior
--ignore-scripts and --ignore-extension stop .npm-extension during pack and publish, and a git dependency's .npm-extension is never loaded. Passing ignoreExtension through to that Arborist would fix pack/publish; for a git dependency's clone it probably wants to be set unconditionally.
Steps To Reproduce
$ mkdir attacker-pkg && cd attacker-pkg
$ echo '{ "name": "attacker-pkg", "version": "1.0.0" }' > package.json
$ cat > .npm-extension.cjs <<'EOF'
require("fs").writeFileSync("/tmp/pwned", "pwned");
console.log("EXTENSION_RAN");
module.exports.transformManifest = (pkg) => pkg;
EOF
$ npm pack --dry-run --ignore-scripts --ignore-extension
EXTENSION_RAN
npm notice Tarball Contents
[..]
attacker-pkg-1.0.0.tgz
$ cat /tmp/pwned
pwned
npm publish --ignore-scripts does the same, with or without --dry-run; the extension runs before anything is sent to the registry. For the git dependency case, commit those two files to a repo, depend on it as git+file:///path/to/repo, and run npm install --ignore-scripts --allow-git=all.
Environment
- npm: 12.2.2
- Node.js: 24.22.1
- OS Name: macOS 26
- npm config: defaults (flags on the command line)
- Lenguaje dominante
- JavaScript
- Estrellas
- 10.3k
- Forks
- 5k
- Merge medio
- 4 d 11 h
- PR fusionados (30 d)
- 26
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de npm/cli
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 2 días
-
[BUG] scripts/dependency-graph.js splits npm-cli-repos.txt on os.EOL, so DEPENDENCIES.md depends on the checkout's line endingsPosiblemente ocupada @saruk-vedant la tomó hace 7 días. AbiertoBug Needs Triage Triage Requested
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
npm/cli#10316 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
[BUG] npm pkg delete removes the first array item for a nonexistent propertyPosiblemente ocupada @drawliin la tomó hace 42 días. Abiertocmd:delete Priority 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Los mantenedores suelen responder en 2 días
-
create node pr: Node.js 20 deprecation & `DEP0040` warnings loggedQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoEngineering Priority 1
Dificultad 1/5 Menos de una hora Aptitud para principiantes 80/100
Los mantenedores suelen responder en 2 días
-
`npm audit signatures` does not report how many packages it skipped for want of registry keysPosiblemente ocupada @greenlincoln05 la tomó hace 63 días. AbiertoPriority 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
npm/cli#10018 · 2 comentarios ·
Los mantenedores suelen responder en 2 días
Issues similares
-
docs: add SECURITY.md vulnerability reporting policyPosiblemente ocupada @AK-Lmn la tomó hoy. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 72/100
flisk-sh/linux2wasm#12 ·
Los mantenedores suelen responder en 1 día
-
possible bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Mintplex-Labs/anything-llm#7388 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 60/100
Los mantenedores suelen responder en 1 día
-
v6: Minified bootstrap.min.css is missing header infoPosiblemente ocupada @lazerg la tomó hoy. Abiertobug build confirmed has-pr v6
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
[workshop-sync] workshop/side-quest-26-01-forecast-costs.md: forecast default history window is inaccuratePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertodocumentation
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
githubnext/gh-aw-workshop#6332 ·
Los mantenedores suelen responder en 1 día