Repository navigation
fix(security): --no-config and the loosening flags need a terminal when the user config sets [sandbox] or [secrets] (#867) - #872
Merged
Conversation
…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.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
5 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-sandboxrule) 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 ranenv -i(orsudo) and then a copy of tole looked like the owner, so--no-configdropped 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:Contextgainsttyanduser_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:Contextgainsttyandchild_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 carriesTOLE_AGENT_DEPTH,TOLE_AGENT_IDor 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 byagent_startor 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-configguard and once for the narrow guard; the user config is read for the--no-configrule only when the flag is given and there is no terminal.tole-coreis untouched.--no-configbullet 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.mdhas no security: the session marker is an environment variable; a child can clear or forge it #867 status line, so it is not touched.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-configfor 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::checkhas one caller (main.rs, right after argument parsing);narrow_guard::checkone caller (main.rs, beforeSettings::resolve);protected_keysis used by both; the--no-sandboxterminal rule insandbox_flags.rsis untouched;serve,acp,mcpkeep 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,--trustor 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 withmode = "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
terminal_guard_e2e(real binary, scrubbed environment, no terminal) with the terminal check forced to true by hand inmain.rs: the three refusal tests FAILED (--no-configunder[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.[sandbox],[secrets],[sandbox] and [secrets]), saysrun it yourself from a terminal, or remove the flag, or change the user config, and ends with(issue #867)(asserted withends_with); the refusal comes before the command (no listing printed).model,allowonly):--no-configworks 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 (python3pty.spawn, stdin and stderr terminals) keeps--no-configand a wider--allowwith a protected config (the test printsSKIPPEDand returns if python3 is missing; it ran here);tole acp --no-configis 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), andtole acp --allowis exempt; a process with only child variables and no terminal is not refused for a wider--allow.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).--no-confighas 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.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 testof 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, withTOLE_REQUIRE_BWRAP=1and--no-fail-fast: green. The attribution grep overorigin/develop..HEADis empty.scripts/review-local.shcannot run (cora is not installed here: exit 1, not a pass), so I self-reviewedgit diff origin/develop...HEADas an adversarial reviewer: the user config is read only when--no-configis 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-sandboxuses; the newnarrow_guardpath 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.