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

Offen
#2,581 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
nodejs, typescript
Bereich
cli

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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]

Vorherrschende Sprache
TypeScript
Sterne
975
Forks
189
Ø Merge
19 Std. 57 Min.
Gemergte PRs (30 T.)
542

Entwicklungsumgebung

Dieses Projekt bietet weder Dev-Container noch Dockerfile noch Beitragsleitfaden – die Einrichtung liegt bei Ihnen. Beginnen Sie mit der README; die allgemeinen Schritte stehen in unserem Leitfaden für den ersten Beitrag.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus getsentry/toolkit

Alle Issues in getsentry/toolkit

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.