FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: prevent environment expansion in remote URLs by Byron · Pull Request #2181 · gitpython-developers/GitPython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion git/objects/submodule/base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def add(
# END verify url

## See #525 for ensuring git URLs in config-files are valid under Windows.
url = Git.polish_url(url)
url = Git.polish_url(url, expand_vars=False)

# It's important to add the URL to the parent config, to let `git submodule` know.
# Otherwise there is a '-' character in front of the submodule listing:
Expand Down
2 changes: 1 addition & 1 deletion git/remote.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ def create(cls, repo: "Repo", name: str, url: str, allow_unsafe_protocols: bool
"""
scmd = "add"
kwargs["insert_kwargs_after"] = scmd
url = Git.polish_url(url)
url = Git.polish_url(url, expand_vars=False)
if not allow_unsafe_protocols:
Git.check_unsafe_protocols(url)
repo.git.remote(scmd, "--", name, url, **kwargs)
Expand Down
9 changes: 9 additions & 0 deletions test/test_remote.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import gc
import os
import os.path as osp
from pathlib import Path
import random
Expand Down Expand Up @@ -685,6 +686,14 @@ def test_multiple_urls(self, rw_repo):
# Will raise fatal: Will not delete all non-push URLs.
self.assertRaises(GitCommandError, remote.delete_url, test3)

@with_rw_repo("HEAD", bare=False)
def test_create_does_not_expand_environment_variables_in_url(self, rw_repo):
url = "https://example.com/${GITPYTHON_TEST_SECRET}/repo.git"
with mock.patch.dict(os.environ, {"GITPYTHON_TEST_SECRET": "sensitive-value"}):
remote = rw_repo.create_remote("untrusted", url)

assert remote.url == url

def test_fetch_error(self):
rem = self.rorepo.remote("origin")
msg = (
Expand Down
14 changes: 14 additions & 0 deletions test/test_submodule.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,20 @@ def test_add_no_clone_multi_options_argument(self, rwdir):
with self.assertRaises(cp.NoOptionError):
sm_config.get_value("core", "eol")

@with_rw_directory
def test_add_does_not_expand_environment_variables_in_url(self, rwdir):
parent = git.Repo.init(osp.join(rwdir, "parent"))
url = osp.join(rwdir, "${GITPYTHON_TEST_SECRET}")
source = git.Repo.init(url)
Path(source.working_tree_dir, "file").write_text("content")
source.index.add(["file"])
source.index.commit("initial")

with mock.patch.dict(os.environ, {"GITPYTHON_TEST_SECRET": "sensitive-value"}):
sm = Submodule.add(parent, "new", "new", url)

assert sm.url == Git.polish_url(url, expand_vars=False)

@with_rw_repo("HEAD")
def test_submodule_add_unsafe_url(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
Expand Down
Loading

Back | FazBrowse Home | New Git URL