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
Check embedded IPv4 destinations in the webhook SSRF guard
rcourtman9fb704e0e8e0
diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.goindex b4c3e9df82..fab4422de5 100644--- a/internal/notifications/notifications.go+++ b/internal/notifications/notifications.go@@ -26,6 +26,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/alerts""github.com/rcourtman/pulse-go-rewrite/internal/securityutil"+ pkgsecurityutil "github.com/rcourtman/pulse-go-rewrite/pkg/securityutil""github.com/rs/zerolog/log")@@ -3800,8 +3801,25 @@ func (n *NotificationManager) validateWebhookURL(webhookURL string, diagnosticURreturn nil}-// isPrivateIP checks if an IP address is in a private range+// isPrivateIP reports whether ip, or any IPv4 destination an IPv6 transition+// address (NAT64, 6to4, Teredo and friends) embeds in it, is in a private or+// special-use range. Without the embedded check 64:ff9b::a9fe:a9fe passes as a+// public address while a NAT64 gateway delivers it to 169.254.169.254.func isPrivateIP(ip net.IP) bool {+ if isPrivateIPLiteral(ip) {+ return true+ }+ for _, embedded := range pkgsecurityutil.EmbeddedIPv4Candidates(ip) {+ if isPrivateIPLiteral(embedded) {+ return true+ }+ }+ return false+}++// isPrivateIPLiteral checks the address exactly as given against the private+// and special-use ranges.+func isPrivateIPLiteral(ip net.IP) bool {// Private and special-use ranges that should not be reachable via webhooks.privateRanges := []string{"10.0.0.0/8", // RFC1918diff --git a/internal/notifications/webhook_transition_address_test.go b/internal/notifications/webhook_transition_address_test.gonew file mode 100644index 0000000000..d3c28f0c25--- /dev/null+++ b/internal/notifications/webhook_transition_address_test.go@@ -0,0 +1,46 @@+package notifications++import (+ "net"+ "testing"+)++// An IPv6 transition address carries an IPv4 destination inside it, so a+// NAT64 gateway delivers 64:ff9b::a9fe:a9fe to the cloud metadata service at+// 169.254.169.254. The webhook guard must judge the embedded destination, not+// just the outer address.+func TestIsPrivateIPCatchesTransitionAddresses(t *testing.T) {+ for _, tc := range []struct {+ name string+ ip string+ want bool+ }{+ {"NAT64 metadata service", "64:ff9b::a9fe:a9fe", true},+ {"NAT64 loopback", "64:ff9b::7f00:1", true},+ {"NAT64 local-use prefix RFC1918", "64:ff9b:1::a00:1", true},+ {"6to4 loopback", "2002:7f00:1::", true},+ {"6to4 RFC1918", "2002:c0a8:101::1", true},+ {"Teredo server RFC1918", "2001:0:a00:1::1", true},+ {"NAT64 public destination", "64:ff9b::808:808", false},+ {"public IPv6", "2607:f8b0::1", false},+ {"public IPv4", "8.8.8.8", false},+ {"plain loopback", "127.0.0.1", true},+ } {+ t.Run(tc.name, func(t *testing.T) {+ ip := net.ParseIP(tc.ip)+ if ip == nil {+ t.Fatalf("parse %q", tc.ip)+ }+ if got := isPrivateIP(ip); got != tc.want {+ t.Fatalf("isPrivateIP(%s) = %v, want %v", tc.ip, got, tc.want)+ }+ })+ }+}++func TestValidateWebhookURLRejectsNAT64MetadataAddress(t *testing.T) {+ nm := NewNotificationManager("")+ if err := nm.ValidateWebhookURL("http://[64:ff9b::a9fe:a9fe]/latest/meta-data/"); err == nil {+ t.Fatal("a NAT64-encoded metadata address passed webhook validation")+ }+}