Skip to content

Commit 3a4fc6a

Browse files
committed
Replace password in URI by stars if present + test
1 parent 20f4a9d commit 3a4fc6a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

git/repo/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,13 @@ def _clone(cls, git, url, path, odb_default_type, progress, multi_options=None,
969969
handle_process_output(proc, None, progress.new_message_handler(), finalize_process, decode_streams=False)
970970
else:
971971
(stdout, stderr) = proc.communicate()
972-
log.debug("Cmd(%s)'s unused stdout: %s", getattr(proc, 'args', ''), stdout)
972+
cmdline = getattr(proc, 'args', '')
973+
uri = cmdline[-2]
974+
if "://" in uri and "@" in uri:
975+
cred = uri.split("://")[1].split("@")[0].split(":")
976+
if len(cred) == 2:
977+
cmdline[-2] = uri.replace(cred[1], "******")
978+
log.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout)
973979
finalize_process(proc, stderr=stderr)
974980

975981
# our git command could have a different working dir than our actual

test/test_repo.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@ def test_clone_from_with_path_contains_unicode(self):
238238
except UnicodeEncodeError:
239239
self.fail('Raised UnicodeEncodeError')
240240

241+
@with_rw_directory
242+
def test_leaking_password_in_clone_logs(self, rw_dir):
243+
"""Check that the password is not printed on the logs"""
244+
password = "fakepassword1234"
245+
try:
246+
Repo.clone_from(
247+
url=f"https://fakeuser:{password}@fakerepo.example.com/testrepo",
248+
to_path=rw_dir)
249+
except GitCommandError as err:
250+
assert password not in str(err)
251+
241252
@with_rw_repo('HEAD')
242253
def test_max_chunk_size(self, repo):
243254
class TestOutputStream(TestBase):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy