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: SSE race conditions, alert user spoofing, and security status oracle
rcourtman12a5a98117cc
diff --git a/internal/api/alerts.go b/internal/api/alerts.goindex 5432a854cc..3c1fb7fbbb 100644--- a/internal/api/alerts.go+++ b/internal/api/alerts.go@@ -671,8 +671,11 @@ func (h *AlertHandlers) AcknowledgeAlert(w http.ResponseWriter, r *http.Request)Str("path", r.URL.Path).Msg("Attempting to acknowledge alert")- // In a real implementation, you'd get the user from authentication- user := "admin"+ // Get the authenticated user from the auth middleware (set in X-Authenticated-User header)+ user := w.Header().Get("X-Authenticated-User")+ if user == "" {+ user = "unknown" // Fallback if auth header not set (shouldn't happen in normal flow)+ }log.Debug().Str("alertID", alertID).@@ -739,7 +742,11 @@ func (h *AlertHandlers) AcknowledgeAlertByBody(w http.ResponseWriter, r *http.Rereturn}- user := "admin"+ // Get the authenticated user from the auth middleware (set in X-Authenticated-User header)+ user := w.Header().Get("X-Authenticated-User")+ if user == "" {+ user = "unknown" // Fallback if auth header not set (shouldn't happen in normal flow)+ }if err := h.getMonitor(r.Context()).GetAlertManager().AcknowledgeAlert(alertID, user); err != nil {log.Error().Err(err).Str("alertID", alertID).Msg("Failed to acknowledge alert")@@ -926,9 +933,10 @@ func (h *AlertHandlers) BulkAcknowledgeAlerts(w http.ResponseWriter, r *http.Reqreturn}- user := request.User+ // Get the authenticated user from the auth middleware - ignore request.User to prevent spoofing+ user := w.Header().Get("X-Authenticated-User")if user == "" {- user = "admin"+ user = "unknown" // Fallback if auth header not set (shouldn't happen in normal flow)}var (diff --git a/internal/api/router.go b/internal/api/router.goindex 72d922d0c9..dd8b4d996f 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -653,6 +653,10 @@ func (r *Router) setupRoutes() {// Determine whether the caller is authenticated before exposing sensitive fields// Also track token scopes for kiosk/limited-access scenarios+ //+ // SECURITY: Do NOT check ?token= query param here - this public endpoint would+ // act as a token validity oracle, allowing attackers to probe for valid tokens+ // without rate limiting. Only check session cookies and X-API-Token header.isAuthenticated := falsevar tokenScopes []stringif cookie, err := req.Cookie("pulse_session"); err == nil && cookie.Value != "" && ValidateSession(cookie.Value) {@@ -662,12 +666,6 @@ func (r *Router) setupRoutes() {isAuthenticated = truetokenScopes = record.Scopes}- } else if token := req.URL.Query().Get("token"); token != "" {- // Also check URL query param (used for kiosk mode)- if record, ok := r.config.ValidateAPIToken(token); ok {- isAuthenticated = true- tokenScopes = record.Scopes- }}// Create token hint if token exists (only revealed to authenticated callers)diff --git a/internal/updates/sse.go b/internal/updates/sse.goindex ae1efbb99f..023b71002a 100644--- a/internal/updates/sse.go+++ b/internal/updates/sse.go@@ -17,6 +17,7 @@ type SSEClient struct {Flusher http.FlusherDone chan boolLastActive time.Time+ mu sync.Mutex // protects writes to Writer and Flusher}// SSEBroadcaster manages Server-Sent Events connections for update progress@@ -175,6 +176,17 @@ func (b *SSEBroadcaster) sendToClient(client *SSEClient, status UpdateStatus) {// Format: data: {json}\n\nmessage := fmt.Sprintf("data: %s\n\n", string(data))+ // Acquire client lock to prevent concurrent writes+ client.mu.Lock()+ defer client.mu.Unlock()++ // Double-check client is not disconnected while waiting for lock+ select {+ case <-client.Done:+ return+ default:+ }+defer func() {if r := recover(); r != nil {log.Warn().@@ -212,8 +224,13 @@ func (b *SSEBroadcaster) cleanupLoop() {idsToRemove := make([]string, 0)for id, client := range b.clients {+ // Acquire client lock to safely read LastActive (written by sendToClient/SendHeartbeat)+ client.mu.Lock()+ inactive := now.Sub(client.LastActive) > 5*time.Minute+ client.mu.Unlock()+// Remove clients inactive for more than 5 minutes- if now.Sub(client.LastActive) > 5*time.Minute {+ if inactive {idsToRemove = append(idsToRemove, id)}}@@ -249,6 +266,17 @@ func (b *SSEBroadcaster) SendHeartbeat() {default:}+ // Acquire client lock to prevent concurrent writes+ c.mu.Lock()+ defer c.mu.Unlock()++ // Double-check client is not disconnected while waiting for lock+ select {+ case <-c.Done:+ return+ default:+ }+defer func() {if r := recover(); r != nil {b.RemoveClient(c.ID)@@ -262,6 +290,8 @@ func (b *SSEBroadcaster) SendHeartbeat() {return}c.Flusher.Flush()+ // Update LastActive so cleanup loop doesn't prune active clients+ c.LastActive = time.Now()}(client)}}