Skip to content

fix(security): --no-config and the loosening flags need a terminal when the user config sets [sandbox] or [secrets] (#867) - #872

Merged
ajianaz merged 1 commit into
developfrom
fix/867-terminal-for-no-config
Nov 16, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/867-terminal-for-no-config

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

Option D+A of #867 (chosen by the owner). Besides the session marker, --no-config (the #855 guard) and the policy-loosening flags (the #865 narrow-only check) need a TERMINAL (stdin AND stderr, the --no-sandbox rule) when the USER config sets [sandbox] or a non-empty [secrets]. When the user config sets neither, nothing changes. The marker is documented as NOT a security boundary; the command sandbox is. No new marker. Closes #867.

Why

Every guard that tells a script from the owner keys on TOLE_UNDER_SESSION / TOLE_AGENT_DEPTH, environment variables. A script that ran env -i (or sudo) and then a copy of tole looked like the owner, so --no-config dropped the user config's sandbox, consumers and secret release, and --allow / --trust / the hook flags replaced its lists. A script has no terminal. Item 1 of the not-fixed list of #858.

Changes

  • no_config_guard.rs: Context gains tty and user_protects; a new rule after the two security: --no-config (and CODECORA_HOME) drop the owner's sandbox and approval policy for a child of an agent session #855 refusals: no terminal AND the user config protects something is --no-config needs a terminal (stdin and stderr) because the user config sets [sandbox] and/or [secrets], which it would drop; run it yourself from a terminal, or remove the flag, or change the user config (issue #867). protected_keys(cfg) is the one definition: the [sandbox] table (mode, profiles, servers, consumers: cfg.sandbox.is_some()) and a non-empty [secrets]. user_config_protects(path) reads the user config only to decide, fail closed: absent file or path means nothing protected; a file that cannot be inspected or does not parse is reported as protected ("cannot be inspected" / "cannot be read or parsed"), keeping the strict rule.
  • narrow_guard.rs: Context gains tty and child_variables; applies(protected) is now the marker path as before (not on serve/acp/mcp), OR an unmarked process with no terminal under a protected user config that is not a child tole itself started (it carries TOLE_AGENT_DEPTH, TOLE_AGENT_ID or the delegation variables). The child variables exempt ONLY on this new path and never a marked process (the depth-1 script case of security: flags, env and --config replace the owner's policy lists instead of merging or being refused #865 stays guarded). A tole started by agent_start or delegation has no terminal either, so without that exemption every legitimate child of a protected owner would be refused; the exemption is forgeable (a script can set the variable), like the marker, and the docs say so.
  • main.rs: has_terminal (stdin and stderr terminals) computed once for the --no-config guard and once for the narrow guard; the user config is read for the --no-config rule only when the flag is given and there is no terminal.
  • tole-core is untouched.
  • Docs: design note §6.2 (the --no-config bullet and the policy-list bullet), threat-model row, README (one sentence), CHANGELOG (Fixed, with the behaviour change for scripts spelled out). All state that the marker and the terminal are NOT a security boundary (a deliberate pty, a copied binary run with a cleared environment, or a forged child variable gets past them) and that the command sandbox, which masks the data dir, is. docs/epics.md has no security: the session marker is an environment variable; a child can clear or forge it #867 status line, so it is not touched.
  • Existing tests adjusted for the new rule (not weakened): no_config_guard_e2e (no marker + [sandbox] user config + no terminal is now refused by security: the session marker is an environment variable; a child can clear or forge it #867; an unprotected config works), user_config_absent_e2e (the security: a missing or unreadable user config is silent (CODECORA_HOME, unset HOME, unreadable path) #864 "way out" is --no-config for an owner at a TERMINAL; without one and with an uninspectable user config it is refused by security: the session marker is an environment variable; a child can clear or forge it #867).

Callers and impact (grep, each checked): no_config_guard::check has one caller (main.rs, right after argument parsing); narrow_guard::check one caller (main.rs, before Settings::resolve); protected_keys is used by both; the --no-sandbox terminal rule in sandbox_flags.rs is untouched; serve, acp, mcp keep their #855 refusal text and the narrow exemption. Behaviour change: a CI job or script WITHOUT a terminal that passes --no-config, or a wider --allow, --trust or fewer hook flags than a list the user config sets, against a user config that also sets [sandbox] or [secrets], is now refused (put the pattern in the user config, or run it from a terminal); the same job against a user config that sets neither key is unchanged. A [sandbox] table counts even with mode = "off" (the spec says "sets [sandbox]"; it is the simpler and the conservative reading). Tests to rerun: terminal_guard_e2e, no_config_guard_e2e, narrow_guard_e2e, user_config_absent_e2e, config_apply, config_check, sandbox_flags_cli, delegated_approval_e2e, serve_delegation_e2e, layering.

Testing

  • Fail without the fix: terminal_guard_e2e (real binary, scrubbed environment, no terminal) with the terminal check forced to true by hand in main.rs: the three refusal tests FAILED (--no-config under [sandbox], [sandbox.consumers] only, [secrets], both; a user config that cannot be read or inspected; the loosening path); the unprotected, pty, face and child-variable tests passed as controls; restored, all 6 pass.
  • Refusal text, checked: names the keys ([sandbox], [secrets], [sandbox] and [secrets]), says run it yourself from a terminal, or remove the flag, or change the user config, and ends with (issue #867) (asserted with ends_with); the refusal comes before the command (no listing printed).
  • Negatives: a user config that protects nothing (none, model, allow only): --no-config works with no terminal and no marker, and under the marker the security: --no-config (and CODECORA_HOME) drop the owner's sandbox and approval policy for a child of an agent session #855 text is exactly as before; an owner on a REAL pty (python3 pty.spawn, stdin and stderr terminals) keeps --no-config and a wider --allow with a protected config (the test prints SKIPPED and returns if python3 is missing; it ran here); tole acp --no-config is still refused with the security: --no-config (and CODECORA_HOME) drop the owner's sandbox and approval policy for a child of an agent session #855 text (not security: the session marker is an environment variable; a child can clear or forge it #867), and tole acp --allow is exempt; a process with only child variables and no terminal is not refused for a wider --allow.
  • Unit tests: the new refusal and its text, protected_keys (sandbox, consumers only, sandbox plus secrets, nothing), the fail-closed read (absent, parse error, uninspectable path, valid), and the narrow guard's no-terminal path (protected refuses, plain config, terminal, child variables and faces are unchanged, child variables never exempt a marked process).
  • Ambiguity noted: the task said "no protected key set -> --no-config still works under the marker". Under the marker --no-config has been refused outright since security: --no-config (and CODECORA_HOME) drop the owner's sandbox and approval policy for a child of an agent session #855 whatever the config says, so I kept that (unchanged) and test that the new rule adds nothing when no key is protected.
  • Gates on the final head: 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 clippy -p tole-cli --no-default-features --features shell-tools --all-targets -- -D warnings; cargo check -p tole-core --no-default-features --tests; cargo test of tole-core and tole-cli (default), of tole-core, tole-cli, tole-tui with --no-default-features, and of tole-cli with --no-default-features --features shell-tools, with TOLE_REQUIRE_BWRAP=1 and --no-fail-fast: green. The attribution grep over origin/develop..HEAD is empty.
  • How it was reviewed: scripts/review-local.sh cannot run (cora is not installed here: exit 1, not a pass), so I self-reviewed git diff origin/develop...HEAD as an adversarial reviewer: the user config is read only when --no-config is given and no terminal exists (so ordinary runs pay nothing and a parse error elsewhere is still reported by the normal loader); every unreadable state keeps the strict rule; the terminal definition is the one --no-sandbox uses; the new narrow_guard path cannot exempt a marked process; faces keep their behaviour. Residual, documented: a deliberate pty, a cleared environment with a copied binary, a forged child variable. An independent reviewer will review this PR before merge.

…en the user config sets [sandbox] or [secrets] (#867)

Besides the session marker, which a script can strip, --no-config now needs
stdin and stderr to be terminals when the USER config sets [sandbox] or a
non-empty [secrets] (read fail closed, only to decide), and the narrow-only
check applies to an unmarked process with no terminal under such a config
(a tole that tole itself started and the faces are exempt). A user config that
sets neither is unchanged. Not a boundary; the sandbox is. No new marker.
@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 d78b70d into develop Nov 16, 2026
23 checks passed
@ajianaz
ajianaz deleted the fix/867-terminal-for-no-config branch November 20, 2026 08:38
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: the session marker is an environment variable; a child can clear or forge it

2 participants