Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -29146,6 +29146,11 @@ func loadGithubWorkflows(url, username, password, userId, branch, orgId string)

log.Printf("Starting load of %s with branch %s", url, branch)

if err := checkAllowedUrl(url); err != nil {
log.Printf("[ERROR] Blocked workflow git clone URL: %s", err)
return err
}

cloneOptions := &git.CloneOptions{
URL: url,
}
Expand Down Expand Up @@ -29293,6 +29298,11 @@ func listGithubWorkflowsInfo(url, username, password, branch, orgId string) ([]R
}
}

if err := checkAllowedUrl(url); err != nil {
log.Printf("[ERROR] Blocked workflow git clone URL: %s", err)
return nil, err
}

cloneOptions := &git.CloneOptions{URL: url}
if len(username) > 0 && len(password) > 0 {
cloneOptions.Auth = &http2.BasicAuth{Username: username, Password: password}
Expand Down Expand Up @@ -29495,6 +29505,11 @@ func importSingleRemoteWorkflow(url, username, password, branch, originalWorkflo
}
}

if err := checkAllowedUrl(url); err != nil {
log.Printf("[ERROR] Blocked workflow git clone URL: %s", err)
return err
}

cloneOptions := &git.CloneOptions{URL: url}
if len(username) > 0 && len(password) > 0 {
cloneOptions.Auth = &http2.BasicAuth{Username: username, Password: password}
Expand Down Expand Up @@ -37464,3 +37479,22 @@ func ListProcesses() ([]ProcessInfo, error) {
return nil, fmt.Errorf("unsupported platform: %s", runtime.GOOS)
}
}

func checkAllowedUrl(rawUrl string) error {
parsedUrl, err := url.Parse(rawUrl)
if err != nil {
return fmt.Errorf("invalid git url: %s", err)
}

host := strings.ToLower(parsedUrl.Hostname())

if parsedUrl.Scheme != "https" {
return fmt.Errorf("unsupported git url scheme")
}

if host != "github.com" && host != "gitlab.com" && host != "bitbucket.org" && host != "dev.azure.com" {
return fmt.Errorf("unsupported git host")
}

return nil
}
Loading