Skip to content

fix(repo): protect against --reference and --reference-if-able when cloning - #2348

Merged
Byron merged 1 commit into
mainfrom
repo-clone-options
Nov 16, 2026
Merged

Byron merged 1 commit into
mainfrom
repo-clone-options

Conversation

@Byron

@Byron Byron commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Tasks

  • refackiew

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

This work follows GHSA-j8pf-7m8v-xx38: applications passing unchecked clone options can unexpectedly let Git read objects from a caller-controlled local repository.

Require allow_unsafe_options=True for --reference and --reference-if-able in both Repo.clone() and Repo.clone_from(). The existing safety guard covers keyword arguments, multi_options, and abbreviated spellings. Record the advisory in the changelog.

Regression coverage checks rejection through both APIs and verifies that explicit opt-in still creates valid reference clones, reads committed objects, and records the requested alternate object store. The opt-in cases cover keyword arguments, joined and split multi_options, an accepted abbreviation, and paths containing spaces.

Validation: all 59 non-network clone tests passed on each of the CLI and Gix backends. Both rejection tests failed when the new safeguards were removed in memory. Ruff lint/format checks, ShellCheck, Bash syntax checking, and git diff --check passed.

Copilot AI balanced review requested due to automatic review settings November 16, 2026 03:49

Copilot AI 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.

🟡 Changes recommended

The added unsafe options lack regression tests for clone() and clone_from() across keyword arguments, multi_options, and abbreviated spellings, including verification that allow_unsafe_options=True still permits valid reference-based clones.

1 open issue
What changed in this PR

GitHub Copilot reviewed this focused change to GitPython’s clone safety checks, requiring explicit opt-in for caller-controlled reference repositories.

Changes:

  • Add --reference and --reference-if-able to the unsafe clone options list.
  • Record the related security advisory in the changelog.
File Description
git/​repo/​base.py Block reference-based clone options unless explicitly allowed.
doc/​source/​changes.rst Add the related security advisory link.

Review effort: Balanced

Comment thread git/repo/base.py Resolved
@Byron
Byron force-pushed the repo-clone-options branch from e266f2e to ee91408 Compare November 16, 2026 04:25
Copilot AI balanced review requested due to automatic review settings November 16, 2026 04:25

Copilot AI 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.

🟢 Approval recommended

No active review issues were identified for the change requiring explicit opt-in for reference-based cloning.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

<!-- agent -->
This change follows the clone safety issue recorded in
https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-j8pf-7m8v-xx38.
Passing unchecked clone keyword arguments can make Git read objects from a
caller-controlled local repository, which is surprising for callers that rely
on GitPython's default unsafe-option restrictions.

Add `--reference` and `--reference-if-able` to `Repo.unsafe_git_clone_options`,
requiring `allow_unsafe_options=True` for these options. The shared clone guard
also rejects abbreviated spellings and options supplied through `multi_options`.
Record the advisory in `doc/source/changes.rst`.

Copilot requested: "Please add regression cases for both `clone()` and
`clone_from()`, covering keyword arguments and `multi_options` (including
abbreviated spellings), and verify that `allow_unsafe_options=True` still permits
valid reference-based clones."

Extend the existing rejection cases and add local reference clones through both
APIs, using keyword arguments and joined or split `multi_options`. The opt-in
cases check the recorded alternate object store and read committed content,
including a reference path containing spaces. Initial repositories are generated
by the existing shell fixture rather than using the source checkout's history.

Co-authored-by: Jeroen <jpab.eemsterboer@gmail.com>
Co-authored-by: GPT 6.1 Sol <codex@openai.com>
Assisted-by: GPT 6.1 Sol
@Byron
Byron force-pushed the repo-clone-options branch from ee91408 to b056f39 Compare November 16, 2026 06:02
@Byron
Byron merged commit d6337df into main Nov 16, 2026
67 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.

2 participants