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 connection probe and simple stats rendering
rcourtman43922161e405
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 605169ed56..3b4d3321c9 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -300,7 +300,11 @@ an add-only capacity posture.agent `Host.LastSeen`-backed rows on that ledger, but must notreinterpret derived `state` (active/paused/unauthorized/unreachable/stale/pending) as install authority or treat the probe response as- enrollment state; ledger writes still flow through the per-type config+ enrollment state. Metadata, link-local, multicast, and unspecified+ probe destinations must fail closed before any outbound dial, and+ lifecycle surfaces must surface that canonical rejection instead of+ retrying through lane-local probe helpers. Ledger writes still flow+ through the per-type configendpoints that own admission checks, and the `Disabled` flag onPVE/PBS/PMG surfaced by that ledger must remain a pause-only signalrather than an installer pre-flight gate.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex ea47a9934f..cf4cd2ad21 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -361,7 +361,11 @@ the canonical monitored-system blocked payload.(`monitoring.Monitor.SchedulerHealth()`) plus agent `Host.LastSeen`; theendpoint must not introduce new persisted per-connection state. The probeendpoint must remain admin-gated (`RequireAdmin` + `ScopeSettingsWrite`)- to block unauthenticated SSRF against internal hosts.+ to block unauthenticated SSRF against internal hosts. That same probe path+ must also validate user-supplied addresses before probing, reject metadata,+ link-local, multicast, and unspecified destinations, and pin each outbound+ dial to the first permitted resolved IP so DNS rebinding cannot swap the+ target between validation and connect time.## Forbidden Pathsdiff --git a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md b/docs/release-control/v6/internal/subsystems/performance-and-scalability.mdindex 74d06ccab2..0fd07ab774 100644--- a/docs/release-control/v6/internal/subsystems/performance-and-scalability.md+++ b/docs/release-control/v6/internal/subsystems/performance-and-scalability.md@@ -282,7 +282,12 @@ regression protection.`/api/connections/probe` must keep those routes off the monitoring fan-outbudget: `GET /api/connections` must resolve purely from`monitoring.Monitor.SchedulerHealth()` plus existing per-type config- stores without triggering any live network probes, and+ stores without triggering any live network probes, and blocked metadata,+ link-local, multicast, and unspecified probe destinations must be+ rejected during request validation so the route does not spend dial budget+ or become a side-channel scanner against forbidden targets. The probe path+ must also keep the validated destination pinned through the restricted+ outbound client so DNS rebinding cannot swap targets after admission, and`POST /api/connections/probe` must remain bounded at 3s total /2s dial / 1s read with at most 5 concurrent fingerprints so the probeendpoint cannot be repurposed into a slow-leak scanner that starves thediff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 30b3f7db73..c1eeda3445 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -360,7 +360,11 @@ querying, and the operator-facing storage health presentation layer.storage and recovery consumers must not reinterpret the derivedconnection `state` (active/paused/unauthorized/unreachable/stale/pending)as storage health, backup-job posture, or recovery verification state;- storage and recovery UI must keep sourcing those signals from their+ they also must not repurpose the shared probe route as a generic internal+ reachability scanner. Metadata, link-local, multicast, and unspecified+ destinations remain fail-closed before dial on that shared route, and any+ future storage/recovery adjacency must preserve that same boundary.+ Storage and recovery UI must keep sourcing those signals from theirexisting canonical page models instead of polling the connectionsledger for per-datastore or per-backup truth.diff --git a/internal/api/connections_handlers.go b/internal/api/connections_handlers.goindex 1157ae2ea4..ac65fcf921 100644--- a/internal/api/connections_handlers.go+++ b/internal/api/connections_handlers.go@@ -101,6 +101,10 @@ func (h *ConnectionsHandlers) HandleProbe(w http.ResponseWriter, r *http.RequestwriteErrorResponse(w, http.StatusBadRequest, "invalid_address", err.Error(), nil)return}+ if err := validateProbeHost(r.Context(), host); err != nil {+ writeErrorResponse(w, http.StatusBadRequest, "invalid_address", err.Error(), nil)+ return+ }candidates, elapsed := runProbe(r.Context(), host, port, probeHTTPClient())writeJSON(w, http.StatusOK, ProbeResponse{diff --git a/internal/api/connections_probe.go b/internal/api/connections_probe.goindex 5783819904..a5c4771a5d 100644--- a/internal/api/connections_probe.go+++ b/internal/api/connections_probe.go@@ -15,6 +15,8 @@ import ("strings""sync""time"++ "github.com/rcourtman/pulse-go-rewrite/internal/securityutil")// Probe budget. Per-candidate and whole-request ceilings are kept tight to@@ -197,18 +199,37 @@ func targetsForPort(port int) []probeTarget {// because the whole point of probing is to talk to a server whose cert we// haven't trusted yet.func probeHTTPClient() *http.Client {- return &http.Client{- Transport: &http.Transport{- DialContext: (&net.Dialer{- Timeout: probeDialTimeout,- }).DialContext,- TLSHandshakeTimeout: probeDialTimeout,- TLSClientConfig: &tls.Config{InsecureSkipVerify: true},- DisableKeepAlives: true,+ return securityutil.NewRestrictedOutboundHTTPClient(probeDialTimeout+time.Second, securityutil.RestrictedOutboundHTTPOptions{+ AllowedSchemes: []string{"https"},+ AllowPrivateIPs: true,+ AllowLoopback: true,+ TLSConfig: &tls.Config{+ MinVersion: tls.VersionTLS12,+ InsecureSkipVerify: true, //nolint:gosec // Probing intentionally accepts untrusted certificates for fingerprint capture.},- // Overall per-request ceiling is the dial + read budget.- Timeout: probeDialTimeout + time.Second,+ })+}++func validateProbeHost(ctx context.Context, host string) error {+ host = strings.TrimSpace(host)+ if host == "" {+ return fmt.Errorf("address is required")+ }++ urlHost := host+ if ip := net.ParseIP(host); ip != nil && strings.Contains(host, ":") {+ urlHost = "[" + host + "]"+ }++ _, err := securityutil.ValidateOutboundFetchURL(ctx, "https://"+urlHost+"/", securityutil.RestrictedOutboundHTTPOptions{+ AllowedSchemes: []string{"https"},+ AllowPrivateIPs: true,+ AllowLoopback: true,+ })+ if err != nil {+ return fmt.Errorf("address is not allowed: %w", err)}+ return nil}// runProbe fans out probe requests against every candidate target. Itdiff --git a/internal/api/connections_probe_test.go b/internal/api/connections_probe_test.goindex ef3dfec79d..179bc23a6e 100644--- a/internal/api/connections_probe_test.go+++ b/internal/api/connections_probe_test.go@@ -3,6 +3,7 @@ package apiimport ("context""crypto/tls"+ "encoding/json""fmt""net""net/http"@@ -332,3 +333,38 @@ func TestRunProbe_TotalBudgetEnforced(t *testing.T) {t.Fatalf("probe exceeded expected timeout: %s", elapsed)}}++func TestValidateProbeHostRejectsMetadataService(t *testing.T) {+ err := validateProbeHost(context.Background(), "169.254.169.254")+ if err == nil {+ t.Fatal("expected metadata service address to be rejected")+ }+ if !strings.Contains(err.Error(), "metadata service") {+ t.Fatalf("unexpected error: %v", err)+ }+}++func TestConnectionsHandlersHandleProbeRejectsBlockedAddress(t *testing.T) {+ h := NewConnectionsHandlers(nil, nil, nil)+ body := strings.NewReader(`{"address":"169.254.169.254"}`)+ req := httptest.NewRequest(http.MethodPost, "/api/connections/probe", body)+ rec := httptest.NewRecorder()++ h.HandleProbe(rec, req)++ if rec.Code != http.StatusBadRequest {+ t.Fatalf("status = %d, want %d (%s)", rec.Code, http.StatusBadRequest, rec.Body.String())+ }++ var payload map[string]any+ if err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {+ t.Fatalf("decode response: %v", err)+ }+ if payload["code"] != "invalid_address" {+ t.Fatalf("code = %v, want invalid_address", payload["code"])+ }+ message, _ := payload["error"].(string)+ if !strings.Contains(message, "metadata service") {+ t.Fatalf("message = %q, want metadata-service guidance", message)+ }+}diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 9870c6c8db..50a86f0d36 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -10858,6 +10858,49 @@ func TestContract_ProbePayloadShapeStaysCanonical(t *testing.T) {assertJSONSnapshot(t, body, want)}+func TestContract_ProbeRejectsBlockedMetadataAddress(t *testing.T) {+ handler := NewConnectionsHandlers(nil, nil, nil)+ req := httptest.NewRequest(http.MethodPost, "/api/connections/probe", strings.NewReader(`{"address":"169.254.169.254"}`))+ req.Header.Set("Content-Type", "application/json")+ rec := httptest.NewRecorder()++ handler.HandleProbe(rec, req)++ if rec.Code != http.StatusBadRequest {+ t.Fatalf("status = %d, want %d (%s)", rec.Code, http.StatusBadRequest, rec.Body.String())+ }++ var payload APIError+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {+ t.Fatalf("decode error payload: %v", err)+ }+ if payload.Code != "invalid_address" {+ t.Fatalf("code = %q, want %q", payload.Code, "invalid_address")+ }+ if !strings.Contains(payload.ErrorMessage, "metadata service address is not allowed") {+ t.Fatalf("error = %q, want metadata-service rejection", payload.ErrorMessage)+ }+}++func TestContract_SimpleStatsUsesTextNodesForContainerFields(t *testing.T) {+ req := httptest.NewRequest(http.MethodGet, "/simple-stats", nil)+ rec := httptest.NewRecorder()++ var router Router+ router.handleSimpleStats(rec, req)++ if rec.Code != http.StatusOK {+ t.Fatalf("status = %d, want %d", rec.Code, http.StatusOK)+ }+ body := rec.Body.String()+ if strings.Contains(body, "row.innerHTML") {+ t.Fatalf("simple stats page must not use row.innerHTML for container rendering")+ }+ if !strings.Contains(body, "textContent") {+ t.Fatalf("simple stats page must use textContent for container rendering")+ }+}+func mustStreamEvent(t *testing.T, eventType string, data interface{}) chat.StreamEvent {t.Helper()diff --git a/internal/api/router.go b/internal/api/router.goindex dad2196743..f6955c4f37 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -9285,6 +9285,28 @@ func (r *Router) handleSimpleStats(w http.ResponseWriter, req *http.Request) {const percent = ((used / total) * 100).toFixed(0);return usedGB + '/' + totalGB + ' GB (' + percent + '%)';}++ function appendCell(row, value, className) {+ const cell = document.createElement('td');+ if (className) {+ cell.className = className;+ }+ cell.textContent = value;+ row.appendChild(cell);+ return cell;+ }++ function appendStatusCell(row, status) {+ const cell = document.createElement('td');+ const badge = document.createElement('span');+ badge.classList.add('status');+ if (status === 'running' || status === 'stopped') {+ badge.classList.add(status);+ }+ badge.textContent = status || 'unknown';+ cell.appendChild(badge);+ row.appendChild(cell);+ }function updateTable(containers) {const tbody = document.querySelector('#containers tbody');@@ -9294,15 +9316,19 @@ func (r *Router) handleSimpleStats(w http.ResponseWriter, req *http.Request) {containers.forEach(ct => {const row = document.createElement('tr');- row.innerHTML =- '<td><strong>' + ct.name + '</strong></td>' +- '<td><span class="status ' + ct.status + '">' + ct.status + '</span></td>' +- '<td class="metric">' + (ct.cpu ? ct.cpu.toFixed(1) : '0.0') + '%</td>' +- '<td class="metric">' + formatMemory(ct.mem || 0, ct.maxmem || 1) + '</td>' +- '<td class="metric">' + formatBytes(ct.diskread) + '</td>' +- '<td class="metric">' + formatBytes(ct.diskwrite) + '</td>' +- '<td class="metric">' + formatBytes(ct.netin) + '</td>' +- '<td class="metric">' + formatBytes(ct.netout) + '</td>';+ const nameCell = document.createElement('td');+ const nameStrong = document.createElement('strong');+ nameStrong.textContent = ct.name || '';+ nameCell.appendChild(nameStrong);+ row.appendChild(nameCell);++ appendStatusCell(row, ct.status);+ appendCell(row, (ct.cpu ? ct.cpu.toFixed(1) : '0.0') + '%', 'metric');+ appendCell(row, formatMemory(ct.mem || 0, ct.maxmem || 1), 'metric');+ appendCell(row, formatBytes(ct.diskread), 'metric');+ appendCell(row, formatBytes(ct.diskwrite), 'metric');+ appendCell(row, formatBytes(ct.netin), 'metric');+ appendCell(row, formatBytes(ct.netout), 'metric');tbody.appendChild(row);});}diff --git a/internal/api/router_handlers_additional_test.go b/internal/api/router_handlers_additional_test.goindex 7a8d6ffae7..05ccc876b5 100644--- a/internal/api/router_handlers_additional_test.go+++ b/internal/api/router_handlers_additional_test.go@@ -82,7 +82,14 @@ func TestHandleSimpleStats(t *testing.T) {if ct := rec.Header().Get("Content-Type"); ct != "text/html; charset=utf-8" {t.Fatalf("expected text/html content type, got %q", ct)}- if !strings.Contains(rec.Body.String(), "Simple Pulse Stats") {- t.Fatalf("expected stats page HTML, got %q", rec.Body.String())+ body := rec.Body.String()+ if !strings.Contains(body, "Simple Pulse Stats") {+ t.Fatalf("expected stats page HTML, got %q", body)+ }+ if strings.Contains(body, "row.innerHTML") {+ t.Fatalf("simple stats page should not use row.innerHTML for container rendering")+ }+ if !strings.Contains(body, "textContent") {+ t.Fatalf("simple stats page should render container data with textContent")}}diff --git a/internal/securityutil/outbound_http.go b/internal/securityutil/outbound_http.goindex 2a3ba5b8ff..90057a398e 100644--- a/internal/securityutil/outbound_http.go+++ b/internal/securityutil/outbound_http.go@@ -47,6 +47,9 @@ func validateOutboundIP(ip net.IP, opts RestrictedOutboundHTTPOptions) error {if ip.IsLoopback() && !opts.AllowLoopback {return fmt.Errorf("loopback addresses are not allowed")}+ if ip.Equal(net.ParseIP("169.254.169.254")) {+ return fmt.Errorf("metadata service address is not allowed")+ }if ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {return fmt.Errorf("link-local addresses are not allowed")}@@ -56,9 +59,6 @@ func validateOutboundIP(ip net.IP, opts RestrictedOutboundHTTPOptions) error {if ip.IsUnspecified() {return fmt.Errorf("unspecified addresses are not allowed")}- if ip.Equal(net.ParseIP("169.254.169.254")) {- return fmt.Errorf("metadata service address is not allowed")- }if !opts.AllowPrivateIPs && ip.IsPrivate() {return fmt.Errorf("private addresses are not allowed")}