Confine staged patch paths to the parent worktree#30844
Conversation
There was a problem hiding this comment.
💡 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()) { |
There was a problem hiding this comment.
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 👍 / 👎.
…x/psec-4394-git-03-path-containment
…x/psec-4394-git-03-path-containment
…x/psec-4394-git-03-path-containment
…x/psec-4394-git-03-path-containment
…x/psec-4394-git-03-path-containment
…x/psec-4394-git-03-path-containment
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
codex-git-utilstests in this stack layer passed.