From f23c8e5cd1d890c309e661b8d139b222b13fc787 Mon Sep 17 00:00:00 2001 From: Artur Wierzbicki Date: Thu, 9 Mar 2023 10:01:44 +0400 Subject: [PATCH] Chore: move `sessionId` from Live service (#64465) * remove sessionid from live * remove sessionid from live * use uuid rather than math.random --- .betterer.results | 6 ++---- public/app/features/live/centrifuge/service.ts | 1 - public/app/features/live/dashboard/dashboardWatcher.ts | 6 +++++- public/app/features/live/index.ts | 8 -------- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/.betterer.results b/.betterer.results index ec5f720494e..9ffb427a6de 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1,5 +1,5 @@ // BETTERER RESULTS V2. -// +// // If this file contains merge conflicts, use `betterer merge` to automatically resolve them: // https://phenomnomnominal.github.io/betterer/docs/results-file/#merge // @@ -3675,9 +3675,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/features/live/index.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"] + [0, 0, 0, "Do not use any type assertions.", "0"] ], "public/app/features/live/pages/AddNewRule.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] diff --git a/public/app/features/live/centrifuge/service.ts b/public/app/features/live/centrifuge/service.ts index 41042f10e8b..affb722ac9e 100644 --- a/public/app/features/live/centrifuge/service.ts +++ b/public/app/features/live/centrifuge/service.ts @@ -29,7 +29,6 @@ export type CentrifugeSrvDeps = { appUrl: string; orgId: number; orgRole: string; - sessionId: string; liveEnabled: boolean; dataStreamSubscriberReadiness: Observable; }; diff --git a/public/app/features/live/dashboard/dashboardWatcher.ts b/public/app/features/live/dashboard/dashboardWatcher.ts index e7cccd2b721..3572a77011f 100644 --- a/public/app/features/live/dashboard/dashboardWatcher.ts +++ b/public/app/features/live/dashboard/dashboardWatcher.ts @@ -1,4 +1,5 @@ import { Unsubscribable } from 'rxjs'; +import { v4 as uuidv4 } from 'uuid'; import { AppEvents, @@ -11,7 +12,6 @@ import { } from '@grafana/data'; import { getGrafanaLiveSrv, locationService } from '@grafana/runtime'; import { appEvents, contextSrv } from 'app/core/core'; -import { sessionId } from 'app/features/live'; import { ShowModalReactEvent } from '../../../types/events'; import { getDashboardSrv } from '../../dashboard/services/DashboardSrv'; @@ -19,6 +19,10 @@ import { getDashboardSrv } from '../../dashboard/services/DashboardSrv'; import { DashboardChangedModal } from './DashboardChangedModal'; import { DashboardEvent, DashboardEventAction } from './types'; +// sessionId is not a security-sensitive value. +// It is used for filtering out dashboard edit events from the same browsing session +const sessionId = uuidv4(); + class DashboardWatcher { channel?: LiveChannelAddress; // path to the channel uid?: string; diff --git a/public/app/features/live/index.ts b/public/app/features/live/index.ts index 6e6ec497752..9b1c10e3573 100644 --- a/public/app/features/live/index.ts +++ b/public/app/features/live/index.ts @@ -8,20 +8,12 @@ import { CentrifugeService } from './centrifuge/service'; import { CentrifugeServiceWorkerProxy } from './centrifuge/serviceWorkerProxy'; import { GrafanaLiveService } from './live'; -export const sessionId = - (window as any)?.grafanaBootData?.user?.id + - '/' + - Date.now().toString(16) + - '/' + - Math.random().toString(36).substring(2, 15); - export function initGrafanaLive() { const centrifugeServiceDeps = { appUrl: `${window.location.origin}${config.appSubUrl}`, orgId: contextSrv.user.orgId, orgRole: contextSrv.user.orgRole, liveEnabled: config.liveEnabled, - sessionId, dataStreamSubscriberReadiness: liveTimer.ok.asObservable(), grafanaAuthToken: loadUrlToken(), };