Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a4fc6a

Browse files
committed
Replace password in URI by stars if present + test
1 parent20f4a9d commit3a4fc6a

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"://"inuriand"@"inuri:
975+
cred=uri.split("://")[1].split("@")[0].split(":")
976+
iflen(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
exceptUnicodeEncodeError:
239239
self.fail('Raised UnicodeEncodeError')
240240

241+
@with_rw_directory
242+
deftest_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+
exceptGitCommandErroraserr:
250+
assertpasswordnotinstr(err)
251+
241252
@with_rw_repo('HEAD')
242253
deftest_max_chunk_size(self,repo):
243254
classTestOutputStream(TestBase):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp