Skip to content

Confine staged patch paths to the parent worktree#30844

Open
bookholt-oai wants to merge 9 commits into
codex/psec-4394-git-02-effective-patch-pathsfrom
codex/psec-4394-git-03-path-containment
Open

Confine staged patch paths to the parent worktree#30844
bookholt-oai wants to merge 9 commits into
codex/psec-4394-git-02-effective-patch-pathsfrom
codex/psec-4394-git-03-path-containment

Conversation

@bookholt-oai

@bookholt-oai bookholt-oai commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Why

Even a correctly parsed patch path can pass through a symlink, junction, submodule, or Git metadata directory. Git staging must not follow those paths outside the parent worktree or recurse into an unvalidated directory.

Approach

Resolve every existing parent directory for each patch path and make sure it stays inside the intended worktree and outside its private or shared Git metadata. Reject exact directory leaves that Git could stage recursively, including directory-valued Windows reparse points.

Keep safe file-symlink replacement working, and cache repeated prefix checks within the operation.

This PR is stacked on #30837 and should land after it.

Testing

  • 12 focused patch-containment tests passed.
  • All 45 codex-git-utils tests in this stack layer passed.
  • Coverage includes escaping aliases, Git metadata, submodules, safe file symlinks, directory leaves, and Windows junctions.
  • Clippy, formatting, Bazel, lock, and diff checks passed. Native Windows junction coverage runs in CI.

@bookholt-oai bookholt-oai marked this pull request as ready for review July 1, 2026 17:35

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c21e78bbd6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

for path in confined.into_exact_leaves()? {
let joined = git_root.join(&path);
if let Ok(metadata) = std::fs::symlink_metadata(&joined) {
if leaf_is_traversable_directory(metadata.file_type()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Allow initialized submodule gitlinks

When reverting a patch that updates an initialized submodule, the patch path is the submodule path itself while the checkout exists as a directory; this guard returns PermissionDenied before git apply -R can run. Git documents submodules as mode 160000 entries that record a commit “as a directory entry” (git-scm.com), and git add <submodule> updates that gitlink rather than recursively adding contents, so valid submodule rollbacks now fail.

Useful? React with 👍 / 👎.

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.

1 participant