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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Harden Apprise server URL base handling
rcourtmana253016327b8
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex 97164061a3..88d4a72139 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -119,6 +119,11 @@ normalization. Server URLs must be validated as absolute HTTP(S) endpointswithout userinfo before request construction, and the `/notify` plus optionalconfig-key path must append to the canonical server base instead of beingrebuilt through raw string concatenation in local delivery code.+That same Apprise boundary also treats `ServerURL` as a canonical base URL,+not a request URL template. The owned runtime must reject query or fragment+state on that base, preserve any mounted base path, and resolve `/notify`+plus the optional config-key segment through shared URL helpers so delivery+cannot silently drop subpaths or reinterpret appended path segments.That same delivery boundary also owns SMTP mailbox normalization. `From`,recipient, and `Reply-To` inputs must be parsed as canonical mailboxes beforeheaders or SMTP envelope commands are constructed, so notification deliverydiff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.goindex 930da52b3b..7101657c33 100644--- a/internal/notifications/notifications.go+++ b/internal/notifications/notifications.go@@ -1487,6 +1487,17 @@ func (n *NotificationManager) sendAppriseViaCLI(cfg AppriseConfig, title, body sreturn nil}+func (n *NotificationManager) validatedWebhookBaseURL(rawURL string) (*url.URL, error) {+ baseURL, err := securityutil.NormalizeHTTPBaseURL(rawURL, "")+ if err != nil {+ return nil, err+ }+ if err := n.ValidateWebhookURL(baseURL.String()); err != nil {+ return nil, err+ }+ return baseURL, nil+}+func (n *NotificationManager) sendAppriseViaHTTP(cfg AppriseConfig, title, body, notifyType string) error {if cfg.ServerURL == "" {return fmt.Errorf("apprise server URL is not configured")@@ -1498,8 +1509,8 @@ func (n *NotificationManager) sendAppriseViaHTTP(cfg AppriseConfig, title, body,return fmt.Errorf("apprise server URL must start with http or https: %s", serverURL)}- // Validate Apprise server URL to prevent SSRF- if err := n.ValidateWebhookURL(serverURL); err != nil {+ validatedBaseURL, err := n.validatedWebhookBaseURL(serverURL)+ if err != nil {log.Error().Err(err).Str("serverURL", serverURL).@@ -1515,8 +1526,7 @@ func (n *NotificationManager) sendAppriseViaHTTP(cfg AppriseConfig, title, body,notifyEndpoint = "/notify/" + url.PathEscape(cfg.ConfigKey)}- requestURL := strings.TrimRight(serverURL, "/") + notifyEndpoint- targetURL, err := securityutil.NormalizeAbsoluteHTTPURL(requestURL)+ targetURL, err := securityutil.ResolveRelativeURL(validatedBaseURL, notifyEndpoint)if err != nil {return fmt.Errorf("apprise server URL validation failed: %w", err)}@@ -1554,7 +1564,7 @@ func (n *NotificationManager) sendAppriseViaHTTP(cfg AppriseConfig, title, body,client := n.createSecureWebhookClientWithTLS(time.Duration(cfg.TimeoutSeconds)*time.Second,- strings.HasPrefix(lowerURL, "https://") && cfg.SkipTLSVerify,+ validatedBaseURL.Scheme == "https" && cfg.SkipTLSVerify,)resp, err := client.Do(req)diff --git a/internal/notifications/notifications_security_http_test.go b/internal/notifications/notifications_security_http_test.goindex 4ebd131885..4fce58a4f0 100644--- a/internal/notifications/notifications_security_http_test.go+++ b/internal/notifications/notifications_security_http_test.go@@ -23,7 +23,7 @@ func TestSendAppriseViaHTTPInvalidScheme(t *testing.T) {defer nm.Stop()err := nm.sendAppriseViaHTTP(AppriseConfig{ServerURL: "ftp://example.com", TimeoutSeconds: 1}, "title", "body", "info")- if err == nil || !strings.Contains(err.Error(), "must start with http or https") {+ if err == nil || !strings.Contains(err.Error(), "http or https") {t.Fatalf("expected scheme validation error, got %v", err)}}@@ -68,6 +68,64 @@ func TestSendAppriseViaHTTPRejectsUserinfoServerURL(t *testing.T) {}}+func TestSendAppriseViaHTTPRejectsQueryOrFragmentInServerURL(t *testing.T) {+ tests := []struct {+ name string+ serverURL func(string) string+ wantErr string+ }{+ {+ name: "query",+ serverURL: func(base string) string {+ return base + "/apprise/api?token=secret"+ },+ wantErr: "base URL must not include query or fragment",+ },+ {+ name: "fragment",+ serverURL: func(base string) string {+ return base + "/apprise/api#notify"+ },+ wantErr: "base URL must not include query or fragment",+ },+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ nm := NewNotificationManager("")+ defer nm.Stop()++ called := make(chan struct{}, 1)+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ select {+ case called <- struct{}{}:+ default:+ }+ w.WriteHeader(http.StatusOK)+ }))+ defer server.Close()++ if err := nm.UpdateAllowedPrivateCIDRs("127.0.0.1/32"); err != nil {+ t.Fatalf("allowlist: %v", err)+ }++ err := nm.sendAppriseViaHTTP(AppriseConfig{+ ServerURL: tt.serverURL(server.URL),+ TimeoutSeconds: 2,+ }, "title", "body", "info")+ if err == nil || !strings.Contains(err.Error(), tt.wantErr) {+ t.Fatalf("expected %q validation error, got %v", tt.wantErr, err)+ }++ select {+ case <-called:+ t.Fatal("expected query/fragment-bearing Apprise base URL to be rejected before outbound delivery")+ default:+ }+ })+ }+}+func TestSendTestWebhookRejectsUserinfoURLBeforeOutboundDelivery(t *testing.T) {nm := NewNotificationManager("https://pulse.local")defer nm.Stop()@@ -176,8 +234,8 @@ func TestSendAppriseViaHTTPIncludesTargetsAndCustomHeader(t *testing.T) {if got := r.Header.Get("X-Test-Key"); got != "secret" {t.Fatalf("expected custom API key header, got %q", got)}- if !strings.Contains(r.URL.Path, "/notify/") {- t.Fatalf("expected notify path, got %q", r.URL.Path)+ if got := r.URL.EscapedPath(); got != "/apprise/api/notify/config%20key" {+ t.Fatalf("expected base path to be preserved, got %q", got)}var p payloadif err := json.NewDecoder(r.Body).Decode(&p); err != nil {@@ -199,7 +257,7 @@ func TestSendAppriseViaHTTPIncludesTargetsAndCustomHeader(t *testing.T) {}err := nm.sendAppriseViaHTTP(AppriseConfig{- ServerURL: server.URL,+ ServerURL: server.URL + "/apprise/api/",ConfigKey: "config key",APIKey: "secret",APIKeyHeader: "X-Test-Key",