You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf_hooks: Histogram.DoImport reads SharedArrayBuffer-backed data without copying (TOCTOU) #67152
HistogramImpl::DoImport in src/histogram.cc accepts a Uint8Array and reads the underlying buffer directly during CBOR parsing. When the Uint8Array is backed by a SharedArrayBuffer, a concurrent Worker thread can mutate the buffer while parsing is in progress, causing a time-of-check/time-of-use (TOCTOU) race.
Affected code
src/histogram.cc — HistogramImpl::DoImport (around line 3202):
Local<Uint8Array> input = args[0].As<Uint8Array>();
auto backing = input->Buffer()->GetBackingStore();
constuint8_t* data =
static_cast<constuint8_t*>(backing->Data()) + input->ByteOffset();
size_t len = input->ByteLength();
// ← no IsSharedArrayBuffer() checkauto histogram = Histogram::Import(data, len); // reads data during multi-step CBOR parse
There is no check for input->Buffer()->IsSharedArrayBuffer(). The CBOR parser in Histogram::Import performs multi-step parsing over data without any snapshot or copy.
Scenario
// Worker A — triggers importHistogram with a SAB-backed viewconstsab=newSharedArrayBuffer(exportedBytes.length);constview=newUint8Array(sab);view.set(exportedBytes);// SAB is shared with Worker B via workerData or postMessageimportHistogram(view);// Worker A starts CBOR parse// Worker B — running concurrentlyconstview2=newUint8Array(sab);// same SABview2[criticalOffset]=0xff;// mutates header field mid-parse
The perf_hooks worker-import pattern in handleMetricsImportWorker-style code already uses this exact shape: the server creates a SAB, copies request data into it, and passes it to a Worker. If the main thread or another Worker modifies the SAB while the Worker is inside importHistogram, the CBOR parser sees inconsistent data.
Existing precedent
src/node_buffer.cc lines 587–592 already handles this case for Buffer.toString():
Copy SAB-backed data to a local buffer before passing to Histogram::Import, matching the node_buffer.cc pattern. This eliminates the race without changing behavior for normal (non-SAB) Uint8Array inputs.
Severity
Low. Exploitation requires the caller to intentionally share a SAB with the histogram import thread and mutate it during parsing. This is not remotely triggerable without cooperation from same-process JavaScript. It is a defense-in-depth hardening, not a CVE-eligible vulnerability.
Activity