diff --git a/CHANGELOG.md b/CHANGELOG.md index 964fc3f..1c3f8ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The application version is maintained in `package.json` and displayed in the adm ## Unreleased +### Security + +- The server no longer decompresses request bodies (`Content-Encoding: br`, `gzip`, `deflate` get 415). The app never sends compressed bodies, but Express decompressed them for anyone who could reach the port, before the admin PIN check and also on `/public-training`. That ran Node's Brotli decoder on untrusted input (CVE-2026-111497). Upgrading Node.js to 22.23.4 / 24.22.1 / 26.12.1 or later is still needed: the server's own `fetch()` calls (voice downloads, public IP lookup) decompress Brotli responses. + ### Added - **Overlay → a driver's training stats in one click.** In RaceCore's own Overlay a click on a driver opens Training stats for that driver and class; the stand-alone overlay window stays up and opens them in a new tab. The public overlay has no links, since the driver's mobile profile link is personal and can also write. diff --git a/server.js b/server.js index ad7b05b..ecaf9ef 100644 --- a/server.js +++ b/server.js @@ -136,7 +136,9 @@ const allowedCorsOrigins = new Set( .filter(Boolean) ); -app.use(express.json({ limit: "20mb" })); +// inflate: false - the app never sends compressed bodies. Decompressing them ran Node's Brotli/zlib +// decoders on input from anyone who can reach the port, before the PIN check (CVE-2026-111497). +app.use(express.json({ limit: "20mb", inflate: false })); app.use((req, res, next) => { res.setHeader("X-Content-Type-Options", "nosniff"); res.setHeader("Referrer-Policy", "no-referrer"); diff --git a/tests/server_persistence.integration.test.js b/tests/server_persistence.integration.test.js index b5c47ea..1d50686 100644 --- a/tests/server_persistence.integration.test.js +++ b/tests/server_persistence.integration.test.js @@ -660,3 +660,31 @@ process.stdin.on("end", () => { fs.appendFileSync(${JSON.stringify(counter)}, "x rmSync(dataDir, { recursive: true, force: true }); } }); + +test("compressed request bodies are refused before anything is decompressed (CVE-2026-111497, Brotli)", { timeout: 20000 }, async () => { + const { brotliCompressSync, gzipSync } = await import("node:zlib"); + const dataDir = mkdtempSync(join(tmpdir(), "live-rc-test-encoding-")); + const port = await reservePort(); + const baseUrl = `http://127.0.0.1:${port}`; + const child = spawn(process.execPath, [join(projectRoot, "server.js")], { + cwd: projectRoot, + env: { ...process.env, HOST: "127.0.0.1", PORT: String(port), RC_TIMING_DATA_DIR: dataDir, RC_TIMING_PID_FILE: "" }, + stdio: ["ignore", "pipe", "pipe"], + }); + const json = JSON.stringify({ classes: [{ id: "compressed", name: "Compressed" }] }); + const post = (path, encoding, body) => fetch(`${baseUrl}${path}`, { method: "POST", headers: { "Content-Type": "application/json", "Content-Encoding": encoding }, body }); + try { + await waitForServer(child); + // The app never sends compressed bodies; decompressing one ran Node's Brotli decoder for + // anyone who could reach the port - before the admin PIN check, also on /public-training. + assert.equal((await post("/api/state", "br", brotliCompressSync(json))).status, 415, "Brotli body refused"); + assert.equal((await post("/api/state", "gzip", gzipSync(json))).status, 415, "gzip body refused too"); + assert.equal((await post("/public-training/api/abcdefghijklmnopqrstuvwxyz0123/markers", "br", brotliCompressSync("{}"))).status, 415, "the public profile API too"); + const state = await (await fetch(`${baseUrl}/api/state`)).json(); + assert.ok(!JSON.stringify(state).includes("Compressed"), "nothing was stored"); + assert.equal((await post("/api/state", "identity", json)).status, 200, "plain JSON still works"); + } finally { + await stopServer(child); + rmSync(dataDir, { recursive: true, force: true }); + } +});