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
Keep notification redirects on their configured origin
pulse-triage[bot]7ee035cb6fff
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex cc0210a930..3da57249e6 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -15,6 +15,34 @@## Purpose+### Notification redirects keep the configured receiver's origin++Webhook and HTTP Apprise firing, recovery, Test and admitted queued delivery+follow redirects only within the initial HTTP origin: scheme, normalised host+and effective port. An SSRF-permitted host, subdomain, DNS alias or another port+is not permission to receive private alert bodies, custom authentication headers+or signed requests. HTTP/HTTPS changes are also refused. Same-origin paths and+queries remain supported, including default-port and equivalent IPv6 spellings;+the existing redirect limit, DNS pinning, URL validation and TLS checks remain.+Foreign redirects stop before target DNS resolution, validation logging or a+second request. A fixed configuration failure advises the operator to configure+the final destination URL, without copying the receiver-controlled Location.++That typed failure stops both enhanced transport retries and the queue's retry+budget. It remains an undelivered dead letter and audit, never a successful+firing/recovery receipt; admitted private configuration is not rewritten.+Apprise retains the same safe guidance and existing opaque diagnostic policy.++`notification_redirect_test.go` supplies real loopback controls for all five+redirect statuses, foreign ports/hostname aliases, authenticated HTTPS downgrade+with and without the existing TLS override, every sender path and the real+queue's firing/recovery dead-letter, audit and receipt lifecycle. Same-origin+controls verify unchanged methods, payloads, credentials and signatures.+`notification_redirect_origin_test.go` covers origin equivalence and separation.+Existing redirect-chain controls now exercise paths on one receiver, not three+different receivers. This is source privacy/compatibility proof, not installed+destination acceptance, evidence of prior exposure or resolution of a report.+### Webhook diagnostics withhold receiver-controlled textOrdinary and enhanced firing/recovery senders, including ntfy's plain-textdiff --git a/internal/notifications/apprise_confidentiality_test.go b/internal/notifications/apprise_confidentiality_test.goindex 2a08e73115..4606ec67dc 100644--- a/internal/notifications/apprise_confidentiality_test.go+++ b/internal/notifications/apprise_confidentiality_test.go@@ -214,7 +214,7 @@ func TestAppriseValidationAndRedirectConfidentiality(t *testing.T) {}if err != nil {assertAppriseConfidential(t, err.Error())- if !strings.Contains(err.Error(), "link-local addresses are not allowed") {+ if !strings.Contains(err.Error(), "configured origin") {t.Error("actionable redirect refusal was lost")}}diff --git a/internal/notifications/apprise_diagnostics.go b/internal/notifications/apprise_diagnostics.goindex 784ec70183..dacdd3c80f 100644--- a/internal/notifications/apprise_diagnostics.go+++ b/internal/notifications/apprise_diagnostics.go@@ -73,7 +73,8 @@ func safeAppriseError(operation string, err error) error {// Inspect wrapped redirect refusals too; unknown reasons stay withheld.for cause := err; cause != nil; cause = errors.Unwrap(cause) {switch cause.Error() {- case "URL userinfo is not allowed", "base URL must not include query or fragment",+ case notificationRedirectOriginMessage,+ "URL userinfo is not allowed", "base URL must not include query or fragment","URL host is required", "URL hostname is required", "base URL path must be host-local","webhook URL userinfo is not allowed", "webhook URL missing hostname","webhook URLs pointing to unspecified addresses are not allowed",diff --git a/internal/notifications/notification_redirect_origin_test.go b/internal/notifications/notification_redirect_origin_test.gonew file mode 100644index 0000000000..f890c84260--- /dev/null+++ b/internal/notifications/notification_redirect_origin_test.go@@ -0,0 +1,51 @@+package notifications++import (+ "net/url"+ "testing"+)++func TestNotificationOriginComparison(t *testing.T) {+ for _, tc := range []struct {+ name, initial, target string+ same bool+ }{+ {"path-query-fragment", "https://receiver.test/start", "https://receiver.test/next?key=fixture#section", true},+ {"dns-case", "https://RECEIVER.test/start", "https://receiver.TEST/next", true},+ {"http-default-port", "http://receiver.test", "http://receiver.test:80/next", true},+ {"https-default-port", "https://receiver.test:443/start", "https://receiver.test/next", true},+ {"decimal-port", "http://receiver.test:080/start", "http://receiver.test:80/next", true},+ {"ipv6-spelling", "https://[2001:DB8:0:0::1]/start", "https://[2001:db8::1]:443/next", true},+ {"ipv6-zone", "http://[fe80::1%25eth0]/start", "http://[fe80::1%25eth0]:80/next", true},+ {"different-zone", "http://[fe80::1%25eth0]", "http://[fe80::1%25ETH0]", false},+ {"different-host", "https://receiver.test", "https://other.test", false},+ {"subdomain", "https://receiver.test", "https://child.receiver.test", false},+ {"suffix-host", "https://receiver.test", "https://receiver.test.other.test", false},+ {"different-port", "https://receiver.test", "https://receiver.test:444", false},+ {"downgrade", "https://receiver.test:443", "http://receiver.test:443", false},+ {"upgrade", "http://receiver.test", "https://receiver.test", false},+ {"dns-root-dot", "https://receiver.test", "https://receiver.test.", false},+ {"userinfo", "https://receiver.test", "https://[email protected]", false},+ {"relative-target", "https://receiver.test", "/next", false},+ {"non-http", "https://receiver.test", "ftp://receiver.test", false},+ {"port-zero", "https://receiver.test", "https://receiver.test:0", false},+ {"port-overflow", "https://receiver.test", "https://receiver.test:65536", false},+ } {+ t.Run(tc.name, func(t *testing.T) {+ initial, err := url.Parse(tc.initial)+ if err != nil {+ t.Fatal(err)+ }+ target, err := url.Parse(tc.target)+ if err != nil {+ t.Fatal(err)+ }+ if sameNotificationOrigin(initial, target) != tc.same || sameNotificationOrigin(target, initial) != tc.same {+ t.Errorf("same-origin comparison = %t, want %t", !tc.same, tc.same)+ }+ })+ }+ if sameNotificationOrigin(nil, &url.URL{}) || sameNotificationOrigin(&url.URL{}, nil) || sameNotificationOrigin(&url.URL{}, &url.URL{}) {+ t.Fatal("missing origin was admitted")+ }+}diff --git a/internal/notifications/notification_redirect_test.go b/internal/notifications/notification_redirect_test.gonew file mode 100644index 0000000000..3b88e298fa--- /dev/null+++ b/internal/notifications/notification_redirect_test.go@@ -0,0 +1,373 @@+package notifications++import (+ "crypto/tls"+ "crypto/x509"+ "database/sql"+ "encoding/json"+ "fmt"+ "io"+ "net/http"+ "strings"+ "sync"+ "testing"+ "time"++ "github.com/rcourtman/pulse-go-rewrite/internal/alerts"+)++// Secret-free loopback receivers: none of these tests sends a real notification.+const redirectPrivateHeader = "synthetic-redirect-authentication"+const redirectPrivateBody = "synthetic-redirect-private-alert"+const redirectPrivateLocation = "synthetic-redirect-private-location"++type notificationRedirectRequest struct {+ method, body string+ headers http.Header+}++type notificationRedirectCapture struct {+ sync.Mutex+ requests []notificationRedirectRequest+}++func (c *notificationRedirectCapture) record(t *testing.T, r *http.Request) {+ t.Helper()+ body, err := io.ReadAll(r.Body)+ if err != nil {+ t.Error("fixture could not read request body")+ }+ c.Lock()+ c.requests = append(c.requests, notificationRedirectRequest{r.Method, string(body), r.Header.Clone()})+ c.Unlock()+}++func (c *notificationRedirectCapture) snapshot() []notificationRedirectRequest {+ c.Lock()+ defer c.Unlock()+ return append([]notificationRedirectRequest(nil), c.requests...)+}++func notificationRedirectFixture(t *testing.T, status int, sameOrigin, hostnameAlias bool) (string, *notificationRedirectCapture, *notificationRedirectCapture) {+ t.Helper()+ initial, final := ¬ificationRedirectCapture{}, ¬ificationRedirectCapture{}+ sink := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ final.record(t, r)+ w.WriteHeader(http.StatusAccepted)+ }))+ t.Cleanup(sink.Close)+ origin := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.URL.Path == "/accepted/"+redirectPrivateLocation {+ final.record(t, r)+ w.WriteHeader(http.StatusAccepted)+ return+ }+ initial.record(t, r)+ target := sink.URL + "/accepted/" + redirectPrivateLocation+ if sameOrigin {+ target = "/accepted/" + redirectPrivateLocation+ } else if hostnameAlias {+ // Same port and resolved IP are not the configured hostname.+ target = strings.Replace("http://"+r.Host, "127.0.0.1", "localhost", 1) + "/accepted/" + redirectPrivateLocation+ }+ http.Redirect(w, r, target, status)+ }))+ t.Cleanup(origin.Close)+ return origin.URL, initial, final+}++func notificationRedirectManager(t *testing.T) *NotificationManager {+ t.Helper()+ n := &NotificationManager{enabled: true, webhookRateLimits: make(map[string]*webhookRateLimit)}+ if err := n.UpdateAllowedPrivateCIDRs("127.0.0.1/32,::1/128"); err != nil {+ t.Fatal(err)+ }+ n.webhookClient = n.createSecureWebhookClient(WebhookTimeout)+ t.Cleanup(n.webhookClient.CloseIdleConnections)+ return n+}++func assertNotificationRedirectRefused(t *testing.T, err error) {+ t.Helper()+ if err == nil || !strings.Contains(err.Error(), "redirects must stay on the configured origin") || !strings.Contains(err.Error(), "use the final destination URL") {+ t.Error("foreign redirect was not rejected with actionable destination guidance")+ return+ }+ if ClassifyNotificationFailureError(err) != NotificationFailureConfiguration || isRetryableWebhookError(err) {+ t.Error("local origin refusal lost its terminal configuration class")+ }+ assertNotificationRedirectPrivate(t, err.Error())+}++func assertNotificationRedirectPrivate(t *testing.T, diagnostic string) {+ t.Helper()+ for _, private := range []string{redirectPrivateHeader, redirectPrivateBody, redirectPrivateLocation} {+ if strings.Contains(diagnostic, private) {+ t.Error("receiver-controlled redirect data escaped into diagnostics")+ }+ }+}++// All five standard redirects are fenced, even when Go would change POST to+// GET but still copy custom headers (or Authorization to another port).+func TestNotificationRedirectOriginTransport(t *testing.T) {+ for _, status := range []int{301, 302, 303, 307, 308} {+ for _, alias := range []bool{false, true} {+ t.Run(fmt.Sprintf("%d/hostname-alias=%t", status, alias), func(t *testing.T) {+ captured := captureAppriseLogs(t)+ base, initial, final := notificationRedirectFixture(t, status, false, alias)+ n := notificationRedirectManager(t)+ webhook := WebhookConfig{URL: base + "/entry", Headers: map[string]string{+ "Authorization": "Bearer " + redirectPrivateHeader, "X-Receiver-Key": redirectPrivateHeader,+ }}+ _, err := n.executeWebhookRequest(webhook, []byte(redirectPrivateBody), webhookRequestOptions{validateURL: true})+ assertNotificationRedirectRefused(t, err)+ first := initial.snapshot()+ if len(first) != 1 || first[0].method != http.MethodPost || first[0].body != redirectPrivateBody || first[0].headers.Get("X-Receiver-Key") != redirectPrivateHeader {+ t.Error("origin admission changed the original configured request")+ }+ if len(final.snapshot()) != 0 {+ t.Error("foreign origin received notification data")+ }+ assertNotificationRedirectPrivate(t, captured.String())+ })+ }+ }+}++func TestNotificationRedirectOriginSendPaths(t *testing.T) {+ for _, path := range []string{"single", "grouped", "resolved", "ntfy-resolved", "enhanced-retry", "test", "enhanced-test", "apprise", "apprise-resolved", "apprise-test"} {+ for _, same := range []bool{false, true} {+ t.Run(fmt.Sprintf("%s/same-origin=%t", path, same), func(t *testing.T) {+ captured := captureAppriseLogs(t)+ base, initial, final := notificationRedirectFixture(t, http.StatusTemporaryRedirect, same, false)+ n := notificationRedirectManager(t)+ webhook := WebhookConfig{Name: "redirect fixture", URL: base + "/entry", Enabled: true,+ Headers: map[string]string{"X-Receiver-Key": redirectPrivateHeader}, SigningSecret: "synthetic-signing-key"}+ alert := &alerts.Alert{ID: "redirect-fixture", Type: "cpu", Message: redirectPrivateBody, ResourceName: "fixture-node",+ Level: alerts.AlertLevelWarning, Value: 90, Threshold: 80, StartTime: time.Unix(100, 0)}+ cfg := AppriseConfig{Enabled: true, Mode: AppriseModeHTTP, ServerURL: base, ConfigKey: "fixture-config",+ APIKey: redirectPrivateHeader, APIKeyHeader: "X-Receiver-Key", Targets: []string{"tgram://" + redirectPrivateHeader + "/fixture"}, TimeoutSeconds: 5}+ var err error+ switch path {+ case "single":+ err = n.sendGroupedWebhook(webhook, []*alerts.Alert{alert})+ case "grouped":+ err = n.sendGroupedWebhook(webhook, []*alerts.Alert{alert, alert.Clone()})+ case "resolved":+ err = n.sendResolvedWebhook(webhook, []*alerts.Alert{alert}, time.Unix(200, 0))+ case "ntfy-resolved":+ webhook.Service = "ntfy"+ err = n.sendResolvedWebhook(webhook, []*alerts.Alert{alert}, time.Unix(200, 0))+ case "enhanced-retry":+ err = n.sendWebhookWithRetry(EnhancedWebhookConfig{WebhookConfig: webhook, RetryCount: 3}, []byte(redirectPrivateBody), "fixture:alert")+ case "test":+ err = n.SendTestWebhook(webhook)+ case "enhanced-test":+ _, _, err = n.TestEnhancedWebhook(BuildEnhancedWebhookTestConfig(webhook, "generic"))+ case "apprise":+ err = n.sendGroupedApprise(cfg, []*alerts.Alert{alert})+ case "apprise-resolved":+ err = n.sendResolvedApprise(cfg, []*alerts.Alert{alert}, time.Unix(200, 0))+ case "apprise-test":+ err = n.SendTestAppriseWithConfig(cfg)+ }+ if same {+ if err != nil {+ t.Error("same-origin notification redirect stopped working")+ }+ } else {+ assertNotificationRedirectRefused(t, err)+ }+ first, last := initial.snapshot(), final.snapshot()+ if len(first) != 1 || first[0].headers.Get("X-Receiver-Key") != redirectPrivateHeader {+ t.Error("configured receiver did not get exactly one authenticated attempt")+ }+ if !same && len(last) != 0 {+ t.Error("foreign receiver got a firing, recovery or Test notification")+ }+ if same && (len(last) != 1 || len(first) != 1 || last[0].body != first[0].body || last[0].method != first[0].method || last[0].headers.Get("X-Receiver-Key") != redirectPrivateHeader || last[0].headers.Get("X-Pulse-Signature") != first[0].headers.Get("X-Pulse-Signature")) {+ t.Error("same-origin redirect changed payload, method, credentials or signature")+ }+ if !same {+ assertNotificationRedirectPrivate(t, captured.String())+ }+ if path == "enhanced-retry" {+ history := n.GetWebhookHistory()+ if len(history) != 1 || history[0].Success != same || history[0].RetryAttempts != 0 {+ t.Error("redirect refusal was retried or marked delivered")+ }+ if len(history) == 1 && !same {+ assertNotificationRedirectPrivate(t, history[0].ErrorMessage)+ }+ }+ })+ }+ }+}++func TestNotificationRedirectOriginTLSDowngrade(t *testing.T) {+ for _, skipTLS := range []bool{false, true} {+ t.Run(fmt.Sprintf("skip-tls=%t", skipTLS), func(t *testing.T) {+ initial, final := ¬ificationRedirectCapture{}, ¬ificationRedirectCapture{}+ sink := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ final.record(t, r)+ w.WriteHeader(http.StatusAccepted)+ }))+ defer sink.Close()+ origin := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ initial.record(t, r)+ http.Redirect(w, r, sink.URL+"/"+redirectPrivateLocation, http.StatusPermanentRedirect)+ }))+ defer origin.Close()+ n := notificationRedirectManager(t)+ n.webhookClient = n.createSecureWebhookClientWithTLS(WebhookTimeout, skipTLS)+ defer n.webhookClient.CloseIdleConnections()+ if !skipTLS {+ roots := x509.NewCertPool()+ roots.AddCert(origin.Certificate())+ n.webhookClient.Transport.(*http.Transport).TLSClientConfig = &tls.Config{RootCAs: roots, MinVersion: tls.VersionTLS12}+ }+ _, err := n.executeWebhookRequest(WebhookConfig{URL: origin.URL, Headers: map[string]string{"X-Receiver-Key": redirectPrivateHeader}}, []byte(redirectPrivateBody), webhookRequestOptions{validateURL: true})+ assertNotificationRedirectRefused(t, err)+ if len(initial.snapshot()) != 1 || len(final.snapshot()) != 0 {+ t.Error("HTTPS origin failed authentication or downgraded private delivery")+ }+ })+ }+}++func TestNotificationSameOriginSignedReplay(t *testing.T) {+ for _, status := range []int{http.StatusTemporaryRedirect, http.StatusPermanentRedirect} {+ t.Run(fmt.Sprint(status), func(t *testing.T) {+ requests := ¬ificationRedirectCapture{}+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ requests.record(t, r)+ switch r.URL.Path {+ case "/first":+ http.Redirect(w, r, "/middle", status)+ case "/middle":+ http.Redirect(w, r, "/final?kept=fixture", status)+ default:+ w.WriteHeader(http.StatusAccepted)+ }+ }))+ defer server.Close()+ n := notificationRedirectManager(t)+ webhook := WebhookConfig{URL: server.URL + "/first", SigningSecret: "synthetic-signing-key",+ Headers: map[string]string{"Authorization": "Bearer " + redirectPrivateHeader, "X-Receiver-Key": redirectPrivateHeader}}+ if err := n.sendWebhookRequest(webhook, []byte(redirectPrivateBody), "alert", "fixture:alert"); err != nil {+ t.Fatal("same-origin signed delivery did not complete")+ }+ got := requests.snapshot()+ if len(got) != WebhookMaxRedirects {+ t.Fatal("same-origin chain did not reach the receiver within the unchanged limit")+ }+ for _, request := range got {+ timestamp := request.headers.Get("X-Pulse-Timestamp")+ if request.method != http.MethodPost || request.body != redirectPrivateBody || request.headers.Get("Authorization") != "Bearer "+redirectPrivateHeader || request.headers.Get("X-Receiver-Key") != redirectPrivateHeader || request.headers.Get("X-Pulse-Event-ID") != "fixture:alert" || timestamp == "" || request.headers.Get("X-Pulse-Signature") != "v1="+signWebhookPayload(webhook.SigningSecret, timestamp, []byte(redirectPrivateBody)) || timestamp != got[0].headers.Get("X-Pulse-Timestamp") {+ t.Error("same-origin replay altered authentication, event identity or signed body")+ }+ }+ })+ }+}++func TestNotificationRedirectOriginQueue(t *testing.T) {+ for _, kind := range []string{"webhook", "webhook_resolved", "apprise", "apprise_resolved"} {+ for _, same := range []bool{false, true} {+ t.Run(fmt.Sprintf("%s/same-origin=%t", kind, same), func(t *testing.T) {+ captured := captureAppriseLogs(t)+ base, initial, final := notificationRedirectFixture(t, http.StatusTemporaryRedirect, same, false)+ q, err := NewNotificationQueue(t.TempDir())+ if err != nil {+ t.Fatal(err)+ }+ defer q.Stop()+ n := notificationRedirectManager(t)+ n.queue = q+ webhook := WebhookConfig{ID: "redirect-destination", Name: "redirect fixture", Enabled: true, URL: base + "/entry",+ Headers: map[string]string{"X-Receiver-Key": redirectPrivateHeader}}+ cfg := AppriseConfig{Enabled: true, Mode: AppriseModeHTTP, ServerURL: base, APIKey: redirectPrivateHeader, APIKeyHeader: "X-Receiver-Key", TimeoutSeconds: 5}+ n.webhooks, n.appriseConfig = []WebhookConfig{webhook}, cfg+ alert := &alerts.Alert{ID: "redirect-occurrence", StartTime: time.Unix(100, 0), Message: redirectPrivateBody}+ job := notificationDeliveryJob{Type: "webhook", Event: eventAlert, WebhookConfig: &webhook, Alerts: []*alerts.Alert{alert}}+ config, err := json.Marshal(webhook)+ if strings.HasPrefix(kind, "apprise") {+ job.Type, job.AppriseConfig = "apprise", &cfg+ config, err = json.Marshal(cfg)+ }+ if err != nil {+ t.Fatal(err)+ }+ resolved := strings.HasSuffix(kind, "_resolved")+ destination := notificationDeliveryDestinationKey(job)+ if resolved {+ if err := q.RecordDeliveryReceipt(alert.ID, alert.StartTime, destination, time.Unix(150, 0)); err != nil {+ t.Fatal(err)+ }+ }+ notif := &QueuedNotification{ID: "redirect-job", Type: kind, Status: QueueStatusPending, Config: config, Alerts: job.Alerts, MaxAttempts: 3}+ if err := q.Enqueue(notif); err != nil {+ t.Fatal(err)+ }+ q.SetProcessor(n.ProcessQueuedNotification)+ // Observe the real dispatcher; do not race it with a manual batch.+ deadline := time.Now().Add(5 * time.Second)+ for {+ var count int+ if err := q.db.QueryRow("SELECT count(*) FROM notification_audit WHERE notification_id = ?", notif.ID).Scan(&count); err != nil {+ t.Fatal(err)+ }+ if count != 0 {+ break+ }+ if time.Now().After(deadline) {+ t.Fatal("notification queue did not finish its attempt")+ }+ time.Sleep(time.Millisecond)+ }+ q.SetProcessor(nil)+ var status, rawConfig string+ var attempts int+ var lastError sql.NullString+ if err := q.db.QueryRow("SELECT status, attempts, last_error, config FROM notification_queue WHERE id = ?", notif.ID).Scan(&status, &attempts, &lastError, &rawConfig); err != nil {+ t.Fatal(err)+ }+ wantStatus := QueueStatusDLQ+ if same {+ wantStatus = QueueStatusSent+ }+ if status != string(wantStatus) || attempts != 1 || rawConfig != string(config) || len(initial.snapshot()) != 1 || (!same && len(final.snapshot()) != 0) || (same && len(final.snapshot()) != 1) {+ t.Error("queue origin verdict, attempt budget or private config snapshot changed")+ }+ var auditError, class string+ var success bool+ if err := q.db.QueryRow("SELECT error_message, failure_class, success FROM notification_audit WHERE notification_id = ?", notif.ID).Scan(&auditError, &class, &success); err != nil {+ t.Fatal(err)+ }+ if success != same || (!same && (class != string(NotificationFailureConfiguration) || !strings.Contains(lastError.String, "configured origin"))) {+ t.Error("origin refusal was reported as delivered or lost from the dead letter/audit")+ }+ if !same {+ assertNotificationRedirectPrivate(t, lastError.String)+ assertNotificationRedirectPrivate(t, auditError)+ entries, err := q.GetDeliveryLog(time.Time{}, 10)+ if err != nil || len(entries) != 1 {+ t.Fatal("delivery-log projection did not retain exactly one failed attempt")+ }+ projection, err := json.Marshal(entries)+ if err != nil {+ t.Fatal(err)+ }+ assertNotificationRedirectPrivate(t, string(projection))+ assertNotificationRedirectPrivate(t, captured.String())+ }+ hasReceipt, err := q.HasDeliveryReceipt(alert.ID, alert.StartTime, destination)+ if err != nil || hasReceipt != (same != resolved) {+ t.Error("refused redirect invented a firing receipt or erased a recovery receipt")+ }+ })+ }+ }+}diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.goindex 67ea7fa95a..577119100d 100644--- a/internal/notifications/notifications.go+++ b/internal/notifications/notifications.go@@ -198,7 +198,13 @@ func (n *NotificationManager) createSecureWebhookClientWithURLDiagnostics(timeouif len(via) >= WebhookMaxRedirects {return fmt.Errorf("stopped after %d redirects", WebhookMaxRedirects)}- // Re-validate strictly on redirect+ // SSRF admission is not permission to forward private alert bodies,+ // custom authentication headers or signatures to a different receiver.+ if len(via) == 0 || via[0] == nil || !sameNotificationOrigin(via[0].URL, req.URL) {+ return FailWithClass(NotificationFailureConfiguration, errNotificationRedirectOrigin)+ }+ // Re-validate strictly on an admitted redirect, including DNS/IP+ // changes. Foreign origins are rejected before resolution or logging.return n.validateWebhookURL(req.URL.String(), diagnosticURL)},}diff --git a/internal/notifications/notifications_security_http_test.go b/internal/notifications/notifications_security_http_test.goindex 4fce58a4f0..7b191edcc5 100644--- a/internal/notifications/notifications_security_http_test.go+++ b/internal/notifications/notifications_security_http_test.go@@ -186,8 +186,8 @@ func TestSendAppriseViaHTTPBlocksRedirectToLinkLocal(t *testing.T) {if err == nil {t.Fatalf("expected redirect validation error")}- if !strings.Contains(err.Error(), "link-local addresses are not allowed") {- t.Fatalf("expected link-local redirect to be blocked, got %v", err)+ if !strings.Contains(err.Error(), "configured origin") {+ t.Fatalf("expected link-local redirect to be blocked before resolution, got %v", err)}}diff --git a/internal/notifications/webhook_client_test.go b/internal/notifications/webhook_client_test.goindex d23daaab95..5779cfe278 100644--- a/internal/notifications/webhook_client_test.go+++ b/internal/notifications/webhook_client_test.go@@ -84,8 +84,8 @@ func TestSecureWebhookClientBlocksUnsafeRedirect(t *testing.T) {if err == nil {t.Fatal("expected error from unsafe redirect, got nil")}- if !strings.Contains(err.Error(), "private IP") {- t.Errorf("expected private IP validation error, got: %v", err)+ if !strings.Contains(err.Error(), "configured origin") {+ t.Errorf("expected origin rejection before redirect validation, got: %v", err)}}@@ -120,40 +120,33 @@ func TestSecureWebhookClientBlocksPrivateNetworkRedirect(t *testing.T) {if err == nil {t.Fatalf("expected error from redirect to %s, got nil", privateURL)}- if !strings.Contains(err.Error(), "private IP") {- t.Errorf("expected private IP validation error for %s, got: %v", privateURL, err)+ if !strings.Contains(err.Error(), "configured origin") {+ t.Errorf("expected origin rejection before resolving %s, got: %v", privateURL, err)}})}}// TestSecureWebhookClientAllowsValidRedirects verifies that valid redirects-// to safe URLs are followed successfully.+// within the configured origin are followed successfully.func TestSecureWebhookClientAllowsValidRedirects(t *testing.T) {- // Create a chain of servers for redirect testing- // Final server returns 200 OK- finalServer := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- w.WriteHeader(http.StatusOK)- w.Write([]byte("success"))- }))- defer finalServer.Close()-- // Middle server redirects to final- middleServer := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- http.Redirect(w, r, finalServer.URL, http.StatusFound)- }))- defer middleServer.Close()-- // First server redirects to middle- firstServer := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {- http.Redirect(w, r, middleServer.URL, http.StatusFound)+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ switch r.URL.Path {+ case "/first":+ http.Redirect(w, r, "/middle", http.StatusFound)+ case "/middle":+ http.Redirect(w, r, "/final", http.StatusFound)+ default:+ w.WriteHeader(http.StatusOK)+ w.Write([]byte("success"))+ }}))- defer firstServer.Close()+ defer server.Close()nm := createTestNotificationManager(t)client := nm.createSecureWebhookClient(WebhookTimeout)- resp, err := client.Get(firstServer.URL)+ resp, err := client.Get(server.URL + "/first")if err != nil {t.Fatalf("expected successful redirect chain, got error: %v", err)@@ -181,8 +174,8 @@ func TestSecureWebhookClientBlocksLinkLocalRedirect(t *testing.T) {if err == nil {t.Fatal("expected error from redirect to link-local/metadata address, got nil")}- if !strings.Contains(err.Error(), "link-local") {- t.Errorf("expected link-local validation error, got: %v", err)+ if !strings.Contains(err.Error(), "configured origin") {+ t.Errorf("expected origin rejection before metadata access, got: %v", err)}}diff --git a/internal/notifications/webhook_enhanced.go b/internal/notifications/webhook_enhanced.goindex 23f9b4d641..7f65c6ac74 100644--- a/internal/notifications/webhook_enhanced.go+++ b/internal/notifications/webhook_enhanced.go@@ -2,6 +2,7 @@ package notificationsimport ("bytes"+ "errors""fmt""net/http""regexp"@@ -503,6 +504,12 @@ func parseRetryAfterBackoff(retryAfter string, now time.Time) (time.Duration, bo// isRetryableWebhookError determines if a webhook error should trigger a retryfunc isRetryableWebhookError(err error) bool {+ // A local security/configuration refusal is authoritative too. In+ // particular, retrying an origin-changing redirect cannot make it safe.+ var declared *NotificationFailureError+ if errors.As(err, &declared) && declared.Class != "" {+ return declared.Class.Retryable()+ }// An explicit HTTP rejection takes precedence over diagnostic body text:// a 403 mentioning "timeout" is not a transport timeout. Errors without// a recognised status (including network failures) remain retryable below.diff --git a/internal/notifications/webhook_redirect.go b/internal/notifications/webhook_redirect.gonew file mode 100644index 0000000000..38c921138f--- /dev/null+++ b/internal/notifications/webhook_redirect.go@@ -0,0 +1,57 @@+package notifications++import (+ "errors"+ "net"+ "net/netip"+ "net/url"+ "strconv"+ "strings"+)++const notificationRedirectOriginMessage = "notification redirects must stay on the configured origin; use the final destination URL"++var errNotificationRedirectOrigin = errors.New(notificationRedirectOriginMessage)++// Compare HTTP origins, not IP resolution, parent domains or just hostnames.+// Another port is another receiver even on the same host. URL paths and query+// strings may change, but HTTPS must never downgrade (nor HTTP upgrade silently).+func sameNotificationOrigin(initial, target *url.URL) bool {+ first, ok := notificationOrigin(initial)+ if !ok {+ return false+ }+ next, ok := notificationOrigin(target)+ return ok && first == next+}++func notificationOrigin(u *url.URL) (string, bool) {+ if u == nil || u.Opaque != "" || u.User != nil || u.Hostname() == "" {+ return "", false+ }+ scheme := strings.ToLower(u.Scheme)+ port := u.Port()+ switch scheme {+ case "http":+ if port == "" {+ port = "80"+ }+ case "https":+ if port == "" {+ port = "443"+ }+ default:+ return "", false+ }+ number, err := strconv.ParseUint(port, 10, 16)+ if err != nil || number == 0 {+ return "", false+ }+ host := u.Hostname()+ if address, err := netip.ParseAddr(host); err == nil {+ host = address.String() // Preserve case-sensitive IPv6 zone identity.+ } else {+ host = strings.ToLower(host)+ }+ return scheme + "://" + net.JoinHostPort(host, strconv.FormatUint(number, 10)), true+}diff --git a/internal/notifications/webhook_url_redaction.go b/internal/notifications/webhook_url_redaction.goindex 370fbba9e5..3de87fddda 100644--- a/internal/notifications/webhook_url_redaction.go+++ b/internal/notifications/webhook_url_redaction.go@@ -143,5 +143,10 @@ func redactWebhookTransportError(err error) error {redacted := *urlErrorredacted.URL = RedactWebhookURLSecrets(urlError.URL)+ if errors.Is(err, errNotificationRedirectOrigin) {+ // A receiver controls Location and can echo private payloads or keys+ // into arbitrary paths/query names. None of that URL is diagnostic data.+ redacted.URL = "[redirect destination withheld]"+ }return &redacted}