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.

Harden webhook request URL validation

rcourtman53f41fdb4517
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.md
index 2e21cb8fa2..44d230d6fd 100644
--- a/docs/release-control/v6/internal/subsystems/notifications.md
+++ b/docs/release-control/v6/internal/subsystems/notifications.md
@@ -105,6 +105,10 @@ Enhanced webhook test/live delivery must follow that same ownership model:
into the canonical webhook render and transport path instead of maintaining a
parallel URL-rendering, enrichment, Telegram URL sanitization, or single-send
HTTP stack.
+That same transport boundary also owns webhook request normalization. Rendered
+webhook URLs must reject userinfo during validation, and request construction
+must route through a validated absolute URL object instead of reparsing raw URL
+strings at send time.
That same ownership includes webhook retry classification. The canonical
retry gate in `webhook_enhanced.go` must parse provider failures from both
`status 429`-style and `HTTP 429`-style error strings before it decides
diff --git a/internal/notifications/notifications.go b/internal/notifications/notifications.go
index 78b5241542..930da52b3b 100644
--- a/internal/notifications/notifications.go
+++ b/internal/notifications/notifications.go
@@ -2185,7 +2185,12 @@ func (n *NotificationManager) executeWebhookRequest(webhook WebhookConfig, paylo
method = "POST"
}
- req, err := http.NewRequest(method, normalizeWebhookRequestURL(webhook), bytes.NewBuffer(payload))
+ targetURL, err := securityutil.NormalizeAbsoluteHTTPURL(normalizeWebhookRequestURL(webhook))
+ if err != nil {
+ return nil, fmt.Errorf("failed to normalize webhook request URL: %w", err)
+ }
+
+ req, err := securityutil.NewValidatedRequestWithContext(context.Background(), method, targetURL, bytes.NewBuffer(payload))
if err != nil {
return nil, fmt.Errorf("failed to create webhook request: %w", err)
}
@@ -2608,6 +2613,9 @@ func (n *NotificationManager) ValidateWebhookURL(webhookURL string) error {
if err != nil {
return fmt.Errorf("invalid URL format: %w", err)
}
+ if u.User != nil {
+ return fmt.Errorf("webhook URL userinfo is not allowed")
+ }
// Must be HTTP or HTTPS
if u.Scheme != "http" && u.Scheme != "https" {
diff --git a/internal/notifications/notifications_security_http_test.go b/internal/notifications/notifications_security_http_test.go
index 3b54dd668a..4ebd131885 100644
--- a/internal/notifications/notifications_security_http_test.go
+++ b/internal/notifications/notifications_security_http_test.go
@@ -68,6 +68,46 @@ func TestSendAppriseViaHTTPRejectsUserinfoServerURL(t *testing.T) {
}
}
+func TestSendTestWebhookRejectsUserinfoURLBeforeOutboundDelivery(t *testing.T) {
+ nm := NewNotificationManager("https://pulse.local")
+ 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)
+ }
+
+ serverURL, err := url.Parse(server.URL)
+ if err != nil {
+ t.Fatalf("parse server URL: %v", err)
+ }
+ serverURL.User = url.UserPassword("user", "pass")
+
+ err = nm.SendTestWebhook(WebhookConfig{
+ Name: "Userinfo Webhook",
+ URL: serverURL.String(),
+ Enabled: true,
+ })
+ if err == nil || !strings.Contains(err.Error(), "userinfo") {
+ t.Fatalf("expected userinfo validation error, got %v", err)
+ }
+
+ select {
+ case <-called:
+ t.Fatal("expected userinfo-bearing webhook URL to be rejected before outbound delivery")
+ default:
+ }
+}
+
func TestSendAppriseViaHTTPBlocksRedirectToLinkLocal(t *testing.T) {
nm := NewNotificationManager("")
defer nm.Stop()
diff --git a/internal/notifications/webhook_allowlist_test.go b/internal/notifications/webhook_allowlist_test.go
index f2404703c6..b1d8fd6f87 100644
--- a/internal/notifications/webhook_allowlist_test.go
+++ b/internal/notifications/webhook_allowlist_test.go
@@ -332,6 +332,18 @@ func TestValidateWebhookURL_InvalidScheme(t *testing.T) {
}
}
+func TestValidateWebhookURL_RejectsUserinfo(t *testing.T) {
+ nm := NewNotificationManager("")
+
+ err := nm.ValidateWebhookURL("http://user:[email protected]/webhook")
+ if err == nil {
+ t.Fatal("expected error for URL userinfo")
+ }
+ if !strings.Contains(err.Error(), "userinfo") {
+ t.Fatalf("expected userinfo error, got %v", err)
+ }
+}
+
func TestValidateWebhookURL_MissingHostname(t *testing.T) {
nm := NewNotificationManager("")