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 critical P0 security and crash issues in API/WebSocket layer
rcourtman1bf9cfea88ce
diff --git a/internal/api/csrf_store.go b/internal/api/csrf_store.goindex 32a7ccc693..558c5926c2 100644--- a/internal/api/csrf_store.go+++ b/internal/api/csrf_store.go@@ -25,9 +25,11 @@ type CSRFToken struct {type CSRFTokenStore struct {tokens map[string]*CSRFTokenmu sync.RWMutex+ saveMu sync.Mutex // Serializes disk writes to prevent save corruptiondataPath stringsaveTicker *time.TickerstopChan chan bool+ stopOnce sync.Once // Ensures Stop() can only close channel once}func csrfSessionKey(sessionID string) string {@@ -99,9 +101,11 @@ func (c *CSRFTokenStore) backgroundWorker() {// Stop gracefully stops the CSRF storefunc (c *CSRFTokenStore) Stop() {- c.saveTicker.Stop()- c.stopChan <- true- c.save()+ c.stopOnce.Do(func() {+ c.saveTicker.Stop()+ close(c.stopChan) // Close instead of send to signal all readers+ c.save()+ })}// GenerateCSRFToken creates a new CSRF token for a session@@ -183,6 +187,10 @@ func (c *CSRFTokenStore) cleanup() {// save persists CSRF tokens to diskfunc (c *CSRFTokenStore) save() {+ // Serialize all disk writes to prevent corruption+ c.saveMu.Lock()+ defer c.saveMu.Unlock()+c.mu.RLock()defer c.mu.RUnlock()c.saveUnsafe()diff --git a/internal/api/recovery_tokens.go b/internal/api/recovery_tokens.goindex 16cee8693f..04a2069d86 100644--- a/internal/api/recovery_tokens.go+++ b/internal/api/recovery_tokens.go@@ -149,6 +149,15 @@ func (r *RecoveryTokenStore) ValidateRecoveryTokenConstantTime(providedToken str// Need to upgrade to write lock to mark as usedr.mu.RUnlock()r.mu.Lock()++ // CRITICAL: Re-check token.Used after acquiring write lock+ // Prevents replay attack where two concurrent requests both pass initial check+ if token.Used {+ r.mu.Unlock()+ r.mu.RLock()+ return false+ }+token.Used = truetoken.UsedAt = time.Now()token.IP = ipdiff --git a/internal/websocket/hub.go b/internal/websocket/hub.goindex 2a5198cc86..a538d1537e 100644--- a/internal/websocket/hub.go+++ b/internal/websocket/hub.go@@ -341,8 +341,12 @@ func (h *Hub) Run() {Data: map[string]string{"message": "Connected to Pulse WebSocket"},}if data, err := json.Marshal(welcomeMsg); err == nil {- // Check if client is still registered before sending- if _, ok := h.clients[client]; ok {+ // Check if client is still registered before sending (must hold lock)+ h.mu.RLock()+ _, stillRegistered := h.clients[client]+ h.mu.RUnlock()++ if stillRegistered {log.Info().Str("client", client.id).Msg("Sending welcome message")select {case client.send <- data:@@ -368,8 +372,12 @@ func (h *Hub) Run() {Data: sanitizeData(stateData),}if data, err := json.Marshal(initialMsg); err == nil {- // Check if client is still registered before sending- if _, ok := h.clients[client]; ok {+ // Check if client is still registered before sending (must hold lock)+ h.mu.RLock()+ _, stillRegistered := h.clients[client]+ h.mu.RUnlock()++ if stillRegistered {log.Info().Str("client", client.id).Int("dataLen", len(data)).Int("dataKB", len(data)/1024).Msg("Sending initial state to client")select {