Skip to content

Conversation

arjunsuresh
Copy link
Contributor

Potential fix for https://github.com/mlcommons/mlcflow/security/code-scanning/12

The right way to fix this is to properly parse the repo variable as a URL, then check whether the hostname is exactly "github.com" or possibly in an allowlist of trusted hostnames (such as "github.com", optionally supporting subdomains if that is a use case).

  • Use Python's built-in urllib.parse.urlparse to parse repo if it's a URL.
  • Check the .hostname property for equality with "github.com". (Not a substring or endswith check.)
  • If the scheme or hostname is not present, reject, or fall back to previous logic.
  • Only proceed to self.github_url_to_user_repo_format if the parsed hostname is trusted.
  • Replace the line elif "github.com" in repo: with a proper parse and check.
  • Ensure that URLs like https://evil.com/github.com/foo do not pass.

The code to import is from urllib.parse import urlparse. Insert this import if not present.

All changes are confined to function(s) within mlc/repo_action.py as shown.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

…g sanitization

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Copy link

github-actions bot commented Sep 4, 2025

MLCommons CLA bot All contributors have signed the MLCommons CLA ✍️ ✅

@arjunsuresh arjunsuresh marked this pull request as ready for review September 4, 2025 15:48
@arjunsuresh arjunsuresh requested a review from a team as a code owner September 4, 2025 15:48
@anandhu-eng anandhu-eng merged commit 27566be into main Sep 4, 2025
38 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2025
@anandhu-eng anandhu-eng deleted the alert-autofix-12 branch September 9, 2025 13:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants