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 notification queue persistence root
rcourtmanb398c9c405a2
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.mdindex 44d230d6fd..c5a12e2cc3 100644--- a/docs/release-control/v6/internal/subsystems/notifications.md+++ b/docs/release-control/v6/internal/subsystems/notifications.md@@ -123,6 +123,10 @@ That same delivery boundary also owns SMTP mailbox normalization. `From`,recipient, and `Reply-To` inputs must be parsed as canonical mailboxes beforeheaders or SMTP envelope commands are constructed, so notification deliverycannot treat raw config strings as header fragments or `RCPT TO` input.+That same queue ownership also governs persistent queue storage roots. The+notifications queue database must normalize its owned data directory and+resolve the fixed `notification_queue.db` leaf through the shared storage-path+helper instead of joining raw caller-provided directory strings.`internal/api/notifications.go` and`frontend-modern/src/api/notifications.ts` are shared boundaries withdiff --git a/internal/notifications/queue.go b/internal/notifications/queue.goindex 5afcfbe946..e4b0285091 100644--- a/internal/notifications/queue.go+++ b/internal/notifications/queue.go@@ -6,12 +6,12 @@ import ("fmt""net/url""os"- "path/filepath""strings""sync""time""github.com/rcourtman/pulse-go-rewrite/internal/alerts"+ "github.com/rcourtman/pulse-go-rewrite/internal/securityutil""github.com/rcourtman/pulse-go-rewrite/internal/utils""github.com/rs/zerolog/log"_ "modernc.org/sqlite"@@ -24,6 +24,8 @@ const defaultQueueMaxAttempts = 3const (notificationAuditAlertIdentifiersColumn = "alert_identifiers"legacyNotificationAuditAlertIdentifiersColumn = "alert_ids"+ notificationQueueDirName = "notifications"+ notificationQueueFileName = "notification_queue.db")// NotificationQueueStatus represents the status of a queued notification@@ -88,6 +90,29 @@ func queueSQLiteDSN(path string) string {}.Encode()}+func resolveNotificationQueuePath(dataDir string) (string, string, error) {+ normalizedDir := strings.TrimSpace(dataDir)+ if normalizedDir == "" {+ defaultDir, err := securityutil.JoinStorageLeaf(utils.GetDataDir(), notificationQueueDirName)+ if err != nil {+ return "", "", fmt.Errorf("resolve default notification queue dir: %w", err)+ }+ normalizedDir = defaultDir+ }++ normalizedDir, err := securityutil.NormalizeStorageDir(normalizedDir)+ if err != nil {+ return "", "", fmt.Errorf("normalize notification queue dir: %w", err)+ }++ dbPath, err := securityutil.JoinStorageLeaf(normalizedDir, notificationQueueFileName)+ if err != nil {+ return "", "", fmt.Errorf("resolve notification queue db path: %w", err)+ }++ return normalizedDir, dbPath, nil+}+func newNotificationQueueFromDSN(dbPath, dsn string) (*NotificationQueue, error) {db, err := sql.Open("sqlite", dsn)if err != nil {@@ -138,19 +163,17 @@ func newNotificationQueueFromDSN(dbPath, dsn string) (*NotificationQueue, error)// NewNotificationQueue creates a new persistent notification queue.func NewNotificationQueue(dataDir string) (*NotificationQueue, error) {- dataDir = strings.TrimSpace(dataDir)- if dataDir == "" {- dataDir = filepath.Join(utils.GetDataDir(), "notifications")+ resolvedDataDir, dbPath, err := resolveNotificationQueuePath(dataDir)+ if err != nil {+ return nil, err}- dataDir = filepath.Clean(dataDir)// Queue data includes alert payload/context and destination configuration;// keep it owner-only by default.- if err := os.MkdirAll(dataDir, 0700); err != nil {+ if err := os.MkdirAll(resolvedDataDir, 0700); err != nil {return nil, fmt.Errorf("failed to create notification queue directory: %w", err)}- dbPath := filepath.Join(dataDir, "notification_queue.db")return newNotificationQueueFromDSN(dbPath, queueSQLiteDSN(dbPath))}diff --git a/internal/notifications/queue_test.go b/internal/notifications/queue_test.goindex 2a7ebd7c60..067557cb0b 100644--- a/internal/notifications/queue_test.go+++ b/internal/notifications/queue_test.go@@ -97,12 +97,51 @@ func TestNewNotificationQueue_WhitespaceDataDirUsesDefault(t *testing.T) {}defer func() { _ = nq.Stop() }()- expectedDBPath := filepath.Join(utils.GetDataDir(), "notifications", "notification_queue.db")+ expectedDBPath := filepath.Join(utils.GetDataDir(), notificationQueueDirName, notificationQueueFileName)if nq.dbPath != expectedDBPath {t.Fatalf("expected db path %q, got %q", expectedDBPath, nq.dbPath)}}+func TestResolveNotificationQueuePathCanonicalizesExplicitDataDir(t *testing.T) {+ rawDataDir := filepath.Join(t.TempDir(), "queue", "..", "queue", ".")++ resolvedDir, dbPath, err := resolveNotificationQueuePath(rawDataDir)+ if err != nil {+ t.Fatalf("resolveNotificationQueuePath() error = %v", err)+ }++ expectedDir := filepath.Clean(rawDataDir)+ if resolvedDir != expectedDir {+ t.Fatalf("resolved dir = %q, want %q", resolvedDir, expectedDir)+ }++ expectedDBPath := filepath.Join(expectedDir, notificationQueueFileName)+ if dbPath != expectedDBPath {+ t.Fatalf("db path = %q, want %q", dbPath, expectedDBPath)+ }+}++func TestResolveNotificationQueuePathWhitespaceUsesDefaultNotificationsDir(t *testing.T) {+ dataDir := t.TempDir()+ t.Setenv("PULSE_DATA_DIR", dataDir)++ resolvedDir, dbPath, err := resolveNotificationQueuePath(" \t ")+ if err != nil {+ t.Fatalf("resolveNotificationQueuePath() error = %v", err)+ }++ expectedDir := filepath.Join(utils.GetDataDir(), notificationQueueDirName)+ if resolvedDir != expectedDir {+ t.Fatalf("resolved dir = %q, want %q", resolvedDir, expectedDir)+ }++ expectedDBPath := filepath.Join(expectedDir, notificationQueueFileName)+ if dbPath != expectedDBPath {+ t.Fatalf("db path = %q, want %q", dbPath, expectedDBPath)+ }+}+func TestEnqueue_ValidatesAndNormalizesInput(t *testing.T) {tempDir := t.TempDir()nq, err := NewNotificationQueue(tempDir)