Skip to content

fix(webui): build process arguments as arrays instead of shell strings - #6898

Merged
kovtcharov-amd merged 3 commits into
mainfrom
kalin/fix-2950-argv-spawn
Nov 7, 2026
Merged

kovtcharov-amd merged 3 commits into
mainfrom
kalin/fix-2950-argv-spawn

Conversation

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

The Electron launcher and backend installer built four of their commands as shell strings: opening the browser, checking whether a tool is on PATH, and the two free-disk-space probes. They now pass process arguments as arrays with no shell, so a URL or a path with spaces or unusual characters reaches the program as a single argument instead of being re-parsed.

Closes #2950

Test plan

  • cd tests/electron && npx jest process-argv backend-installer gaia-ui — new tests assert the exact argv and shell: false for each call, including a home path with spaces and shell metacharacters (asserted on the argv, nothing executed)
  • npx tsc --noEmit and npx vitest run in src/gaia/apps/webui
  • npx @amd-gaia/agent-ui (or node bin/gaia-ui.cjs) opens the browser on the right URL on Windows, macOS and Linux
  • Desktop installer on a clean machine still finds uv and gaia on PATH

The Electron launcher and backend installer assembled four commands as
shell strings (opening the browser, the PATH lookup, and both free-space
probes). They now pass an argument array to spawn/spawnSync/execFileSync
with no shell, so a URL or path reaches the program as one argument.

Closes #2950
@kovtcharov-amd kovtcharov-amd self-assigned this Nov 7, 2026
@github-actions github-actions Bot added the tests Test changes label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

The launcher and desktop installer now hand URLs and paths to the browser opener, the PATH lookup and the disk-space probes as single arguments with no shell, so a home folder or URL with spaces, quotes or $(…) no longer gets re-parsed or runs anything. The fix is correct, every shell-string call in the webui is now gone, and the evidence below shows the injection reproducing on the parent commit and stopping on this one.

Two small things are worth doing before merge:

  • The new Windows PATH and disk-space checks can flash a console window. The installer runs these from the desktop app, and where is called many times during setup. The installer's other child processes already hide their window; these two should too. This is one line each, and it's the same cost the old code had, so it doesn't block merge.
  • The Linux PATH check now depends on which being installed. The old check used the shell's built-in command -v. Some minimal Linux installs ship without which, and there the installer would decide uv and gaia are missing.

Real-world evidence

The evidence stage ran on a Linux runner against the real launcher, xdg-open and df, with a home path and URL containing shell metacharacters. On this PR, each argument arrived whole and nothing ran. On the parent commit, the shell ran two injected commands and the disk check silently failed:

===== PR head (b0af348ec) =====
--- xdg-open received:
ARG[http://localhost:4200/?q=My Files "q" ; $(touch PWNED) & `touch PWNED2`]
--- df received:
ARG[-k]
ARG[$TMP/home/My Files "q" ; $(touch PWNED) & `touch PWNED2`/user]
--- injection markers in cwd:
ls: cannot access 'PWNED': No such file or directory
ls: cannot access 'PWNED2': No such file or directory

===== parent (dad0ed13f) =====
df: '$TMP/home/My Files q ;  & /user': No such file or directory
checkDiskSpace() = {"ok":true,"freeBytesPositive":false,"message":"Free disk space could not be determined"}
--- injection markers in cwd:
PWNED
PWNED2
$ PATH=<shim>:$PATH node bin/gaia-ui.cjs --serve --port 4311
GAIA Agent UI serving at http://localhost:4311
--- xdg-open received:
ARG[http://localhost:4311]

# Real xdg-open, no shim, headless runner with no browser:
GAIA Agent UI serving at http://localhost:4312
  Open manually: http://localhost:4312

The Windows paths (rundll32, where, PowerShell) and macOS open were not exercised; they rest on the PR's mocked jest tests and static review. The rendered Agent UI is pending the strix-halo lane, though this PR changes no UI pixels. The two unchecked test-plan items still need someone to try them on Windows and macOS.

🔍 Technical details

🟡 New Windows subprocesses don't set windowsHide (src/gaia/apps/webui/services/backend-installer.cjs:449, :472)
Elsewhere in this file, spawns pass windowsHide: true (lines 483, 585, 2168). commandExists runs where up to six times during install (lines 1502–1620, 1986), and each call can flash a console from the Electron GUI process. The old execSync behaved the same way, so this isn't a regression, but the PR rewrote exactly these calls (missed-bug-class "Windows behaviour").

  const result = spawnSync(IS_WINDOWS ? "where" : "which", [cmd], {
    stdio: "ignore",
    shell: false,
    windowsHide: true,
  });

Also add windowsHide: true to the PowerShell execFileSync options at line 475.

🟢 which isn't guaranteed on Linux (backend-installer.cjs:449)
command -v was a shell builtin. Without which, spawnSync sets error (ENOENT) with status: null, so commandExists quietly returns false and the installer treats uv as missing. One option is to walk process.env.PATH with fs.accessSync(…, X_OK). Another is to check result.error?.code === "ENOENT" and fail loudly instead of reporting "not found".

Checked, no issue

  • No exec/execSync/shell: true calls remain under src/gaia/apps/webui.
  • rundll32 url.dll,FileProtocolHandler <url> is the standard shell-free way to open a URL on Windows. detached with a GUI-subsystem exe doesn't open a console.
  • With a UNC home, the drive regex yields a bad drive name. The PowerShell call then fails inside the existing non-fatal catch, the same as before.
  • The new test file matches testMatch (**/*.test.cjs) in tests/electron/package.json, so CI collects it. I couldn't run jest locally because node_modules isn't installed on this runner.
  • No docs describe these internals, so there's nothing to update.

Strengths

  • browserCommand is a pure function, so tests can check the exact argv on every platform without spawning anything.
  • PowerShell gets the drive letter through an environment variable, not the script text. That closes the injection in a language that execFileSync alone wouldn't have protected.
  • The new failure handling tells the user to open the URL by hand, and the evidence shows it firing for real on a headless runner.

Minimal Linux installs ship no `which`, so uv and gaia read as missing.
The PATH lookup now runs `sh -c 'command -v "$1"'` with the name as $1,
and a lookup that can't run at all raises an InstallError naming the fix
instead of reporting the tool as absent. The Windows lookup and the
PowerShell disk probe no longer flash a console window.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit d7fa27c Nov 7, 2026
60 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/fix-2950-argv-spawn branch November 7, 2026 08:36
kovtcharov-amd added a commit to kovtcharov/gaia that referenced this pull request Nov 7, 2026
Brings in amd#6898's argv-array process calls. The installer keeps main's
execFileSync import and drops the now-unused crypto import, since the
frozen-core path no longer downloads or verifies a bundled uv; the
bundled-core Jest mock now stubs execFileSync instead of execSync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(webui): remove shell string interpolation from Electron process spawning

1 participant