ensure_private_dir() skips permission hardening on Windows, leaving the auth token and the exec'd agent-workspace unprotected

Author: BarnsAWSCreated Sep 18, 2026Updated Sep 18, 2026

Labels: bug, security, windows

Description

paths.ensure_private_dir() skips permission hardening entirely on Windows, and the directories it protects hold an auth token and a path that is exec'd on import.

python
# src/browser_harness/paths.py
def ensure_private_dir(path: Path) -> Path:
    existed = path.exists()
    path.mkdir(parents=True, exist_ok=True)
    if not existed and sys.platform != "win32":
        os.chmod(path, 0o700)
    return path

config_dir(), runtime_dir(), tmp_dir() and workspace_dir() all route through it, so on Windows none of them get restricted permissions. auth.py has the same shape in _chmod_private().

The guard is understandable — os.chmod on Windows only toggles the read-only bit, so calling it there would be close to a no-op. The problem is that "unimplemented on this platform" is currently spelled as "not needed on this platform", silently.

Why it matters: what lives in those directories

1. The auth token. auth.py:save_auth_record() writes the OAuth / device-login record into config_dir(). On POSIX it lands 0600. On Windows it inherits whatever the parent directory allows.

2. A path that gets executed. helpers.py:_load_agent_helpers() runs:

python
p = AGENT_WORKSPACE / "agent_helpers.py"
if not p.exists():
    return
spec = importlib.util.spec_from_file_location("browser_harness_agent_helpers", p)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)          # arbitrary code, on import
for name, value in vars(module).items():
    ...
    globals()[name] = value              # injected into helpers' namespace

3. A dotenv that can flip a network setting. helpers.py:20 loads .env from both REPO_ROOT and AGENT_WORKSPACE. That matters because helpers.http_get() branches on an environment variable:

python
# src/browser_harness/helpers.py:628
def http_get(url, headers=None, timeout=20.0):
    if os.environ.get("BROWSER_USE_API_KEY"):
        from fetch_use import fetch_sync
        return fetch_sync(url, headers=headers, timeout_ms=int(timeout * 1000)).text
    # ... local urllib fallback

AGENT_WORKSPACE defaults to ~/.config/browser-harness/agent-workspace (paths.workspace_dir()), a well-known path.

Combined effect on Windows

Any process running as the user, or anything that can write to that well-known directory, can:

  • drop agent_helpers.py and get arbitrary code executed inside helpers the next time the harness is imported, with its globals merged into the module; and
  • drop .env containing BROWSER_USE_API_KEY=... and silently redirect http_get() from local urllib to the remote fetch.browser-use.com proxy.

Neither requires modifying anything in the installed package, and neither is visible to the user.

Reproduction

# Windows, any recent Python
python -c "from browser_harness import paths; print(paths.workspace_dir())"
# inspect the ACL on the printed directory -- it is the inherited user-profile ACL,
# with no restriction applied by browser-harness

# then, to show the exec path:
#   write any print() statement into <workspace_dir>/agent_helpers.py
#   import browser_harness.helpers
# the statement runs

Suggested fixes, smallest first

  1. Apply a real ACL on Windows instead of skipping. The usual 0700 equivalent is: icacls "<dir>" /inheritance:r /grant:r "%USERNAME%":(OI)(CI)F which can be shelled out once at directory creation, or done via pywin32 / ctypes if a dependency is unwanted.
  2. If (1) is not wanted, warn instead of staying silent. Emit a one-time warning on Windows that the config directory is not access-restricted, so the residual risk is visible rather than implicit.
  3. Gate _load_agent_helpers() behind an explicit opt-in (for example BH_AGENT_HELPERS=1), independently of platform. Implicit arbitrary code execution from a well-known path is a lot of authority to grant by default, and an opt-in costs the feature's users one environment variable.
  4. Consider whether .env should be read from AGENT_WORKSPACE at all, given that one of the variables it can set changes where HTTP requests are sent.

Notes

Found while auditing 0.1.13 before using admin.ensure_daemon and helpers.cdp as a library. Worth saying explicitly: the rest of the package audited well — cdp-use carries no outbound calls at all, the fetch-use proxy is correctly gated behind an environment variable rather than being on by default, auth.py does not touch browser cookies, and the telemetry module has a genuinely careful scrubber (its misapplication is already tracked in #681, which is not this issue). This one is narrower: a platform-conditional hardening step that is skipped without saying so, on paths that carry a token and an exec_module target.

Source: browser-use/browser-harness