Skip to content

fix(#798): stop the nested Codex sandbox from handing model-run commands its own secrets - #801

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/798
Sep 26, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/798

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #798.

What changed

#751/#792 widened _codex_child_env()'s allow-list (CODEX_API_KEY, HTTPS_PROXY/HTTP_PROXY/NO_PROXY, SSL_CERT_FILE/NODE_EXTRA_CA_CERTS, matched case-insensitively) so the nested codex exec summarizer subprocess could authenticate and reach the network through a proxy. That allow-list only ever governed the environment subprocess.run gives to Codex's OWN process. #724 already established that Codex's --sandbox read-only still runs whatever shell command the model issues -- it denies writes and network, not command execution -- so a transcript-injected instruction could get the model to run a shell command inside that sandbox and read those same secrets directly out of THAT command's own environment. That is the gate-3 gap #798 names.

_build_codex_cmd now appends -c shell_environment_policy.inherit=none to the codex exec argv -- Codex's own documented mechanism (confirmed against the locally-installed codex-cli 0.153.2's own --help output and the official Codex manual, fetched live) for controlling what environment a command IT SPAWNS receives, independently of what its own process receives. _codex_child_env() is unchanged and still reaches Codex's own process via the env= kwarg exactly as before, so #751's auth/proxy fix is not regressed.

Trade-off named in the diff

inherit=none gives a spawned command NO environment at all, not only no secrets -- no PATH/HOME/locale either. Accepted because this summarizer's job never depends on a spawned command succeeding. Also named: the verification above is pinned to codex-cli 0.153.2, not re-verified against 0.150.1 (the version this repo's README reports as observed working), though shell_environment_policy is a long-standing Codex config key rather than something new in 0.153.2. And: the new unit tests can only assert the literal flag is present in the argv Codex's own process receives -- none can spawn a real codex exec to confirm the CLI actually honors this flag at runtime, so that trust boundary is reasoned, not observed.

Tests

Red (python3 -m pytest tests/test_summarizer_sandbox_724.py -q --no-cov): 2 failed, 14 passed -- _build_codex_cmd carried no -c override at all pre-fix. Green after the fix: 16 passed. Also ran the same file plus tests/test_haiku.py together: 106 passed, 0 failed. Full suite not run locally (CI is the gate, per this repo's own CLAUDE.md).

Self-review

Two spawned rounds (an Explore-type reviewer against the diff/checklist, and oss:auditor against the 4-class audit brief) found three issues total, all fixed doc-only in a second commit: the inherit=none all-or-nothing trade-off was unstated, the 0.153.2-vs-0.150.1 version claim sat unreconciled with an adjacent 0.150.1-verified claim in the same docstring, and the runtime trust-boundary (does codex-cli actually honor this flag) was implied but not stated. tree_snapshot compare returned clean before and after both rounds.

[AI-generated]

fdaviddpt and others added 2 commits September 26, 2026 18:53
… to model-issued commands

#751 widened _codex_child_env's allow-list (CODEX_API_KEY, the proxy
vars, the CA bundle) so the nested codex exec summarizer could
authenticate and reach the network -- but that allow-list only ever
governs the env subprocess.run gives to Codex's own process. Codex's
--sandbox read-only still runs whatever shell command the model issues
(#724), and nothing here stopped such a command from reading those same
secrets directly out of its own environment.

_build_codex_cmd now passes -c shell_environment_policy.inherit=none,
confirmed against codex-cli 0.153.2's own --help and the official Codex
manual (fetched 2026-09-26) to be Codex's own documented mechanism for
controlling what environment a command it spawns receives, independently
of what its own process received. _codex_child_env's allow-list keeps
reaching Codex's own process via the env= kwarg exactly as before, so
auth and proxy access are unaffected.

Added a red-then-green test asserting the -c override is present, plus a
positive control in the same call: CODEX_API_KEY and HTTPS_PROXY still
reach Codex's own process while the override that keeps them from a
spawned command is also present.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…rsion-pin gap

Self-review (Explore + oss:auditor) on the #798 fix found two real,
non-blocking gaps in the prose, not in the mechanism:

- inherit=none strips a spawned command's environment entirely --
  PATH/HOME/locale included, not only secrets. That is an accepted
  trade-off (this summarizer never depends on a spawned command
  succeeding), but the docstring, the block comment, and the changelog
  fragment described only the security benefit and never said so.
- The docstring cited codex-cli 0.153.2 as the verification target for the
  new -c override, while this repo's README pins 0.150.1 and an adjacent,
  untouched sentence in the SAME docstring already carries a 0.150.1
  verification claim for a different flag. Reconciled: noted explicitly
  that shell_environment_policy was not re-verified against 0.150.1,
  reasoned (not observed) to be present there too since it is a
  long-standing Codex config key.

Also names, rather than leaves implicit, the residual trust boundary the
auditor flagged as unranked: a unit test can only assert the argv carries
the override string, never that codex-cli genuinely honors it at runtime --
that is not verifiable from this codebase.

No code change; pipeline/haiku.py's docstrings, the block comment above
_CODEX_CHILD_ENV_ALLOW, and changelog.d/798.fixed.md only.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit b2f6382 into main Sep 26, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/798 branch September 26, 2026 20:46
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.

Codex child-env allow-list widened by #751/#792 may leak API key / proxy credentials to model-run shell commands

1 participant