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

Aperta
#2,581 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
nodejs, typescript
Ambito
cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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]

Lingua principale
TypeScript
Stelle
975
Fork
189
Merge medio
19h 57m
PR unite (30g)
542

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/toolkit

Tutte le issue di getsentry/toolkit

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.