downloadBase returns the release download base and whether it is a loopback HTTP base. CBM_DOWNLOAD_URL replaces the GitHub release base (for testing) with install.sh's policy: HTTPS, or plain HTTP to an exact loopback authority.
(override string)
| 488 | // testing) with install.sh's policy: HTTPS, or plain HTTP to an exact |
| 489 | // loopback authority. |
| 490 | func downloadBase(override string) (string, bool, error) { |
| 491 | if override == "" { |
| 492 | return fmt.Sprintf( |
| 493 | "https://github.com/%s/releases/download/v%s", repo, installVersion, |
| 494 | ), false, nil |
| 495 | } |
| 496 | if strings.HasPrefix(override, "https://") { |
| 497 | return override, false, nil |
| 498 | } |
| 499 | if loopbackHTTPURL.MatchString(override) { |
| 500 | return override, true, nil |
| 501 | } |
| 502 | return "", false, fmt.Errorf( |
| 503 | "refusing non-HTTPS download URL (CBM_DOWNLOAD_URL): %s", override, |
| 504 | ) |
| 505 | } |
| 506 | |
| 507 | // validateURLScheme rejects non-https URLs before any fetch (defense-in-depth). |
| 508 | func validateURLScheme(rawURL string) error { |
no outgoing calls