From 3a4fc6abfb3b39237f557372262ac79f45b6a9fa Mon Sep 17 00:00:00 2001 From: Michael Mercier Date: Thu, 11 Mar 2021 18:46:34 +0100 Subject: Replace password in URI by stars if present + test --- git/repo/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 8f1ef0a6..44e3f859 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -969,7 +969,13 @@ class Repo(object): handle_process_output(proc, None, progress.new_message_handler(), finalize_process, decode_streams=False) else: (stdout, stderr) = proc.communicate() - log.debug("Cmd(%s)'s unused stdout: %s", getattr(proc, 'args', ''), stdout) + cmdline = getattr(proc, 'args', '') + uri = cmdline[-2] + if "://" in uri and "@" in uri: + cred = uri.split("://")[1].split("@")[0].split(":") + if len(cred) == 2: + cmdline[-2] = uri.replace(cred[1], "******") + log.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout) finalize_process(proc, stderr=stderr) # our git command could have a different working dir than our actual -- cgit v1.2.1 From f7180d50f785ec28963e12e647d269650ad89b31 Mon Sep 17 00:00:00 2001 From: Michael Mercier Date: Mon, 15 Mar 2021 09:51:14 +0100 Subject: Use urllib instead of custom parsing --- git/repo/base.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 44e3f859..9cb84054 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -9,6 +9,7 @@ import logging import os import re import warnings +from urllib.parse import urlsplit, urlunsplit from git.cmd import ( Git, @@ -971,10 +972,15 @@ class Repo(object): (stdout, stderr) = proc.communicate() cmdline = getattr(proc, 'args', '') uri = cmdline[-2] - if "://" in uri and "@" in uri: - cred = uri.split("://")[1].split("@")[0].split(":") - if len(cred) == 2: - cmdline[-2] = uri.replace(cred[1], "******") + try: + url = urlsplit(uri) + # Remove password from the URL if present + if url.password: + edited_url = url._replace( + netloc=url.netloc.replace(url.password, "****")) + cmdline[-2] = urlunsplit(edited_url) + except ValueError: + log.debug("Unable to parse the URL %s", url) log.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout) finalize_process(proc, stderr=stderr) -- cgit v1.2.1 From f7968d136276607115907267b3be89c3ff9acd03 Mon Sep 17 00:00:00 2001 From: Michael Mercier Date: Mon, 15 Mar 2021 17:54:48 +0100 Subject: Put remove password in the utils and use it also in cmd.execute --- git/repo/base.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'git/repo/base.py') diff --git a/git/repo/base.py b/git/repo/base.py index 9cb84054..e68bc077 100644 --- a/git/repo/base.py +++ b/git/repo/base.py @@ -9,7 +9,6 @@ import logging import os import re import warnings -from urllib.parse import urlsplit, urlunsplit from git.cmd import ( Git, @@ -27,7 +26,7 @@ from git.index import IndexFile from git.objects import Submodule, RootModule, Commit from git.refs import HEAD, Head, Reference, TagReference from git.remote import Remote, add_progress, to_progress_instance -from git.util import Actor, finalize_process, decygpath, hex_to_bin, expand_path +from git.util import Actor, finalize_process, decygpath, hex_to_bin, expand_path, remove_password_if_present import os.path as osp from .fun import rev_parse, is_git_dir, find_submodule_git_dir, touch, find_worktree_git_dir @@ -971,16 +970,8 @@ class Repo(object): else: (stdout, stderr) = proc.communicate() cmdline = getattr(proc, 'args', '') - uri = cmdline[-2] - try: - url = urlsplit(uri) - # Remove password from the URL if present - if url.password: - edited_url = url._replace( - netloc=url.netloc.replace(url.password, "****")) - cmdline[-2] = urlunsplit(edited_url) - except ValueError: - log.debug("Unable to parse the URL %s", url) + cmdline = remove_password_if_present(cmdline) + log.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout) finalize_process(proc, stderr=stderr) -- cgit v1.2.1