Skip to content

fix(security): refuse --no-config under an agent session and on serve, acp and mcp - #858

Merged
ajianaz merged 3 commits into
developfrom
security/no-config-under-session
Nov 15, 2026
Merged

ajianaz merged 3 commits into
developfrom
security/no-config-under-session

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

--no-config is refused under an agent session (TOLE_UNDER_SESSION set or child depth >= 1, the marker --sandbox/--no-sandbox already use) and for tole serve, tole acp and tole mcp, with an error naming the reason. An owner at a terminal keeps it.

Closes #855

Why

--no-config makes the project and user config None, so the owner's sandbox mode, [sandbox.consumers] (run_command, job_start, verify), secret release, [sensitive_files], [delegation], hooks, profiles and allow/trust lists all fall back to defaults. --sandbox/--no-sandbox are refused under a session (#684/#750); --no-config was not. A sandboxed command cannot reach this (check_session_argv stops run_command running tole), but anything that starts tole unsandboxed and inherits the marker (an agent_start or delegated child, a job) could run tole --no-config ... and drop the owner's policy.

A config whose parse fails is NOT a fail-open: load_user_config / load_project_config return the error and main exits (?); sandbox.policy() and consumers() are validated at load, so the .ok() in main.rs cannot swallow a bad value.

Changes

  • crates/tole-cli/src/no_config_guard.rs (new, small, so sandbox_flags.rs is untouched): check(given, ctx); Context { under_session, unattended_command }.
  • main.rs: call it right after argument parsing, before the review-gate env, config loading or any command; unattended class reuses sandbox_flag_class(..).0 (serve, acp, mcp). The serve/acp/mcp refusals of a config value they cannot honor used to say "use --no-config"; they now say to remove the key (refuse_unattended), mission keeps the old hint.
  • tests/layering.rs (new face module), CHANGELOG, docs/sandbox-design.md 6.2, --no-config help text.

Config-dropping escape hatches (verified in code):

Hatch What it drops Now
--no-config project + user config entirely refused under session and on serve/acp/mcp
--config <path> replaces only the project layer; the user layer is still loaded and is the only source of [sandbox], consumers, secrets widening, delegation, hooks routes, profiles unchanged; can replace list keys (on_pretool/posttool/turnend, allow, trust, mcp_server) and plan_mode = false like a flag (reported, not changed)
CODECORA_HOME (other, relative, or HOME unset) user config silently absent (no file, no error) unchanged: also the owner's legitimate override, cannot be told from an attack by env alone
flags/env --on-pretool, --allow, --trust, TOLE_TRUST, ... replace the whole list from config (flag > env > config) unchanged, by design of precedence
-c key=value, --no-user-config, TOLE_CONFIG do not exist n/a
GatePolicy::Skip commands (config, cron, hook, sandbox, approvals, skills, ...) never load the config unchanged

Callers / impact (cora is absent; grep, verified by hand): cli.no_config is read only in main.rs (project and user config loading, the new guard). Tests that pass --no-config: config_sensitive.rs, config_apply.rs, config_check.rs; none uses a session marker or serve/acp/mcp except the updated config_sensitive.rs helper (serve/acp/mcp now expect the edit-the-config hint and the guard refusal). Hint text consumers: main_gate_tests.rs, config_apply.rs, config_sensitive.rs. config_apply.rs unsupported_keys still says "use --no-config" (feature-missing key; shared by all faces, left as is).

Testing

  • New real-binary e2e tests/no_config_guard_e2e.rs: refused under TOLE_UNDER_SESSION and TOLE_AGENT_DEPTH, refused before run, refused for serve/acp (shell-tools) and mcp (shell-tools+mcp); control: same commands without the flag or without the marker are not refused. Unit tests in no_config_guard (hand-built context: attended owner keeps the flag; session and unattended refused). The harness has no pty, so the attended case is the unit test.
  • Fail without the fix (guard neutered by hand: check(false, ..)): 4 of the 5 e2e tests fail (session marker and depth, run, serve/acp, mcp; the control passes); restored, all pass.
  • cargo fmt --all --check; cargo clippy --workspace --all-targets --all-features -- -D warnings; cargo clippy -p tole-core -p tole-cli -p tole-tui --no-default-features --all-targets -- -D warnings; cargo test -p tole-cli with default features, --no-default-features, and --no-default-features --features shell-tools (no mcp): all green; layering test updated.
  • Cora: scripts/review-local.sh could not run (cora not on PATH). Agent adversarial review of git diff origin/develop...HEAD: the guard sits before every config read; the remaining paths to an unsandboxed tole without the owner's config are out of this PR and listed below.

Not fixed, for a decision:

  1. The marker is an env var: a script that strips TOLE_UNDER_SESSION and TOLE_AGENT_DEPTH (an unsandboxed hook/cron script) is not covered, like every security(trust): owner-only trust records can be written by the agent (tole CLI from run_command, file tools when the workspace holds the data dir) #684 guard. Proposal: also refuse --no-config without a terminal when the user config sets [sandbox] mode other than off or any consumer (same rule as --no-sandbox), reading the user file only to decide.
  2. CODECORA_HOME elsewhere / HOME unset: silent no user config. Proposal: warn at startup when the data dir is not the default and TOLE_UNDER_SESSION is set; and use try_exists() in load_user_config so an unreadable path fails closed (risky inside the command sandbox, where the data dir is masked).
  3. List keys replaced by a flag/env/--config (--on-pretool, --allow, --trust): proposal: pin user-layer policy keys so a flag can only narrow them under a session.
  4. -s sessions dir inside the workspace but outside .tole is writable by a sandboxed command, which undermines the append-only claim for that setup. Proposal: refuse (or protect read-only) a sessions dir that is inside the workspace when the consumers are on.

…, acp and mcp (#855)

--no-config made the project and user configs unread, so the owner's
sandbox mode, [sandbox.consumers], secret release and approval lists fell
back to their defaults for a child of an agent session. Unlike --sandbox
and --no-sandbox it was accepted under TOLE_UNDER_SESSION / a child agent,
and on the unattended faces.

It is now refused under an agent session and for serve, acp and mcp, with a
message naming the reason; an owner at a terminal keeps it. The refusals of
those faces for a config value they cannot honor no longer suggest the
flag they now refuse.
@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 3c326b9 into develop Nov 15, 2026
23 checks passed
@ajianaz
ajianaz deleted the security/no-config-under-session 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

Development

Successfully merging this pull request may close these issues.

security: --no-config (and CODECORA_HOME) drop the owner's sandbox and approval policy for a child of an agent session

2 participants