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
fix(notifications): webhook dialer tries every permitted resolved IP instead of pinning the first
rcourtmanb5d852a279cb
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex 944f0a19d5..707f15a077 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -155,6 +155,12 @@ strings at send time. The same SSRF guard must reject unspecified directtargets such as `0.0.0.0` and `::` before delivery and must not allow webhookprivate-CIDR allowlists to include networks that contain those unspecifiedaddresses.+The DNS-rebinding pin in the secure webhook dialer is part of that same guard:+hostname dials may connect only to resolver-validated IPs, and the dialer must+try every permitted resolved address in resolution order rather than pinning+the first, so an IPv6-first resolution (`::1` ahead of `127.0.0.1`) or a dead+leading A record cannot fail delivery to a host that is reachable on a later+permitted address.That same ownership includes webhook retry classification. The canonicalretry gate in `webhook_enhanced.go` must parse provider failures from both`status 429`-style and `HTTP 429`-style error strings before it decidesdiff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.goindex 6da4bed668..14cbc9a329 100644--- a/internal/notifications/notifications.go+++ b/internal/notifications/notifications.go@@ -130,21 +130,20 @@ func (n *NotificationManager) createSecureWebhookClientWithTLS(timeout time.Dura}// Resolve hostname- ips, err := net.LookupIP(host)+ ips, err := n.lookupWebhookHostIPs(host)if err != nil {return nil, fmt.Errorf("resolve webhook host %q: %w", host, err)}- // Find first permitted IP- var permittedIP net.IP+ // Collect every permitted IP in resolution order+ var permittedIPs []net.IPfor _, ip := range ips {if !isPrivateIP(ip) || n.isIPInAllowlist(ip) {- permittedIP = ip- break+ permittedIPs = append(permittedIPs, ip)}}- if permittedIP == nil {+ if len(permittedIPs) == 0 {return nil, fmt.Errorf("hostname %s resolves to blocked private IPs", host)}@@ -152,13 +151,29 @@ func (n *NotificationManager) createSecureWebhookClientWithTLS(timeout time.Duraif len(ips) > 1 {log.Debug().Str("host", host).- Str("selected_ip", permittedIP.String()).+ Int("resolved", len(ips)).+ Int("permitted", len(permittedIPs)).Msg("dns resolution pinned for webhook security")}- // Dial the permitted IP+ // Try every permitted IP from the validating resolution, not just the+ // first: a hostname can resolve to ::1 ahead of 127.0.0.1 while the+ // webhook receiver listens only on one loopback family, and a+ // multi-A-record host can lead with a dead address. Each candidate was+ // validated above, so rebinding protection is unchanged.d := net.Dialer{Timeout: 10 * time.Second}- return d.DialContext(ctx, network, net.JoinHostPort(permittedIP.String(), port))+ var dialErr error+ for _, permittedIP := range permittedIPs {+ conn, err := d.DialContext(ctx, network, net.JoinHostPort(permittedIP.String(), port))+ if err == nil {+ return conn, nil+ }+ dialErr = err+ if ctx.Err() != nil {+ break+ }+ }+ return nil, dialErr},ForceAttemptHTTP2: true,MaxIdleConns: 100,@@ -233,15 +248,16 @@ type NotificationManager struct {webhookRateMu sync.Mutex // Separate mutex for webhook rate limitingwebhookRateCleanup time.Time // Last cleanup time for webhook rate limit entriesappriseExec appriseExecFunc- queue *NotificationQueue // Persistent notification queue- tenantID string // Tenant identity stamped into webhook payloads (env default)- tenantName string // Tenant display name stamped into webhook payloads (env default)- tenantResolver func() (id string, name string) // Org-backed tenant identity override (multi-tenant)- webhookClient *http.Client // Shared HTTP client for webhooks- stopCleanup chan struct{} // Signal to stop cleanup goroutine- cleanupDone chan struct{} // Signals cleanup goroutine exit during shutdown- allowedPrivateNets []*net.IPNet // Parsed CIDR ranges allowed for private webhook targets- allowedPrivateMu sync.RWMutex // Protects allowedPrivateNets+ queue *NotificationQueue // Persistent notification queue+ tenantID string // Tenant identity stamped into webhook payloads (env default)+ tenantName string // Tenant display name stamped into webhook payloads (env default)+ tenantResolver func() (id string, name string) // Org-backed tenant identity override (multi-tenant)+ webhookClient *http.Client // Shared HTTP client for webhooks+ stopCleanup chan struct{} // Signal to stop cleanup goroutine+ cleanupDone chan struct{} // Signals cleanup goroutine exit during shutdown+ allowedPrivateNets []*net.IPNet // Parsed CIDR ranges allowed for private webhook targets+ allowedPrivateMu sync.RWMutex // Protects allowedPrivateNets+ resolveWebhookIPs func(host string) ([]net.IP, error) // Test seam for webhook dialer DNS resolution; nil means net.LookupIP}type webhookHTTPResult struct {@@ -3119,6 +3135,14 @@ func (n *NotificationManager) UpdateAllowedPrivateCIDRs(cidrsString string) erroreturn nil}+// lookupWebhookHostIPs resolves a webhook hostname for the SSRF-pinned dialer.+func (n *NotificationManager) lookupWebhookHostIPs(host string) ([]net.IP, error) {+ if n.resolveWebhookIPs != nil {+ return n.resolveWebhookIPs(host)+ }+ return net.LookupIP(host)+}+// isIPInAllowlist checks if an IP is in the configured allowlistfunc (n *NotificationManager) isIPInAllowlist(ip net.IP) bool {n.allowedPrivateMu.RLock()diff --git a/internal/notifications/webhook_client_test.go b/internal/notifications/webhook_client_test.goindex 77405ebb9d..d23daaab95 100644--- a/internal/notifications/webhook_client_test.go+++ b/internal/notifications/webhook_client_test.go@@ -2,6 +2,7 @@ package notificationsimport ("context"+ "net""net/http""strings""testing"@@ -255,6 +256,45 @@ func TestSecureWebhookClientDialContextAllowsHostnameWithAllowlist(t *testing.T)resp.Body.Close()}+// TestSecureWebhookClientDialContextTriesAllPermittedResolvedIPs pins the+// multi-IP dial behavior: a host that resolves to ::1 first while the webhook+// receiver listens only on 127.0.0.1 must still connect via the next permitted+// IP instead of failing on the first (regression for the first-permitted-IP+// pin, same defect class fixed in pkg/securityutil).+func TestSecureWebhookClientDialContextTriesAllPermittedResolvedIPs(t *testing.T) {+ server := newIPv4HTTPServer(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.WriteHeader(http.StatusOK)+ }))+ defer server.Close()++ _, port, err := net.SplitHostPort(strings.TrimPrefix(server.URL, "http://"))+ if err != nil {+ t.Fatalf("failed to parse test server address: %v", err)+ }++ nm := &NotificationManager{+ lastNotified: make(map[string]notificationRecord),+ webhookRateLimits: make(map[string]*webhookRateLimit),+ }+ // Permit both loopback families so ::1 survives filtering and is dialed first.+ if err := nm.UpdateAllowedPrivateCIDRs("127.0.0.0/8,::1/128"); err != nil {+ t.Fatalf("failed to set allowlist: %v", err)+ }+ nm.resolveWebhookIPs = func(host string) ([]net.IP, error) {+ return []net.IP{net.ParseIP("::1"), net.ParseIP("127.0.0.1")}, nil+ }++ client := nm.createSecureWebhookClient(WebhookTimeout)+ resp, err := client.Get("http://ipv6-first.test:" + port + "/")+ if err != nil {+ t.Fatalf("expected fallback to the second permitted IP to succeed, got: %v", err)+ }+ resp.Body.Close()+ if resp.StatusCode != http.StatusOK {+ t.Fatalf("expected status 200, got %d", resp.StatusCode)+ }+}+func TestSecureWebhookClientDialContextAllowsPublicIP(t *testing.T) {nm := &NotificationManager{lastNotified: make(map[string]notificationRecord),