Skip to content

fix(security): deny same-user inspection of tole, scrub the mission verify command and stop gates - #687

Merged
ajianaz merged 4 commits into
developfrom
security/proc-environ-verify-scrub
Nov 13, 2026
Merged

ajianaz merged 4 commits into
developfrom
security/proc-environ-verify-scrub

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Two HIGH findings of the #594 audit, fixed together because each one alone leaves the other open:

Why

The ENV-1 scrub only edits the environment a child starts with. /proc/<ppid>/environ showed the child every secret tole was exec'd with (provider key, GITHUB_TOKEN, TOLE_SERVE_TOKEN, webhook keys), whatever the scrub removed. Separately, run_verify ran sh -c with tole's full, unscrubbed environment, without approval, and the command usually runs code the agent just wrote (cargo test runs build scripts and tests). The stop gates ran as the hook consumer, which keeps GITHUB_TOKEN by default, and they also usually run workspace code.

Changes

  • tole_core::process_guard (new, not feature-gated): deny_inspection() (Linux: PR_SET_DUMPABLE 0; a no-op returning Ok elsewhere) and inspection_denied(). libc was already a dependency of both crates; no new dependency. The Linux code is behind cfg(target_os = "linux").
  • tole-cli main: calls it before argument parsing, so before any thread or child exists. serve, mission, cron, hook and child agents (tole run processes) all start in this main, so there is no other entry point to cover. tole-replay (an eval binary behind the replay feature) does not call it.
  • secret_release: new consumers VERIFY = "verify" and TURNEND = "turnend". The default release does not bind them.
  • mission.rs run_verify: scrub_env_for(.., VERIFY).
  • hooks.rs ProcessHook::run_raw (used only by the turn-end gates): consumer turnend instead of hook. Pre/post tool hooks keep hook and its GITHUB_TOKEN default.
  • Docs: threat model (new "parent process" row with the residual, ENV-1 row, the stop-gate and mission paragraphs), secrets-integrations-design.md §9 table and rationale, README [secrets] paragraph, and two CHANGELOG [Unreleased] entries. The verify and stop-gate one is marked BREAKING with a migration note.

Decisions to check

  • Not removing secrets from tole's own environment. It would not close the leak: /proc/<pid>/environ shows the exec-time block, which unsetenv does not erase. tole also reads several secrets lazily (provider chain, [secrets] grants passed to gh/git/hooks/MCP by inheritance), so removing them would break those consumers. And remove_var is unsound once threads may exist. Non-dumpable is what actually closes /proc/<pid>/environ and /proc/<pid>/mem.
  • Side effects of non-dumpable: tole writes no core dumps, and attaching a debugger to a running tole needs root. tole's own /proc/self/environ becomes root-owned too; tole never reads it. /proc/<pid>/stat stays world-readable, so delegation lease liveness is unchanged, and a test covers that.
  • Two consumers, not one: verify and turnend are separate so an owner can grant one without the other.
  • Residual (stated in the threat model): a process running as root or with CAP_SYS_PTRACE still reads tole's files. macOS (KERN_PROCARGS2) and Windows expose a same-user process's environment by other means. A secret the owner keeps in a readable file (a config, ~/.netrc) is readable by any same-user child. These belong to the sandbox work in feat(plugins): sandbox wrapper for third-party stdio servers, lazy start, tool retrieval by meaning #601. Also, the flag resets to 1 in an exec'd child, which is expected: each tole child sets it again in its own main.

Testing

  • New crates/tole-core/tests/process_guard.rs (Linux). The test re-runs itself with a canary secret in its exec-time environment, so the canary sits in /proc/<pid>/environ. When run as root, it re-runs as nobody, because root bypasses the check. Control: before the guard, a child does read the canary through /proc/$PPID/environ. After the guard, the read fails and the canary is absent. A second test checks that current_exe, /proc/self/stat, /proc/self/cgroup and a child's read of the parent's /proc/<pid>/stat still work.
  • New end-to-end tests in crates/tole-cli/tests/mission_e2e.rs with the real binary, a mock provider, TOLE_API_KEY and GITHUB_TOKEN set. A tole mission --verify and a tole run --on-turnend <gate.sh> each record printenv and tr '\0' '\n' < /proc/$PPID/environ.
    • verify_and_stop_gates_get_no_secret_by_default: neither secret appears in any of the four outputs.
    • a_secrets_grant_restores_a_token_for_verify_and_stop_gates: with GITHUB_TOKEN = { tools = ["verify", "turnend"] }, both children see the token and still not the provider key.
  • Red on develop and mutation checks: each was run and failed as expected.
    • Removing the run_verify scrub fails both e2e tests ("verify env holds the provider key").
    • Putting the gate back on hook fails both ("gate env holds GITHUB_TOKEN" / "lacks the granted token").
    • Removing the deny_inspection call from main fails the default test ("tole's environ read by verify holds the provider key").
    • Making deny_inspection set dumpable to 1 fails the core test.
  • The mission repro from security(mission): --verify runs agent-written code with tole's full, unscrubbed environment #676 (mock provider, --verify "printenv > verify_env.txt") now prints neither TOLE_API_KEY nor GITHUB_TOKEN (status complete, verify failures 0).
  • Gates: cargo fmt --all --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace, cargo test -p tole-core --no-default-features, cora review --no-llm --base origin/develop (no issues). The non-Linux branches of process_guard compile for aarch64-apple-ios (checked in a scratch crate, because ring needs an iOS C toolchain to build all of tole-core).

Closes #675
Closes #676

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit bb39167 into develop Nov 13, 2026
15 checks passed
@ajianaz
ajianaz deleted the security/proc-environ-verify-scrub branch November 20, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants