Skip to content

Start the tray's child programs with an allow-listed environment - #4350

Merged
mstomar125 merged 1 commit into
mainfrom
issue-4306-env
Nov 25, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-4306-env

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

The tray started ps, taskkill and the desktop app with the daemon's full environment. They now go through packages/daemon/src/child_env.rs, which clears the environment and rebuilds it from an allow-list: PATH/HOME/USER/LANG/TMPDIR and the Windows loader variables for helpers; for the app also the display session, Windows profile folders, and the product's own names (NODESPACE_*, NODESPACED_*, XDG_*, LC_*). Credentials in the daemon's environment no longer reach these children.

The agent's PTY child and tool programs already clear their environment inside nodespace-agent (untouched). A scan test fails if any other production code in the daemon crate uses a bare process-start call, so a new spawn cannot skip this.

Security-sensitive: changes what environment child processes receive. The allow-list for the app is a judgement call (a variable the app needs and is missing from the list would be absent on a given platform; the Windows and Linux lists are not run here).

Tests added (all mutation-checked): helper gets only base vars (removing env_clear fails it), app gets its names and not a planted credential (skipping the UI names fails it), source scan (reverting tray's ps to a bare spawn fails it). Existing tray tests pass; bun run test:changed passed.

Not covered: the design document states every child process runs scrubbed; that document lives in the NodeSpace workspace and was not edited. Spawns in the CLI and in desktop-app (daemon_setup, which starts the daemon and system tools like launchctl from the app process, not the daemon) are not changed here.

Closes #4306

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (static review plus the checks listed; two non-blocking follow-ups)

Ran: cargo fmt --check -p nodespace-daemon pass; cargo test -p nodespace-daemon --lib child_env (3 tests) pass. NOT run: clippy, the tray tests, the mutation checks, bun run test:changed (the machine was overloaded and I was told to stop queueing builds). The merge gate must pass. Windows and Linux lists judged by reading only.

Spawn sites: every Command::new in packages/daemon/src outside tests is now the three in tray.rs (ps at tray.rs:70, taskkill at :138, app launch at :801); no other process start, open/xdg-open/osascript call or alias import exists in the crate (grep). The only other Command::new is a test in services/remote_confirmation.rs:1026.

macOS app launch: HOME, PATH, TMPDIR, USER, LANG, SHELL, TERM, CF_USER_TEXT_ENCODING are kept, plus NODESPACE*/NODESPACED/XDG_/LC_*. The app itself reads almost no environment (NODESPACE_HOME, HOME). The database variable set after the clear (tray.rs:808) is kept. I see no way the clear breaks the macOS launch.

Findings, non-blocking:

  1. child_env.rs:107 scan hole: it cuts each file at the FIRST #[cfg(test)] text, but some files have an early #[cfg(test)] on a production item, so everything after it is not scanned: durable_write.rs:47, user_presence.rs:207, services/database_manager.rs:401 (and the rest of those files). A bare Command::new added to those files after that line would pass. Today there is none, but the guard is weaker than its comment says. Suggest cutting at #[cfg(test)]\nmod tests / mod tests {, or scanning with a real parse. Also missed: use std::process::Command as C; C::new( and Command::new ( with a space. (I did not run a mutation to prove the hole; it is from reading.)
  2. Lists: Linux app launch drops GDK_BACKEND, WEBKIT_, GTK_, LANGUAGE, LOGNAME, LD_LIBRARY_PATH (AppImage), and proxy/SSL_CERT_FILE variables for the app's own network use; Windows drops ProgramFiles, ProgramW6432, PROCESSOR_ARCHITECTURE, NUMBER_OF_PROCESSORS, OS. Probably fine, cannot be checked here; worth one manual launch on each OS.

…vironment

A child_env module clears the inherited environment and rebuilds it from an allow-list for the tray's ps, taskkill and desktop-app spawns. A scan test fails on any other production Command::new in the daemon crate.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@mstomar125
mstomar125 merged commit 73885e8 into main Nov 25, 2026
@mstomar125
mstomar125 deleted the issue-4306-env branch November 25, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only the agent's PTY child gets a scrubbed environment; the tray spawns children with the daemon's

1 participant