OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
ralph(M30-003): F2: /live/organization leaks a cross-tenant identifier to a non-member
ralph20228bec1173
diff --git a/packages/core/src/modules/realtime/realtime.routes.test.ts b/packages/core/src/modules/realtime/realtime.routes.test.tsindex 07af282e5..1d5cb0c00 100644--- a/packages/core/src/modules/realtime/realtime.routes.test.ts+++ b/packages/core/src/modules/realtime/realtime.routes.test.ts@@ -51,7 +51,9 @@ const subscribeToProjectEventBatches = mock(const subscribeToProjectNotifications = mock(async () => () => undefined);const subscribeToOrganizationSubscriptionUpdates = mock(- async () => () => undefined+ async (_organizationId: string, _onUpdate: (message: unknown) => void) =>+ () =>+ undefined);let activeVisitorCount = 0;@@ -308,6 +310,34 @@ test('wsOrganizationEvents: session but no org access -> "No access" then close'});});+// M30-003 / F2: `organization:subscription_updated` is an instance-wide+// channel. Before the fix the open handler subscribed to it unscoped, so a+// member of org_1 was sent the `organizationId` of every OTHER organization+// whose subscription changed. The scope handed to the subscription must be the+// id `getOrganizationAccess` just proved this caller is a member of — the+// filter itself is asserted in realtime.service.test.ts.+test('wsOrganizationEvents: subscribes scoped to the organization the caller is a member of', async () => {+ session = { userId: 'user_1' };+ organizationAccess = { role: 'org:member' };++ const { ws } = await connect('/live/organization/org_1');++ while (subscribeToOrganizationSubscriptionUpdates.mock.calls.length === 0) {+ await new Promise((resolve) => setTimeout(resolve, 1));+ }++ expect(getOrganizationAccess).toHaveBeenCalledWith({+ userId: 'user_1',+ organizationId: 'org_1',+ });+ expect(subscribeToOrganizationSubscriptionUpdates).toHaveBeenCalledWith(+ 'org_1',+ expect.any(Function)+ );++ ws.close();+});+test('wsProjectNotifications: no session -> "No active session" then close', async () => {const { nextMessage, nextClose } = await connect('/live/notifications/proj_1'diff --git a/packages/core/src/modules/realtime/realtime.routes.ts b/packages/core/src/modules/realtime/realtime.routes.tsindex 34a6f24a8..deb7a9e2b 100644--- a/packages/core/src/modules/realtime/realtime.routes.ts+++ b/packages/core/src/modules/realtime/realtime.routes.ts@@ -179,9 +179,15 @@ export const realtimeRoutes = defineRoutes((app) =>rememberUnsubscribe(ws,- await subscribeToOrganizationSubscriptionUpdates((message) => {- ws.send(setSuperJson(message));- })+ // `organizationId` only reaches the subscription once+ // `getOrganizationAccess` has proved this caller is a member of it,+ // so the scope is the caller's own membership, not their input.+ await subscribeToOrganizationSubscriptionUpdates(+ organizationId,+ (message) => {+ ws.send(setSuperJson(message));+ }+ ));},close(ws) {diff --git a/packages/core/src/modules/realtime/realtime.service.test.ts b/packages/core/src/modules/realtime/realtime.service.test.tsindex 2048fa9bb..8397277a7 100644--- a/packages/core/src/modules/realtime/realtime.service.test.ts+++ b/packages/core/src/modules/realtime/realtime.service.test.ts@@ -156,15 +156,23 @@ test('subscribeToProjectNotifications subscribes on notification:created and filexpect(onNotification).toHaveBeenCalledTimes(1);});-test('subscribeToOrganizationSubscriptionUpdates subscribes on organization:subscription_updated, unfiltered', async () => {+// M30-003 / F2: the `organization:subscription_updated` channel is+// instance-wide. Unfiltered, a subscriber saw the `organizationId` of every+// organization whose subscription changed — including ones it is not a+// member of. This test is red without the filter.+test('subscribeToOrganizationSubscriptionUpdates subscribes on organization:subscription_updated and filters by organizationId', async () => {const onUpdate = mock((_message: unknown) => undefined);- await subject.subscribeToOrganizationSubscriptionUpdates(onUpdate);+ await subject.subscribeToOrganizationSubscriptionUpdates('org_1', onUpdate);const [channel, type, callback] = subscribeToPublishedEvent.mock.calls[0]!;expect(channel).toBe('organization');expect(type).toBe('subscription_updated');+ (callback as (event: unknown) => void)({ organizationId: 'org_other' });+ expect(onUpdate).not.toHaveBeenCalled();+(callback as (event: unknown) => void)({ organizationId: 'org_1' });+ expect(onUpdate).toHaveBeenCalledTimes(1);expect(onUpdate).toHaveBeenCalledWith({ organizationId: 'org_1' });});diff --git a/packages/core/src/modules/realtime/realtime.service.ts b/packages/core/src/modules/realtime/realtime.service.tsindex a20de0353..3207a19d9 100644--- a/packages/core/src/modules/realtime/realtime.service.ts+++ b/packages/core/src/modules/realtime/realtime.service.ts@@ -523,8 +523,18 @@ export async function subscribeToProjectNotifications();}-/** V1: `wsOrganizationEvents` — every subscriber, no per-org filter (V1 has none either). */+/**+ * V1: `wsOrganizationEvents`. Scoped to the single organization the caller's+ * membership was verified against, exactly as the three siblings above scope+ * to a verified `projectId`.+ *+ * The channel is instance-wide: without this filter every subscriber saw the+ * `organizationId` of every organization whose subscription changed, which is+ * a cross-tenant identifier leak (M30-003 / F2). V1 had no filter either —+ * this is a deliberate divergence, approved 2026-09-15.+ */export async function subscribeToOrganizationSubscriptionUpdates(+ organizationId: string,onUpdate: (message: IPublishChannels['organization']['subscription_updated']) => void@@ -532,7 +542,11 @@ export async function subscribeToOrganizationSubscriptionUpdates(return subscribeToPublishedEvent('organization','subscription_updated',- onUpdate+ (message) => {+ if (message.organizationId === organizationId) {+ onUpdate(message);+ }+ });}