Compare commits

..

1 Commits

Author SHA1 Message Date
Claude Bot
7f57c9c747 fix(debugger): use crypto.randomUUID() for WebSocket auth token
Replace Math.random().toString(36) with crypto.randomUUID() for generating
the debugger WebSocket path token. Math.random() is not cryptographically
secure and produces predictable output, making it possible for local
attackers to guess the token and connect to the debugger via Chrome DevTools
Protocol. This is the same class of vulnerability as Node.js CVE-2018-7160.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-12 04:44:25 +00:00
5 changed files with 2 additions and 48 deletions

View File

@@ -591,7 +591,7 @@ function parseUrl(input: string): URL {
}
function randomId() {
return Math.random().toString(36).slice(2);
return crypto.randomUUID();
}
const { enableANSIColors } = Bun;

View File

@@ -34,11 +34,6 @@ pub fn main() void {
// This should appear before we make any calls at all to libuv.
// So it's safest to put it very early in the main function.
if (Environment.isWindows) {
// Set the Windows timer resolution to 1ms. Without this, the default
// resolution is ~15.6ms which causes timers like setInterval(fn, 16)
// to fire at ~28ms intervals instead of ~16ms. (See #26965)
_ = _bun.windows.timeBeginPeriod(1);
_ = _bun.windows.libuv.uv_replace_allocator(
&_bun.mimalloc.mi_malloc,
&_bun.mimalloc.mi_realloc,

View File

@@ -86,9 +86,6 @@ pub const WPathBuffer = if (Environment.isWindows) bun.WPathBuffer else void;
pub const HANDLE = win32.HANDLE;
pub const HMODULE = win32.HMODULE;
/// https://learn.microsoft.com/en-us/windows/win32/api/timeapi/nf-timeapi-timebeginperiod
pub extern "winmm" fn timeBeginPeriod(uPeriod: UINT) callconv(.winapi) UINT;
/// https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfileinformationbyhandle
pub extern "kernel32" fn GetFileInformationByHandle(
hFile: HANDLE,

View File

@@ -9,7 +9,7 @@ import { InspectorSession, JUnitReporter, connect } from "./junit-reporter";
import { SocketFramer } from "./socket-framer";
let inspectee: Subprocess;
const anyPort = expect.stringMatching(/^\d+$/);
const anyPathname = expect.stringMatching(/^\/[a-z0-9]+$/);
const anyPathname = expect.stringMatching(/^\/[a-f0-9-]+$/);
/**
* Get a function that creates a random `.sock` file in the specified temporary directory.

View File

@@ -1,38 +0,0 @@
import { expect, test } from "bun:test";
// https://github.com/oven-sh/bun/issues/26965
// setInterval(fn, 16) fires with ~28ms intervals on Windows instead of ~16ms
// due to the default Windows timer resolution being ~15.6ms.
// The fix calls timeBeginPeriod(1) at startup to set 1ms resolution.
test("setInterval fires at approximately the requested interval", async () => {
const interval = 16;
const count = 50;
const times: number[] = [];
let last = performance.now();
await new Promise<void>(resolve => {
let i = 0;
const id = setInterval(() => {
const now = performance.now();
times.push(now - last);
last = now;
i++;
if (i >= count) {
clearInterval(id);
resolve();
}
}, interval);
});
// Drop the first few measurements as they can be noisy during startup
const stable = times.slice(5);
const avg = stable.reduce((a, b) => a + b, 0) / stable.length;
// The average interval should be close to the requested 16ms.
// Before the fix on Windows, this was ~28ms (nearly 2x).
// Allow up to 22ms to account for normal scheduling jitter,
// but catch the ~28ms+ intervals caused by 15.6ms timer resolution.
expect(avg).toBeLessThan(22);
expect(avg).toBeGreaterThan(10);
});