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

Aberta
#2,581 1 comentário 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
55/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
nodejs, typescript
Domínio
cli

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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]

Linguagem predominante
TypeScript
Estrelas
975
Forks
189
Merge médio
19h 57min
PRs com merge (30d)
542

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de getsentry/toolkit

Todas as issues de getsentry/toolkit

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.