Skip to content

Commit 846e0f6

Browse files
Potential fix for code scanning alert no. 2: Incomplete URL substring sanitization
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent a6c13bb commit 846e0f6

1 file changed

Lines changed: 29 additions & 6 deletions

File tree

main.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Register this as a proper app using the classic ctypes.windll workaround
22
import ctypes
33
import sys
4+
from urllib.parse import urlparse
45

56
if sys.platform == "win32":
67
ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(
@@ -6063,13 +6064,35 @@ def _clone(self):
60636064
if not url:
60646065
return
60656066
try:
6066-
if "github.com" in url:
6067-
idx = url.find("github.com") + len("github.com/")
6068-
rest = url[idx:].rstrip("/").replace(".git", "").split("/")
6069-
dev_name, repo_name = rest[0], rest[1]
6067+
# Support HTTPS/HTTP GitHub URLs and SSH-style GitHub URLs.
6068+
dev_name = None
6069+
repo_name = None
6070+
6071+
# SSH-style: git@github.com:user/repo.git
6072+
if url.startswith("git@github.com:"):
6073+
path_part = url[len("git@github.com:") :].rstrip("/")
6074+
parts = path_part.split("/")
6075+
if len(parts) >= 2:
6076+
dev_name = parts[0]
6077+
repo_name = parts[1]
6078+
else:
6079+
raise ValueError("Incomplete SSH GitHub URL")
60706080
else:
6071-
parts = url.rstrip("/").split("/")
6072-
dev_name, repo_name = parts[-2], parts[-1].replace(".git", "")
6081+
parsed = urlparse(url)
6082+
# Require a proper HTTP(S) URL with github.com as hostname
6083+
if parsed.scheme not in ("http", "https") or parsed.hostname != "github.com":
6084+
raise ValueError("Not a GitHub HTTPS/HTTP URL")
6085+
path = parsed.path.lstrip("/").rstrip("/")
6086+
parts = path.split("/")
6087+
if len(parts) < 2:
6088+
raise ValueError("Incomplete GitHub repository path")
6089+
dev_name = parts[0]
6090+
repo_name = parts[1]
6091+
6092+
# Normalize repository name (strip optional .git suffix)
6093+
if repo_name.endswith(".git"):
6094+
repo_name = repo_name[: -len(".git")]
6095+
60736096
except Exception:
60746097
self.status_lbl.setText("❌ Invalid GitHub URL")
60756098
return

0 commit comments

Comments
 (0)