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.

Require monitoring scope for socket.io

rcourtman8951b6f7f9ca
diff --git a/internal/api/router.go b/internal/api/router.go
index 731587c1f1..29ed0c9e53 100644
--- a/internal/api/router.go
+++ b/internal/api/router.go
@@ -6580,6 +6580,10 @@ func (r *Router) handleSocketIO(w http.ResponseWriter, req *http.Request) {
if !CheckAuth(r.config, w, req) {
return
}
+ // SECURITY: Ensure monitoring:read scope for socket.io connections
+ if !ensureScope(w, req, config.ScopeMonitoringRead) {
+ return
+ }
// For socket.io.js, redirect to CDN
if strings.Contains(req.URL.Path, "socket.io.js") {
http.Redirect(w, req, "https://cdn.socket.io/4.8.1/socket.io.min.js", http.StatusFound)
diff --git a/internal/api/security_regression_test.go b/internal/api/security_regression_test.go
index eb2537bec5..899b777401 100644
--- a/internal/api/security_regression_test.go
+++ b/internal/api/security_regression_test.go
@@ -170,6 +170,24 @@ func TestSocketIORequiresAuthInAPIMode(t *testing.T) {
}
}
+func TestSocketIORequiresMonitoringReadScope(t *testing.T) {
+ rawToken := "socket-scope-token-123.12345678"
+ record := newTokenRecord(t, rawToken, []string{config.ScopeSettingsRead}, nil)
+ cfg := newTestConfigWithTokens(t, record)
+ router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")
+
+ req := httptest.NewRequest(http.MethodGet, "/socket.io/?transport=polling", nil)
+ req.Header.Set("X-API-Token", rawToken)
+ rec := httptest.NewRecorder()
+ router.Handler().ServeHTTP(rec, req)
+ if rec.Code != http.StatusForbidden {
+ t.Fatalf("expected 403 for missing monitoring:read scope, got %d", rec.Code)
+ }
+ if !strings.Contains(rec.Body.String(), config.ScopeMonitoringRead) {
+ t.Fatalf("expected missing scope response to mention %q, got %q", config.ScopeMonitoringRead, rec.Body.String())
+ }
+}
+
func TestSocketIOJSRequiresAuth(t *testing.T) {
rawToken := "socket-js-token-123.12345678"
record := newTokenRecord(t, rawToken, []string{config.ScopeMonitoringRead}, nil)