Files
archived-hc-harbor/lib/git_remote.rb
Max Wofford 633eb4a5ce Add protocol allowlist to git_remote checker
I wasn't able to replicate CVE-2022-24439 / CVE-2023-40267 after a while of trying to add something malicious but I figure it's a quick and easy check to add just in case
2025-07-13 11:27:21 -07:00

15 lines
427 B
Ruby

require "open3"
class GitRemote
def self.check_remote_exists(repo_url)
# only run check if git is installed and in path
return true unless system("git --version")
# Only allow safe protocols
return false unless repo_url.match?(/\A(https?|git|ssh):\/\//)
safe_repo_url = URI.parse(repo_url).to_s.gsub(" ", "").gsub("'", "")
Open3.capture2e("git", "ls-remote", safe_repo_url).last.success?
end
end