fix(security): refuse compressed request bodies
express.json decompressed Content-Encoding br/gzip/deflate bodies before the PIN check, running Node's Brotli decoder on input from anyone who can reach the port (CVE-2026-111497). The app never sends compressed bodies, so they now get 415.
This commit is contained in:
1 parent
4def444202
commit
3f7f62bfa8
3 files changed
+35
-1
No files matched your search
@@ -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 });
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user