Skip to content

defence-in-depth: $CODEX_HOME from env is trusted verbatim — no canonicalization or outside-$HOME check #27

Closed

Description

@thehoff

Summary

resolve_codex_dir_from() (src/hooks/init.rs ~line 2773-2784) returns whatever $CODEX_HOME env var holds, without canonicalization or a "must be inside $HOME" guard. A malicious or accidentally-set env var (CODEX_HOME=/etc or CODEX_HOME=../../../tmp) would redirect init --codex / uninstall --codex writes and deletes there.

Caught by adversarial codex review of today's commit range.

Severity

Low / defence-in-depth. Same trust boundary as the binary's own process env — an attacker who can set the user's env vars already has equivalent access. The upstream OpenAI Codex CLI uses the same convention. So this is NOT a directly-exploitable vulnerability.

Filing as defence-in-depth because the binary makes destructive on-disk changes (file create/delete, file content overwrite in AGENTS.md), and adding a paranoid check is cheap.

Fix (proposed — optional)

Either:

  • (a) Canonicalize the resolved path (fs::canonicalize) and warn-or-bail if it escapes $HOME
  • (b) Just print the absolute resolved path before mutating, so an unintentional CODEX_HOME=... jumps out in interactive use
  • (c) Document the expectation in the help text + leave the code as-is

(c) is consistent with upstream behaviour. (a) is the strongest. (b) is the cheapest improvement.

Test plan (if fixed)

  • CODEX_HOME=/tmp/test-codex-home set → resolved path is used as-is (existing behaviour preserved)
  • CODEX_HOME=/etc triggers warning/bail (if option a)
  • CODEX_HOME unset → falls back to ~/.codex (existing behaviour)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions