Skip to content

runPrettierStep breaks on shell-sensitive filenames #800

Description

@BakedSoups

I ran across a potential issue in the wizard UI flow after the agent finishes making changes and the wizard tries to run the post-run formatting step.

From the user's perspective, this would show up near the end of a wizard run when the terminal says it is running Prettier on changed files. If one of the changed or untracked files has a name containing a space, quote, semicolon, or another shell-sensitive character, the formatting step may fail or format the wrong path.

I traced it in the repo to runPrettierStep: it gets changed/untracked files from git status --porcelain=v1, joins those filenames into one string, then interpolates that into a shell command:

childProcess.exec(
  `npx prettier --ignore-unknown --write ${changedOrUntrackedFiles}`,
  ...
)

Relevant code:

  • src/utils/setup-utils.ts builds the changed-file list from Git status output.
  • src/steps/run-prettier.ts joins that list and passes it to childProcess.exec.

This looks like it can break on ordinary filenames with spaces, quotes, or other shell-sensitive characters. It may also be worth checking whether a malicious filename could change what the shell executes, since the filenames are interpolated into the command string.

A simple reproduction should be something like:

  1. In a test project, create or modify a file with a name containing a space, quote, semicolon, or other shell-sensitive character.
  2. Ensure the project has Prettier declared in package.json.
  3. Run a wizard flow that reaches the post-run Prettier step.
  4. Observe whether Prettier formats the intended file, fails, or interprets the filename incorrectly.

I think the safer shape is probably to keep filenames as argv entries and use spawn/execFile instead of exec, but I have not fully tested the behavior yet.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions