8000 Paginate SV1 workers before dashboard aggregation · Issue #336 · stratum-mining/sv2-ui · GitHub
[go: up one dir, main page]

Skip to content

Paginate SV1 workers before dashboard aggregation #336

Closed as duplicate

Description

@lucasbalieiro

tracking https://github.com/project-loupe/audit-sv2-ui/issues/55


Finding

  • repo: stratum-mining/sv2-ui (https://github.com/stratum-mining/sv2-ui.git)
  • reviewed revision: b610455ac2d1e017c1df5db8787c0b2e505eabdc
  • title: Paginate SV1 workers before dashboard aggregation
  • severity: low
  • location: src/pages/UnifiedDashboard.tsx:121
  • scanner: llm-code-review
  • fingerprint: b0ec24b7c590e0bf00edf2003d3007076f20aee7e26ea713b0abf01023c51190

Description

UnifiedDashboard calls useSv1ClientsData(0, 1000) and treats the returned items array as the complete SV1 population for active-worker counts, total hashrate, search, and the worker table. The checked-in shared/openapi.json contract states that /api/v1/sv1/clients is paginated with a maximum page size of 100, and useSv1ClientsData performs only one request and never follows the response's total. Requesting 1,000 therefore does not make the snapshot complete: with 101 connected SV1 clients, only the first 100 are represented. A downstream peer able to establish many normal SV1 connections can place a connection beyond the first page, creating a monitoring blind spot and excluding its identity, telemetry, activity state, and hashrate from dashboard-derived values. The response's aggregate total can expose a count discrepancy in some modes, so this is conservatively low severity rather than a full stealth or authorization bypass. The fix should fetch successive bounded pages until items.length reaches total, with an explicit safety cap. Prior findings #13075 and #13079 were reviewed: they cover SV2-client and server-channel pagination respectively, not this SV1 endpoint. #13074 concerns negative telemetry and is also distinct. The PoC preserves the current one-request behavior behind a testable helper, then simulates the API's 100-record cap; it fails because the 101st client is never requested.

Proof of Concept

diff --git a/src/pages/UnifiedDashboard.tsx b/src/pages/UnifiedDashboard.tsx
--- a/src/pages/UnifiedDashboard.tsx
+++ b/src/pages/UnifiedDashboard.tsx
@@ -18,6 +18,6 @@
 import {
   usePoolData,
-  useSv1ClientsData,
+  useAllSv1ClientsData,
   useTranslatorServerChannels,
   useTranslatorHealth,
   useJdcHealth,
@@ -118,7 +118,7 @@
   const {
     data: sv1Data,
     isLoading: sv1Loading,
-  } = useSv1ClientsData(0, 1000);
+  } = useAllSv1ClientsData();
 
   // Health checks for the error banner (React Query deduplicates the API calls)
   const { data: translatorOk, isLoading: translatorHealthLoading, isError: translatorHealthError } = useTranslatorHealth();
diff --git a/src/hooks/usePoolData.ts b/src/hooks/usePoolData.ts
--- a/src/hooks/usePoolData.ts
+++ b/src/hooks/usePoolData.ts
@@ -223,8 +223,36 @@
     },
     refetchInterval: 3000,
     enabled,
   });
 }
+
+/**
+ * Fetch the complete SV1 client snapshot used by the dashboard.
+ *
+ * This extraction intentionally preserves the dashboard's current single
+ * oversized request so the regression test below exercises HEAD behavior.
+ */
+export async function fetchAllSv1Clients(baseUrl: string): Promise<Sv1ClientsResponse> {
+  const response = await fetch(
+    baseUrl + '/sv1/clients?offset=0&limit=1000',
+    { signal: AbortSignal.timeout(5000) },
+  );
+  if (!response.ok) {
+    throw new Error('HTTP ' + response.status);
+  }
+  return response.json() as Promise<Sv1ClientsResponse>;
+}
+
+export function useAllSv1ClientsData(enabled = true) {
+  const endpoints = getEndpointsCached();
+
+  return useQuery({
+    queryKey: ['sv1-clients', 'all'],
+    queryFn: () => fetchAllSv1Clients(endpoints.translator.base),
+    refetchInterval: 3000,
+    enabled,
+  });
+}
 
 /**
  * Hook to fetch Translator upstream channels.
diff --git a/src/hooks/usePoolData.sv1-pagination.test.ts b/src/hooks/usePoolData.sv1-pagination.test.ts
new file mode 100644
--- /dev/null
+++ b/src/hooks/usePoolData.sv1-pagination.test.ts
@@ -0,0 +1,56 @@
+import assert from 'node:assert/strict';
+import test from 'node:test';
+
+import { fetchAllSv1Clients } from './usePoolData.js';
+
+test('dashboard SV1 snapshot follows pagination through the advertised total', async () => {
+  const originalFetch = globalThis.fetch;
+  const requestedOffsets: number[] = [];
+  const firstPage = Array.from({ length: 100 }, (_, client_id) => ({ client_id }));
+
+  globalThis.fetch = (async (input: RequestInfo | URL) => {
+    const url = new URL(String(input), 'http://dashboard.test');
+    const offset = Number(url.searchParams.get('offset'));
+    requestedOffsets.push(offset);
+
+    let body: unknown;
+    if (offset === 0) {
+      // The monitoring contract caps every page at 100 even if the caller
+      // asks for 1000. A total of 101 therefore requires a second request.
+      body = {
+        offset: 0,
+        limit: 100,
+        total: 101,
+        items: firstPage,
+      };
+    } else if (offset === 100) {
+      body = {
+        offset: 100,
+        limit: 100,
+        total: 101,
+        items: [{ client_id: 100 }],
+      };
+    } else {
+      throw new Error('unexpected offset: ' + offset);
+    }
+
+    return new Response(JSON.stringify(body), {
+      status: 200,
+      headers: { 'Content-Type': 'application/json' },
+    });
+  }) as typeof globalThis.fetch;
+
+  try {
+    const snapshot = await fetchAllSv1Clients('/translator-api/v1');
+
+    assert.equal(snapshot.total, 101);
+    assert.equal(
+      snapshot.items.length,
+      snapshot.total,
+      'all clients advertised by total must be represented in the dashboard snapshot',
+    );
+    assert.deepEqual(requestedOffsets, [0, 100]);
+  } finally {
+    globalThis.fetch = originalFetch;
+  }
+});

Suggested Fix

diff --git a/src/pages/UnifiedDashboard.tsx b/src/pages/UnifiedDashboard.tsx
--- a/src/pages/UnifiedDashboard.tsx
+++ b/src/pages/UnifiedDashboard.tsx
@@ -18,7 +18,7 @@
 import {
   usePoolData,
-  useSv1ClientsData,
+  useAllSv1ClientsData,
   useTranslatorServerChannels,
   useTranslatorHealth,
   useJdcHealth,
 } from '@/hooks/usePoolData';
@@ -118,7 +118,7 @@ export function UnifiedDashboard() {
   const {
     data: sv1Data,
     isLoading: sv1Loading,
-  } = useSv1ClientsData(0, 1000);
+  } = useAllSv1ClientsData();
 
   // Health checks for the error banner (React Query deduplicates the API calls)
   const { data: translatorOk, isLoading: translatorHealthLoading, isError: translatorHealthError } = useTranslatorHealth();
diff --git a/src/hooks/usePoolData.ts b/src/hooks/usePoolData.ts
--- a/src/hooks/usePoolData.ts
+++ b/src/hooks/usePoolData.ts
@@ -225,6 +225,49 @@ export function useSv1ClientsData(offset = 0, limit = 25, enabled = true) {
     enabled,
   });
 }
+
+const SV1_CLIENTS_PAGE_LIMIT = 100;
+const SV1_CLIENTS_MAX_ITEMS = 1000;
+
+/**
+ * Fetch the bounded SV1 client snapshot used by the dashboard.
+ */
+export async function fetchAllSv1Clients(baseUrl: string): Promise<Sv1ClientsResponse> {
+  const firstPage = await fetchWithTimeout<Sv1ClientsResponse>(
+    `${baseUrl}/sv1/clients?offset=0&limit=${SV1_CLIENTS_PAGE_LIMIT}`
+  );
+  const cappedTotal = Math.min(firstPage.total, SV1_CLIENTS_MAX_ITEMS);
+  const items = firstPage.items.slice(0, cappedTotal);
+  let page = firstPage;
+  let offset = firstPage.offset + firstPage.items.length;
+
+  while (items.length < cappedTotal && page.items.length > 0) {
+    page = await fetchWithTimeout<Sv1ClientsResponse>(
+      `${baseUrl}/sv1/clients?offset=${offset}&limit=${SV1_CLIENTS_PAGE_LIMIT}`
+    );
+    items.push(...page.items.slice(0, cappedTotal - items.length));
+    offset = page.offset + page.items.length;
+  }
+
+  return {
+    ...firstPage,
+    items,
+  };
+}
+
+/**
+ * Hook to fetch the bounded SV1 client snapshot used by the dashboard.
+ */
+export function useAllSv1ClientsData(enabled = true) {
+  const endpoints = getEndpointsCached();
+
+  return useQuery({
+    queryKey: ['sv1-clients', 'all'],
+    queryFn: () => fetchAllSv1Clients(endpoints.translator.base),
+    refetchInterval: 3000,
+    enabled,
+  });
+}
 
 /**
  * Hook to fetch Translator upstream channels.

Related issues and PRs

This finding was discovered by Project Loupe.

Activity

  1. added
    area:dashboard
    and removed on Oct 14, 2026
  2. GitGab19 commented on Oct 14, 2026

    @GitGab19
    Member

    Closed as a duplicate of #330, which now lists this issue's Loupe finding and keeps its export in a collapsible block. The fix lands there.

  3. added
    duplicate
    on Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:dashboardduplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0