fix: cache file permission window, export-env quoting, shell guardrail gap - #22
Merged
DustyStudy merged 3 commits intoSep 22, 2026
Merged
Conversation
put() wrote a new token/credentials file with Path.write_text() (mode dictated by the process umask, often world-readable) and only restricted access with chmod() afterward — a real window during which a brand-new cache file was readable by anyone on POSIX systems. Create the file with os.open() and an explicit 0o600 mode instead, which sets the permissions atomically at creation time. Best-effort as before on Windows, where the mode argument doesn't map onto real ACLs.
… shell - export_env_lines() interpolated credential values straight into `export KEY="value"` / `$env:KEY = "value"` with no quoting. AWS credentials never actually contain shell metacharacters, but the values still come from an external API response, so the interpolation itself shouldn't be a foot-gun for whatever eval's the output. POSIX lines now go through shlex.quote(); PowerShell lines escape backtick/"/$. - guardrails.yaml documents protected_account_ids as blocking "ANY command via `orgctl exec`/`shell`", but spawn_shell() never called into guardrails at all. There's no single "command" to pattern-match against for an interactive session, so pull the protected-account check out of check_command() into its own check_protected_account() and call that from spawn_shell() too. export-env/creds-process remain intentionally uncovered (see the updated comment in guardrails.example.yaml) since they're meant to work non-interactively.
README's "Security model" and THREAT_MODEL's asset table both said credentials are never exported outside the one child process/shell that requested them, full stop — but export-env and creds-process print credentials to stdout by design (for eval into the current shell, or for AWS tooling's credential_process protocol). Scope the claim to exec/shell and describe what export-env/creds-process actually guard instead (quoting, and stdout/stderr separation) — see the exec_cmd fix in this same PR for the quoting itself.
DustyStudy
deleted the
fix/cache-perms-export-quoting-shell-guardrails
branch
September 22, 2026 03:03
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.
Summary
Follow-up to #18/#20: the remaining lower-priority items from the original review — cache file permissions,
export-envquoting, a real guardrail gap onshell, and the doc claims that didn't match. One commit per fix, each with regression tests checked against the pre-fix code.chmodlocked them down.put()wrote withPath.write_text()(mode from the process umask) thenchmod'd afterward — a real window on POSIX systems during which a brand-new token/credentials file was readable by anyone. Now created viaos.open()with an explicit0o600mode, set atomically. Still best-effort on Windows, same as before.export-env's output wasn't quoted. Credential values were interpolated straight intoexport KEY="value"/$env:KEY = "value". AWS credentials never actually contain shell metacharacters, but the values come from an external API response, so the interpolation itself shouldn't be a foot-gun for whateverevals it. POSIX lines now go throughshlex.quote(); PowerShell lines escape`/"/$.protected_account_idsdidn't actually covershell, despiteguardrails.yamldocumenting it as blocking "ANY command viaorgctl exec/shell" —spawn_shell()never called into guardrails at all. Pulled the protected-account check out ofcheck_command()into its owncheck_protected_account()and wired it intospawn_shell()too.export-env/creds-processstay intentionally uncovered (documented in the example config) since they're meant to work non-interactively.export-env/creds-processprint them to stdout by design. Scoped the claim toexec/shelland described what those two commands actually guard instead.Verification
ruff check,ruff format --check,mypy src: clean.pytest: 116 passed, 5 skipped (POSIX-only checks that don't apply on the Windows dev box — they run for real on theubuntu-latestCI runners); coverage 70% → 73%.git stashper file) and confirmed to fail there for the right reason, then pass with the fix. Newtests/test_export_env.pyincludes an end-to-end test that actuallyevals the generated POSIX line in a real shell with a value containing shell metacharacters, and checks the value comes back unmangled rather than executed.Not in this PR
Two intentionally-out-of-scope items surfaced along the way and documented rather than changed:
export-env/creds-processdon't get blocked byprotected_account_ids(by design — see commit 3), andorgctlstill has no signature/integrity check onorgs.yaml/guardrails.yamlthemselves (pre-existing, named in the threat model's "explicitly out of scope" section).