diff --git a/docs/notes/claude-session-recovery-2026-11-07.md b/docs/notes/claude-session-recovery-2026-11-07.md index 5069cf0c..96eaaaa6 100644 --- a/docs/notes/claude-session-recovery-2026-11-07.md +++ b/docs/notes/claude-session-recovery-2026-11-07.md @@ -44,3 +44,12 @@ No physical-device verification or installation was performed. PDF external handlers and media playback are not claimed as verified on physical devices. Deployment receipts belong in the installation's private rollback directory; source integration, checks, installed runtime and APK publication are separate. + +Live delivery verification caught an omitted authenticated web-proxy route: +`/files?path=...` returned the SPA instead of file bytes. `web/serve.mjs` now +forwards the exact `/files` path after authentication, retaining query strings, +Range requests, HEAD and response disposition. A proxy integration regression +in `web/test/serve.test.mjs` verifies sign-in enforcement and forwarding; +`node --test web/test/*.test.mjs` passes all five proxy tests. The existing +`npm test --prefix web` directory invocation fails on this Node 22 setup; +explicit test-file selection is the verified command. diff --git a/web/serve.mjs b/web/serve.mjs index b8ea1b6d..3faa8aca 100644 --- a/web/serve.mjs +++ b/web/serve.mjs @@ -4,7 +4,7 @@ // [--root DIR] [--updates DIR] // // Serves the app (--root, default ../app/build/web) and proxies /connect, -// /artifacts/ and /chat-uploads to the Pipelines server, so the page, the +// /artifacts/, /files and /chat-uploads to the Pipelines server, so the page, the // WebSocket and artifact files share one origin. --updates serves the Android // app's update feed at /updates/. // @@ -449,7 +449,7 @@ const server = createServer(async (req, res) => { return; } } - if (pathname.startsWith("/artifacts/")) { + if (pathname.startsWith("/artifacts/") || pathname === "/files") { proxyArtifact(req, res); return; } @@ -566,7 +566,7 @@ const host = flag(process.argv, "--host", "127.0.0.1"); server.listen(port, host, () => { const shown = host === "0.0.0.0" ? "127.0.0.1" : host; console.log(`web spike: http://${shown}:${port}/ (bound ${host}:${port})`); - console.log(`proxying /connect (ws) and /artifacts/ (http) -> ${targetHost}:${targetPort}`); + console.log(`proxying /connect (ws), /artifacts/ and /files (http) -> ${targetHost}:${targetPort}`); console.log(auth ? "auth: sign-in required" : "auth: DISABLED (tests)"); console.log(`serving ${ROOT}${UPDATES ? `; app updates from ${UPDATES}` : ""}`); }); diff --git a/web/test/serve.test.mjs b/web/test/serve.test.mjs index f5e7ebd3..f08e9f3f 100644 --- a/web/test/serve.test.mjs +++ b/web/test/serve.test.mjs @@ -6,6 +6,8 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; import net from "node:net"; +import { createServer } from "node:http"; +import { once } from "node:events"; const here = fileURLToPath(new URL("..", import.meta.url)); @@ -89,3 +91,51 @@ test("icons and the manifest need no sign-in; the app does", async (t) => { assert.equal((await fetch(`${base}/main.dart.js`)).status, 401); assert.equal((await fetch(`${base}/icons/../main.dart.js`)).status, 401); }); + +test("files require sign-in and proxy query, ranges and attachment headers", async (t) => { + const requests = []; + const upstream = createServer((req, res) => { + requests.push({ method: req.method, url: req.url, range: req.headers.range }); + res.writeHead(req.headers.range ? 206 : 200, { + "Content-Type": "application/octet-stream", + "Content-Disposition": 'attachment; filename="report.bin"', + "Accept-Ranges": "bytes", + ...(req.headers.range ? { "Content-Range": "bytes 0-2/6" } : {}), + }); + res.end(req.headers.range ? "abc" : "abcdef"); + }).listen(0, "127.0.0.1"); + await once(upstream, "listening"); + t.after(() => new Promise((done) => upstream.close(done))); + const dir = await mkdtemp(join(tmpdir(), "serve-files-")); + const auth = join(dir, "auth.json"); + await writeFile(auth, JSON.stringify({ password: "password-1", secret: "s".repeat(40) })); + const port = await freePort(); + const child = spawn(process.execPath, ["serve.mjs", "--port", String(port), + "--pipelines", `127.0.0.1:${upstream.address().port}`], { + cwd: here, + env: { ...process.env, PIPELINES_WEB_AUTH: "", PIPELINES_WEB_AUTH_FILE: auth }, + stdio: ["ignore", "pipe", "inherit"], + }); + t.after(async () => { const exited = once(child, "exit"); child.kill(); await exited; }); + await once(child.stdout, "data"); + const base = `http://127.0.0.1:${port}`; + const path = "/files?path=%2Fhome%2Freport%20one.bin&download=1"; + assert.equal((await fetch(base + path)).status, 401); + assert.equal(requests.length, 0); + const login = await fetch(base + "/login", { + method: "POST", body: new URLSearchParams({ password: "password-1" }), redirect: "manual", + }); + const cookie = login.headers.get("set-cookie").split(";")[0]; + const reply = await fetch(base + path, { headers: { Cookie: cookie, Range: "bytes=0-2" } }); + assert.equal(reply.status, 206); + assert.equal(await reply.text(), "abc"); + assert.equal(reply.headers.get("content-disposition"), 'attachment; filename="report.bin"'); + assert.equal(reply.headers.get("content-range"), "bytes 0-2/6"); + const head = await fetch(base + path, { method: "HEAD", headers: { Cookie: cookie } }); + assert.equal(head.status, 200); + assert.equal(await head.text(), ""); + assert.deepEqual(requests, [ + { method: "GET", url: path, range: "bytes=0-2" }, + { method: "HEAD", url: path, range: undefined }, + ]); +});