Skip to content

Commit f9dc5f6

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

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

src/apm_cli/models/apm_package.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,15 @@ def parse(cls, dependency_str: str) -> "DependencyReference":
123123
parsed_url = urllib.parse.urlparse(repo_url)
124124
else:
125125
# Safely construct GitHub URL from various input formats
126-
if repo_url.startswith("github.com/"):
127-
# Remove github.com/ prefix to get user/repo part
128-
user_repo = repo_url[len("github.com/"):]
126+
parts = repo_url.split("/")
127+
if len(parts) >= 3 and parts[0] == "github.com":
128+
# Format: github.com/user/repo (must be precisely so)
129+
user_repo = "/".join(parts[1:3])
130+
elif len(parts) >= 2 and "." not in parts[0]:
131+
# Format: user/repo (no dot in user part, so not a domain)
132+
user_repo = "/".join(parts[:2])
129133
else:
130-
# For any input that contains a domain-like pattern, reject it unless it's github.com
131-
if "." in repo_url.split("/")[0] and not repo_url.startswith("github.com/"):
132-
raise ValueError(f"Only GitHub repositories are supported. Use 'user/repo' or 'github.com/user/repo' format")
133-
134-
# Assume it's in user/repo format
135-
user_repo = repo_url
134+
raise ValueError(f"Only GitHub repositories are supported. Use 'user/repo' or 'github.com/user/repo' format")
136135

137136
# Validate format before URL construction (security critical)
138137
if not user_repo or "/" not in user_repo:

0 commit comments

Comments
 (0)