Skip to content

Commit 57dc093

Browse files
authored
[Dexter] Sanitize user details from git repo URL in dexter --version (#105533)
Currently the output of dexter --version contains the raw output of `git remote get-url origin`, which may contain a username and password. This patch adds a small change to remove these from the output string. A similar patch for LLVM's default version string* also removes the git URL altogether unless opted-in to; it's not clear whether this is a necessary or desirable step yet, but if so we can trivially remove the URL from Dexter as well. *PR here: #105220
1 parent 716f7e2 commit 57dc093

File tree

1 file changed

+14
-1
lines changed
  • cross-project-tests/debuginfo-tests/dexter/dex/utils

1 file changed

+14
-1
lines changed

cross-project-tests/debuginfo-tests/dexter/dex/utils/Version.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,23 @@
99
import os
1010
from subprocess import CalledProcessError, check_output, STDOUT
1111
import sys
12+
from urllib.parse import urlparse, urlunparse
1213

1314
from dex import __version__
1415

1516

17+
def sanitize_repo_url(repo):
18+
parsed = urlparse(repo)
19+
# No username present, repo URL is fine.
20+
if parsed.username is None:
21+
return repo
22+
# Otherwise, strip the login details from the URL by reconstructing the netloc from just `<hostname>(:<port>)?`.
23+
sanitized_netloc = parsed.hostname
24+
if parsed.port:
25+
sanitized_netloc = f"{sanitized_netloc}:{parsed.port}"
26+
return urlunparse(parsed._replace(netloc=sanitized_netloc))
27+
28+
1629
def _git_version():
1730
dir_ = os.path.dirname(__file__)
1831
try:
@@ -28,7 +41,7 @@ def _git_version():
2841
.rstrip()
2942
.decode("utf-8")
3043
)
31-
repo = (
44+
repo = sanitize_repo_url(
3245
check_output(
3346
["git", "remote", "get-url", "origin"], stderr=STDOUT, cwd=dir_
3447
)

0 commit comments

Comments
 (0)