Skip to content

Harden wsl.exe/git argument construction: leading-dash distro names, worktree path quoting #123

Description

@AThraen

Two small argument-construction gaps left open by #121. Neither is reachable through normal use; both were found during that PR's review and deliberately parked rather than fixed, to keep the change focused.

1. A distro name beginning with - is not defended against

Documented under WSL Sessions → Known gaps in CLAUDE.md.

ShellSession.QuoteForCmd only wraps a value in quotes when it contains a space, tab or quote, so a distro named --help (or anything starting with -) reaches wsl.exe as a bare token and is parsed as an option rather than as the argument to -d. Distro names come from wsl -l -v, so this needs a user who imported a distro with a hostile name — low likelihood, but the value flows from state.json, which CLAUDE.md treats as untrusted input.

Note that quoting alone does not fix it: wsl.exe -d "-x" still parses as an option. The real fix is either rejecting such names in WslDiscoveryService.Parse or validating in LaunchValidationError, which already guards a blank distro on the same path.

2. GitService.CreateWorktreeAsync still uses naive quoting

GitService.cs:150-152 builds its arguments with plain \"{value}\" interpolation while everything else on the WSL path goes through QuoteForCmd. Since #121 routes git for \wsl$ folders through wsl.exe, that string now reaches one more layer than it used to. Inputs are user-typed branch names and paths rather than persisted state, so this is robustness rather than a security hole — but it is the last caller not using the shared helper, and the asymmetry is the kind that gets copied.

Verify

Unit tests only; both are covered by the existing Win32CommandLineTests round-trip harness, which tokenizes through the real CommandLineToArgvW.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions