Skip to content

prevent out-of-repo access when manipulating references.#2134

Merged
Byron merged 2 commits intomainfrom
validate-ref-creation
Apr 28, 2026
Merged

prevent out-of-repo access when manipulating references.#2134
Byron merged 2 commits intomainfrom
validate-ref-creation

Conversation

@Byron
Copy link
Copy Markdown
Member

@Byron Byron commented Apr 28, 2026

This previously made it possible to create, modify and delete files outside outside of the repository, which is a problem if inputs aren't trusted.

Tasks

  • refackiew
  • pass CI
  • review

This previously made it possible to create, modify and delete files outside outside
of the repository, which is a problem if inputs aren't trusted.

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
Copilot AI review requested due to automatic review settings April 28, 2026 01:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens ref/reflog filesystem path handling to prevent path traversal and other escapes that could otherwise write, rename, or delete files outside the repository’s git directories when ref inputs are untrusted.

Changes:

  • Add validated path resolution (realpath + commonpath) for ref and reflog paths to ensure they stay within the repo’s git/common dirs.
  • Use validated ref paths in SymbolicReference operations (create/set/delete/rename) and in RemoteReference.delete.
  • Add regression tests to ensure path traversal attempts are rejected.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
git/refs/symbolic.py Introduces validated path helpers and applies them to ref file operations.
git/refs/remote.py Validates remote ref paths and uses validated filesystem paths when deleting ref files.
git/refs/log.py Uses validated reflog path construction.
test/test_refs.py Adds regression tests ensuring path traversal is rejected for various ref operations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread git/refs/remote.py Outdated
Comment thread test/test_refs.py
Copilot AI review requested due to automatic review settings April 28, 2026 02:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread git/refs/symbolic.py Outdated
@Byron Byron force-pushed the validate-ref-creation branch from e90b57c to 44e8cc5 Compare April 28, 2026 02:37
Copilot AI review requested due to automatic review settings April 28, 2026 02:51
@Byron Byron force-pushed the validate-ref-creation branch from 44e8cc5 to 38f91f0 Compare April 28, 2026 02:51
@Byron Byron force-pushed the validate-ref-creation branch from 38f91f0 to 8c6d5ee Compare April 28, 2026 02:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread git/refs/symbolic.py
Comment thread test/test_refs.py
Comment thread git/refs/log.py
@Byron Byron force-pushed the validate-ref-creation branch from 8c6d5ee to c57e127 Compare April 28, 2026 03:12
@Byron
Copy link
Copy Markdown
Member Author

Byron commented Apr 28, 2026

On Byron's behalf: Review pass on the latest Copilot comments:

  • I addressed the RefLog.path() docstring comment in c57e127b by documenting the new ValueError case.
  • I am intentionally not taking the two symlink-hardening suggestions in this review commit. They reintroduce explicit segment walking/path manipulation that this simplification was meant to avoid, and they broaden the patch from validating attacker-controlled ref names to defending against pre-existing attacker-controlled symlinks under .git/refs. The current patch keeps the implementation to ref-name validation plus realpath/commonpath, with symlink coverage only where realpath provides that signal.

Consolidate follow-up fixes from review and CI:

- fix lint and mypy issues in reference log path handling
- validate remote reference paths before invoking git branch deletion
- add symlink escape coverage where realpath resolves symlinks
- ensure temporary test repositories release git resources during cleanup

Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>
@Byron Byron force-pushed the validate-ref-creation branch from c57e127 to 4af8463 Compare April 28, 2026 05:13
@Byron Byron merged commit dbfa264 into main Apr 28, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants