Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Canonicalize apply-update download URLs

rcourtman7950cfe0e2ee
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 6068883c79..3655e88d52 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -163,7 +163,9 @@ That same boundary also owns outbound update transport safety: env-configured
update server bases must normalize to absolute HTTP(S) URLs without userinfo,
and release API, feed, download, and checksum requests must resolve from
validated URL objects instead of raw string concatenation or request creation
-from unchecked inputs.
+from unchecked inputs. `ApplyUpdate` must canonicalize the supplied download
+URL through that shared validator before version inference, history emission,
+or transfer work begins.
That same boundary also governs owned filesystem scans inside the update
manager: when `internal/updates/manager.go` enumerates already-owned extract,
temp, backup, or restore directories, it must rejoin discovered entry names
diff --git a/internal/updates/manager.go b/internal/updates/manager.go
index 52960e0537..a5ac9660fa 100644
--- a/internal/updates/manager.go
+++ b/internal/updates/manager.go
@@ -131,6 +131,32 @@ func resolveUpdateReleaseFeedURL() (*url.URL, error) {
return target, nil
}
+func validateApplyDownloadURL(rawURL string) (*url.URL, error) {
+ downloadURL, err := securityutil.NormalizeAbsoluteHTTPURL(rawURL)
+ if err != nil {
+ return nil, fmt.Errorf("invalid download URL: %w", err)
+ }
+ if strings.TrimSpace(os.Getenv("PULSE_UPDATE_SERVER")) != "" {
+ return downloadURL, nil
+ }
+
+ allowedPrefix, err := securityutil.NormalizeHTTPBaseURL(updateReleaseDownloadPrefix(), "")
+ if err != nil {
+ return nil, fmt.Errorf("invalid download URL: %w", err)
+ }
+
+ if downloadURL.Scheme != allowedPrefix.Scheme || !strings.EqualFold(downloadURL.Host, allowedPrefix.Host) {
+ return nil, fmt.Errorf("invalid download URL")
+ }
+
+ allowedPathPrefix := allowedPrefix.Path
+ if downloadURL.Path != allowedPathPrefix && !strings.HasPrefix(downloadURL.Path, allowedPathPrefix+"/") {
+ return nil, fmt.Errorf("invalid download URL")
+ }
+
+ return downloadURL, nil
+}
+
func updateReleaseMigrationURL() string {
return fmt.Sprintf("https://github.com/%s/releases/v4.0.0", updateReleaseRepo())
}
@@ -465,15 +491,14 @@ func (m *Manager) CheckForUpdatesWithChannel(ctx context.Context, channel string
// ApplyUpdate downloads and applies an update
func (m *Manager) ApplyUpdate(ctx context.Context, req ApplyUpdateRequest) error {
- // Validate download URL (allow test server URLs when PULSE_UPDATE_SERVER is set)
if req.DownloadURL == "" {
return fmt.Errorf("download URL is required")
}
- if os.Getenv("PULSE_UPDATE_SERVER") == "" {
- if !strings.HasPrefix(req.DownloadURL, updateReleaseDownloadPrefix()) {
- return fmt.Errorf("invalid download URL")
- }
+ validatedDownloadURL, validationErr := validateApplyDownloadURL(req.DownloadURL)
+ if validationErr != nil {
+ return validationErr
}
+ req.DownloadURL = validatedDownloadURL.String()
// Check if Docker
currentInfo, _ := GetCurrentVersion()
@@ -1014,11 +1039,18 @@ func inferVersionFromDownloadURL(downloadURL string) string {
if downloadURL == "" {
return ""
}
+ if parsed, err := securityutil.NormalizeAbsoluteHTTPURL(downloadURL); err == nil {
+ if match := versionInURLRegex.FindString(parsed.Path); match != "" {
+ return match
+ }
+ if match := versionInURLRegex.FindString(filepath.Base(parsed.Path)); match != "" {
+ return match
+ }
+ }
if match := versionInURLRegex.FindString(downloadURL); match != "" {
return match
}
- base := filepath.Base(downloadURL)
- if match := versionInURLRegex.FindString(base); match != "" {
+ if match := versionInURLRegex.FindString(filepath.Base(downloadURL)); match != "" {
return match
}
return ""
diff --git a/internal/updates/manager_more_test.go b/internal/updates/manager_more_test.go
index 788481d4e0..a54ed4030d 100644
--- a/internal/updates/manager_more_test.go
+++ b/internal/updates/manager_more_test.go
@@ -73,6 +73,40 @@ func TestValidateApplyTargetVersion(t *testing.T) {
if _, err := validateApplyTargetVersion("stable", "https://github.com/rcourtman/Pulse/releases/download/latest/install.sh"); err == nil {
t.Fatal("expected invalid download URL to be rejected")
}
+
+ target, err = validateApplyTargetVersion("stable", "https://github.com/rcourtman/Pulse/releases/download/v6.0.0/pulse-linux-amd64.tar.gz?download=1#v9.9.9")
+ if err != nil {
+ t.Fatalf("version should be inferred from URL path, got %v", err)
+ }
+ if target != "v6.0.0" {
+ t.Fatalf("unexpected target version with fragment/query = %q", target)
+ }
+}
+
+func TestValidateApplyDownloadURL(t *testing.T) {
+ t.Run("rejects userinfo", func(t *testing.T) {
+ if _, err := validateApplyDownloadURL("https://user:[email protected]/rcourtman/Pulse/releases/download/v6.0.0/pulse-v6.0.0-linux-amd64.tar.gz"); err == nil {
+ t.Fatal("expected userinfo URL to be rejected")
+ }
+ })
+
+ t.Run("rejects non release host without override", func(t *testing.T) {
+ if _, err := validateApplyDownloadURL("https://example.com/pulse-v6.0.0-linux-amd64.tar.gz"); err == nil {
+ t.Fatal("expected non-GitHub URL to be rejected without update server override")
+ }
+ })
+
+ t.Run("accepts configured update server URL", func(t *testing.T) {
+ t.Setenv("PULSE_UPDATE_SERVER", "https://updates.example.com/proxy")
+
+ validated, err := validateApplyDownloadURL("https://updates.example.com/releases/pulse-v6.0.0-linux-amd64.tar.gz")
+ if err != nil {
+ t.Fatalf("expected configured update server URL to be accepted, got %v", err)
+ }
+ if got := validated.String(); got != "https://updates.example.com/releases/pulse-v6.0.0-linux-amd64.tar.gz" {
+ t.Fatalf("validateApplyDownloadURL() = %q", got)
+ }
+ })
}
func TestUpdateReleaseHelpersUseConfiguredRepo(t *testing.T) {