Skip to content

fix: prevent environment expansion in remote URLs#2181

Merged
Byron merged 1 commit into
mainfrom
fix-env-var-exfiltration
Jul 22, 2026
Merged

fix: prevent environment expansion in remote URLs#2181
Byron merged 1 commit into
mainfrom
fix-env-var-exfiltration

Conversation

@Byron

@Byron Byron commented Jul 22, 2026

Copy link
Copy Markdown
Member

Tasks

This section is for Byron only. Models continuing this PR must not add, remove, check, uncheck, rename, or reorder checkboxes here.

  • refackiew

Everything below this line was generated by Codex GPT-5.

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

Summary

Preserve caller-supplied environment-variable references literally when creating remotes and submodules. This closes the remaining sibling URL paths missed by the earlier clone hardening while retaining existing local-path normalization behavior.

Advisory summary

The advisory remains in triage, so reproduction and exploit details are intentionally omitted here.

Validation

  • Focused remote and submodule regression tests: 2 passed
  • Changed-file pre-commit hooks: passed
  • git diff --check: passed
  • Full remote/submodule modules: 56 passed, 1 skipped; 14 fixture failures from unavailable nested test repositories and a historical master-branch fixture
  • Codex commit review: no correctness findings

Remote and submodule creation expanded environment-variable references in
caller-supplied URLs before storing them in Git configuration. This could
expose process environment values through a later network request or a tracked
.gitmodules file.

Preserve variables literally in the remaining untrusted URL callers while
retaining Git.polish_url() expansion for intentional local-path normalization.
Add regression tests covering remote configuration and submodule configuration.

Git baseline: git remote add and git submodule add accept URL arguments
literally; Git does not perform shell-style environment expansion on those
arguments.

Co-authored-by: Sebastian Thiel <[email protected]>
@Byron
Byron force-pushed the fix-env-var-exfiltration branch from 333c6ba to 8634174 Compare July 22, 2026 15:04
@Byron
Byron marked this pull request as ready for review July 22, 2026 15:09
Copilot AI review requested due to automatic review settings July 22, 2026 15:09

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.

Pull request overview

This PR hardens GitPython’s remote and submodule creation paths to preserve caller-supplied environment-variable references literally (e.g. ${VAR}) instead of expanding them via os.path.expandvars, aligning with the security advisory context.

Changes:

  • Disable variable/~ expansion when polishing URLs in Remote.create() by passing expand_vars=False.
  • Disable variable/~ expansion when polishing URLs written into submodule config by passing expand_vars=False.
  • Add regression tests covering remote creation and submodule add behavior under a patched environment.

Reviewed changes

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

File Description
git/remote.py Prevents env/~ expansion when adding a new remote by polishing URLs with expand_vars=False.
git/objects/submodule/base.py Prevents env/~ expansion when writing submodule URLs to config by polishing with expand_vars=False.
test/test_remote.py Adds a regression test ensuring ${VAR} in a remote URL is not expanded during create_remote.
test/test_submodule.py Adds a regression test ensuring ${VAR} in a local-path submodule URL is not expanded during Submodule.add.

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

@Byron
Byron merged commit e227e01 into main Jul 22, 2026
31 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