openai/codex · error · GitToolingError

path escapes the repository root

Error message

path {path:?} escapes the repository root

What it means

GitToolingError variant for path escapes: a path joined against the worktree root resolves outside the repository root (via .. or symlink tricks). Snapshot restore refuses such paths to prevent writing outside the worktree.

Solutions

  1. Normalize the path lexically and reject any .. components that escape the root
  2. Join with the repo root, canonicalize, and verify the result stays under the root before proceeding
  3. Fix the caller to pass paths genuinely contained in the repository
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at codex-rs/git-utils/src/errors.rs:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of openai/codex@339751715c (2026-08-25). Data as JSON: /api/errors/7ed50222c37e9ecb. Report an issue: GitHub.

Appendix: source

Thrown at codex-rs/git-utils/src/errors.rs:27

#[derive(Debug, Error)]
pub enum GitToolingError {
    #[error("git command `{command}` failed with status {status}: {stderr}")]
    GitCommand {
        command: String,
        status: ExitStatus,
        stderr: String,
    },
    #[error("git command `{command}` produced non-UTF-8 output")]
    GitOutputUtf8 {
        command: String,
        #[source]
        source: FromUtf8Error,
    },
    #[error("{path:?} is not a git repository")]
    NotAGitRepository { path: PathBuf },
    #[error("path {path:?} must be relative to the repository root")]
    NonRelativePath { path: PathBuf },
    #[error("path {path:?} escapes the repository root")]
    PathEscapesRepository { path: PathBuf },
    #[error("failed to process path inside worktree")]
    PathPrefix(#[from] std::path::StripPrefixError),
    #[error(transparent)]
    Walkdir(#[from] WalkdirError),
    #[error(transparent)]
    Io(#[from] std::io::Error),
}

View on GitHub (pinned to 339751715c)