Skip to content

bug: setup hook subprocess in _run_install inherits full host-agent environment — AGENT_API_KEY exposed to hook scripts #315

@yasinBursali

Description

@yasinBursali

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

  1. Create a user extension with a setup.sh that writes env > /tmp/leaked.txt.
  2. Install the extension via POST /api/extensions/{service_id}/install.
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions