Repository navigation
Description
Affected layers
- Frontend (
src/): affected.getNiceYAxisScaleinsrc/components/data/HashrateChart.tsxadvances its tick loop witht += stepand stops oncetpasses the top of the range. Whenstepis smaller than half the distance betweentand the next representable double, the addition returnstunchanged and the loop never advances. Rendering the chart on main with the samples 100000000000000 and 100000000000000.02 pushes the same tick until the array can no longer grow: on Node 22 that takes 2.3 s and 2.2 GB and ends in aRangeError. A browser blocks its main thread for that long and then either fails the render, with no error boundary to catch it, or runs out of memory. The samples come fromuseHashrateHistory, which records the dashboard total every 5 seconds and keeps an hour of it in localStorage. The total is a sum of values taken from sv2-apps:reported_hashrate_hs, a double reported by the miner's management interface, and thehashrate,total_hashrateandnominal_hashrateestimates, all accepted whenever finite. - Backend (
server/): not affected. Charts are computed in the browser only. shared/: not affected.
Problem
The scale derives a nice step from the spread between the smallest and largest charted sample. Two samples one floating-point unit apart, 0.0156 H/s at 100 TH/s or 0.00012 H/s at 1 TH/s, give a step too small to change the value it is added to. Every iteration then pushes a tick, and the loop only stops when the browser cannot allocate more. The chart is rendered on every dashboard render, so the freeze starts as soon as both samples are in the charted window.
Impact
The operator loses the dashboard page, not the mining service. A malicious or compromised miner inside the telemetry range can alternate two adjacent values across polls; when it is the only source that varies, the totals differ by one unit as well. Once both totals are in the charted window the page freezes, and because the history is persisted, a reload replays it and freezes again until the samples age out of the selected range or storage is cleared. Severity medium, since only dashboard availability is affected.
Expected outcome
- The chart renders in bounded time for any finite samples, including two that differ by one floating-point unit, or by nothing, at any magnitude.
- For ordinary data the axis keeps a handful of evenly spaced ticks that cover the sample range, as today.
- A regression test covers the adjacent-samples case. The samples are sums of monitoring fields, so the fixture can state the
reported_hashrate_hsvalues that produce them, asdocs/monitoring-api-compatibility.mdasks.
Possible approach (non-binding)
Compute each tick from its index, niceMin + i * step for a fixed small number of ticks, instead of accumulating, or stop as soon as the addition no longer changes t, as the Loupe suggestion does, and cap the tick count either way. Exporting getNiceYAxisScale allows a plain unit test on the tick list. A test that goes through the component cannot catch a hang in process; the Loupe PoC renders it in a child process with a timeout, and src/components/data/ContainerLogsPanel.test.tsx shows the react-dom/server setup for rendering a component under node:test.
Loupe findings
- project-loupe/audit-sv2-ui#44: the tick loop never checks that
t += stepadvanced (reported as dashboard: the hashrate chart renders in bounded time for any finite samples #344)
Related issues and PRs
- dashboard: a negative hashrate never enters the dashboard totals #342 removes negative totals from the same chart input.
- Tracker: [Tracker] Dashboard metrics #373.
Loupe export for #344 (finding #44)
Finding
- repo:
stratum-mining/sv2-ui(https://github.com/stratum-mining/sv2-ui.git) - reviewed revision:
b610455ac2d1e017c1df5db8787c0b2e505eabdc - title: Non-progressing Y-axis tick loop freezes the dashboard
- severity:
medium - location:
src/components/data/HashrateChart.tsx:57-60 - cwe: CWE-835
- scanner:
llm-code-review - fingerprint:
19f8775e9c250518f0be0740dc0455124ed6f2212a218265febf25459d72f507
Description
getNiceYAxisScale advances its tick loop with t += step but never verifies that the addition changes t. IEEE-754 spacing makes that false for sufficiently large values with a very narrow range. For example, [100000000000000, 100000000000000.02] produces niceMin = 100000000000000 and step = 0.005; adding that step rounds back to niceMin, while the loop condition remains true forever. Rendering the component therefore blocks the browser's main thread.
These values can reach the chart through the normal dashboard flow: monitoring API/miner telemetry numbers are accepted when finite, sampled by useHashrateHistory, and passed to HashrateChart. A malicious or compromised telemetry-producing miner can alternate the two JSON numbers across samples. Once both are present, viewing the dashboard freezes; the history is also written to localStorage, so reloads can retrigger the freeze until the points expire or storage is cleared. This is limited to operator-dashboard availability, so it is rated medium rather than high.
The PoC invokes the real component in a child process and fails when the synchronous render exceeds two seconds, avoiding hanging the test runner itself. Prior search HashrateChart getNiceYAxisScale infinite loop floating point returned no matches.
Proof of Concept
diff --git a/src/components/data/HashrateChart.test.ts b/src/components/data/HashrateChart.test.ts
new file mode 100644
--- /dev/null
+++ b/src/components/data/HashrateChart.test.ts
@@ -0,0 +1,30 @@
+import assert from 'node:assert/strict';
+import { spawnSync } from 'node:child_process';
+import test from 'node:test';
+
+test('HashrateChart terminates for adjacent high-magnitude values', () => {
+ const script = `
+ const { HashrateChart } = await import('./src/components/data/HashrateChart.tsx');
+ HashrateChart({
+ data: [
+ { time: '00:00', hashrate: 100000000000000 },
+ { time: '00:05', hashrate: 100000000000000.02 },
+ ],
+ });
+ `;
+
+ // Run the render in a child because the vulnerable tick loop blocks its
+ // event loop and cannot be interrupted by node:test's in-process timeout.
+ const result = spawnSync(
+ process.execPath,
+ ['--import', 'tsx', '--input-type=module', '--eval', script],
+ {
+ cwd: process.cwd(),
+ encoding: 'utf8',
+ timeout: 2_000,
+ },
+ );
+
+ assert.equal(result.error?.code, undefined, 'chart calculation timed out');
+ assert.equal(result.status, 0, result.stderr || result.error?.message);
+});
Suggested Fix
diff --git a/src/components/data/HashrateChart.tsx b/src/components/data/HashrateChart.tsx
index 618d1ad..b26b9b8 100644
--- a/src/components/data/HashrateChart.tsx
+++ b/src/components/data/HashrateChart.tsx
@@ -53,8 +53,11 @@ function getNiceYAxisScale(values: number[]): {
const niceMax = Math.ceil(rawMax / step) * step;
const ticks: number[] = [];
- for (let t = niceMin; t <= niceMax + step * 0.01; t += step) {
+ for (let t = niceMin; t <= niceMax + step * 0.01;) {
ticks.push(Math.round(t * 1e10) / 1e10); // strip float noise
+ const next = t + step;
+ if (next === t) break;
+ t = next;
}
return { domain: [niceMin, niceMax], ticks };
This finding was discovered by Project Loupe.
Activity
[-]Non-progressing Y-axis tick loop freezes the dashboard[/-][+]dashboard: the hashrate chart renders in bounded time for any finite samples[/+]