Bug Report: setup hook subprocess in _run_install inherits full host-agent environment — AGENT_API_KEY exposed to hook scripts
Severity: Medium
Category: Security
Platform: All (macOS, Linux, Windows/WSL2)
Confidence: Confirmed
Description
The _run_install worker function inside _handle_install runs the extension's setup hook via subprocess.run without specifying an env= argument. This means the subprocess inherits the complete environment of the host agent process, including AGENT_API_KEY, DREAM_AGENT_KEY, DASHBOARD_API_KEY, and any other secrets loaded at startup. By contrast, the _execute_hook path (used by _handle_hook and _handle_setup_hook) was explicitly designed with a minimal allowlist env. The two paths are inconsistent.
Affected File(s)
dream-server/bin/dream-host-agent.py (L936–944, inside _run_install in _handle_install)
Root Cause
# dream-host-agent.py L936-940 — setup hook in _run_install:
result = subprocess.run(
["bash", str(hook_path), str(INSTALL_DIR), GPU_BACKEND],
cwd=str(ext_dir),
capture_output=True, text=True,
timeout=SUBPROCESS_TIMEOUT_START,
# No env= argument — inherits full host-agent process environment
)
Compare with _execute_hook (L856-866) which builds an explicit allowlist:
hook_env = {
"PATH": ..., "HOME": ..., "SERVICE_ID": ...,
"SERVICE_PORT": ..., "SERVICE_DATA_DIR": ...,
"DREAM_VERSION": ..., "GPU_BACKEND": ..., "HOOK_NAME": ...,
}
proc = subprocess.Popen(..., env=hook_env, ...)
An extension author who controls setup.sh can read $AGENT_API_KEY or $DREAM_AGENT_KEY from the environment and exfiltrate them.
Platform Analysis
- macOS: Affected — host agent runs natively; its environment contains launchd-injected secrets.
- Linux: Affected — host agent runs as a systemd service; environment includes secrets passed via
EnvironmentFile=.
- Windows/WSL2: Affected — same environment inheritance applies in the WSL2 context.
Reproduction
- Create a user extension with a
setup.sh that writes env > /tmp/leaked.txt.
- Install the extension via
POST /api/extensions/{service_id}/install.
- Check
/tmp/leaked.txt — it will contain AGENT_API_KEY and other host-agent secrets.
Impact
A malicious or compromised extension package in the extensions library could exfiltrate the dashboard API key and host agent API key during install. This allows the extension to make authenticated calls to the host agent API (container start/stop, model activation, file deletion) without operator knowledge. Risk is highest in multi-user or cloud-hosted DreamServer deployments.
Suggested Approach
Pass the same minimal allowlist env dict used in _execute_hook to the subprocess.run call in _run_install. The INSTALL_DIR and GPU_BACKEND are already passed as positional argv, so hook scripts do not need them from the environment. This harmonises both install paths with the same security posture.
Filed by automated Python auditor after full-sweep review of Python changes merged 2026-04-06 → 2026-04-11 on upstream/main @ c0600ca.
Bug Report: setup hook subprocess in _run_install inherits full host-agent environment — AGENT_API_KEY exposed to hook scripts
Severity: Medium
Category: Security
Platform: All (macOS, Linux, Windows/WSL2)
Confidence: Confirmed
Description
The
_run_installworker function inside_handle_installruns the extension's setup hook viasubprocess.runwithout specifying anenv=argument. This means the subprocess inherits the complete environment of the host agent process, includingAGENT_API_KEY,DREAM_AGENT_KEY,DASHBOARD_API_KEY, and any other secrets loaded at startup. By contrast, the_execute_hookpath (used by_handle_hookand_handle_setup_hook) was explicitly designed with a minimal allowlist env. The two paths are inconsistent.Affected File(s)
dream-server/bin/dream-host-agent.py(L936–944, inside_run_installin_handle_install)Root Cause
Compare with
_execute_hook(L856-866) which builds an explicit allowlist:An extension author who controls
setup.shcan read$AGENT_API_KEYor$DREAM_AGENT_KEYfrom the environment and exfiltrate them.Platform Analysis
EnvironmentFile=.Reproduction
setup.shthat writesenv > /tmp/leaked.txt.POST /api/extensions/{service_id}/install./tmp/leaked.txt— it will containAGENT_API_KEYand other host-agent secrets.Impact
A malicious or compromised extension package in the extensions library could exfiltrate the dashboard API key and host agent API key during install. This allows the extension to make authenticated calls to the host agent API (container start/stop, model activation, file deletion) without operator knowledge. Risk is highest in multi-user or cloud-hosted DreamServer deployments.
Suggested Approach
Pass the same minimal allowlist
envdict used in_execute_hookto thesubprocess.runcall in_run_install. The INSTALL_DIR and GPU_BACKEND are already passed as positional argv, so hook scripts do not need them from the environment. This harmonises both install paths with the same security posture.Filed by automated Python auditor after full-sweep review of Python changes merged 2026-04-06 → 2026-04-11 on upstream/main @ c0600ca.