wizard: installPackage passes unquoted package specs through spawn(..., { shell: true })

Abierto
#2,581 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
nodejs, typescript
Área
cli

Línea de trabajo

Start with installPackage in packages/cli/src/lib/wizard/utils/clack/index.ts (around line 512), where spawn(pkgManager.name, installArgs, { shell: true }) joins arguments into one shell command line. Remove shell: true and pass argv directly, resolving the .cmd shim on Windows. Done when specs containing >, ^ and | reach the package manager intact, and a test using a fake package-manager binary that records its argv passes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

installPackage in packages/cli/src/lib/wizard/utils/clack/index.ts (around line 512) runs the package manager with spawn(pkgManager.name, installArgs, { shell: true }), and it doesn't quote the arguments. Node concatenates them into one shell command line, so any shell metacharacter in a package spec gets parsed by the shell:

  • > and < become redirects. A spec of sentry@>=0.52.0 ran as <pm> add sentry@ -D (it installed latest with no version floor) and wrote the command's output to a file named =0.52.0 in the project.
  • | becomes a pipe.
  • ^ is the escape character in Windows cmd, so caret ranges like pkg@^1.2.3 can be mangled there.

Node also prints DEP0190 for this pattern: passing args with shell: true concatenates them without escaping.

Nothing user-controlled reaches this today, because every package spec the wizard installs is a constant. getsentry/toolkit#2525 works around it by installing sentry@<major>.x, which has no metacharacters. That workaround only holds while every spec stays free of shell syntax.

Proposal

  • Drop shell: true and pass argv directly. On Windows, resolve <pm>.cmd (npm.cmd, pnpm.cmd, yarn.cmd, and so on) so it still launches without a shell.
  • Add a test that exercises installPackage's argv handling end to end, with a fake package-manager binary that records its argv instead of a mock of installPackage, including a spec with >, ^ and |.

Related: getsentry/toolkit#1385 covers the same shell: true pattern in sentry init's local-ops.ts.

via @BYK.

--

View Session [Sentry]

Lenguaje dominante
TypeScript
Estrellas
975
Forks
189
Merge medio
19 h 57 min
PR fusionados (30 d)
542

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de getsentry/toolkit

Todos los issues de getsentry/toolkit

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.