Skip to content

Commit 27566be

Browse files
authored
Merge pull request #172 from mlcommons/alert-autofix-12
Potential fix for code scanning alert no. 12: Incomplete URL substring sanitization
2 parents 48dd398 + 2af2f74 commit 27566be

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mlc/repo_action.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,18 @@ def find(self, run_args):
199199
repo_uid = repo_split[1]
200200
elif "@" in repo:
201201
repo_name = repo
202-
elif "github.com" in repo:
203-
result = self.github_url_to_user_repo_format(repo)
204-
if result["return"] == 0:
205-
repo_name = result["value"]
206-
else:
207-
return result
202+
else:
203+
# Check for valid github.com URL using urlparse
204+
try:
205+
parsed = urlparse(repo)
206+
except Exception:
207+
parsed = None
208+
if parsed and parsed.scheme in ("http", "https") and parsed.hostname == "github.com":
209+
result = self.github_url_to_user_repo_format(repo)
210+
if result["return"] == 0:
211+
repo_name = result["value"]
212+
else:
213+
return result
208214

209215
# Check if repo_name exists in repos.json
210216
matched_repo_path = None

0 commit comments

Comments
 (0)