diff --git a/cli/src/__tests__/open.test.ts b/cli/src/__tests__/open.test.ts index dd4ce02e22a..5222d3e0d16 100644 --- a/cli/src/__tests__/open.test.ts +++ b/cli/src/__tests__/open.test.ts @@ -22,6 +22,8 @@ describe("paperclipai open", () => { it("refuses to sign in to a Paperclip that is not on this computer", () => { expect(() => buildLocalBoardSignInUrl("https://paperclip.example.com", "/nonexistent/key")).toThrow(/not local/); + expect(() => buildLocalBoardSignInUrl("http://127.attacker.example:3100", "/nonexistent/key")).toThrow(/not local/); + expect(() => buildLocalBoardSignInUrl("http://localhost.attacker.example:3100", "/nonexistent/key")).toThrow(/not local/); }); }); diff --git a/cli/src/commands/open.ts b/cli/src/commands/open.ts index c6fc7131fe2..26cf6765061 100644 --- a/cli/src/commands/open.ts +++ b/cli/src/commands/open.ts @@ -1,3 +1,4 @@ +import { isIPv4 } from "node:net"; import path from "node:path"; import type { Command } from "commander"; import pc from "picocolors"; @@ -22,7 +23,8 @@ interface OpenOptions { function isLoopbackBase(apiBase: string): boolean { try { const host = new URL(apiBase).hostname.replace(/^\[|\]$/g, "").toLowerCase(); - return host === "localhost" || host === "::1" || host.startsWith("127."); + if (host === "localhost" || host === "::1") return true; + return isIPv4(host) && host.split(".")[0] === "127"; } catch { return false; } diff --git a/server/src/__tests__/http-log-redaction.test.ts b/server/src/__tests__/http-log-redaction.test.ts index 15a738ee89b..86ffe52eb53 100644 --- a/server/src/__tests__/http-log-redaction.test.ts +++ b/server/src/__tests__/http-log-redaction.test.ts @@ -21,6 +21,16 @@ it("redacts a routine caller run token on ordinary HTTP routes", async () => { expect(chunks.join("")).not.toContain("private-routine-caller-token"); }); +it("redacts the local board page's operator token", async () => { + const chunks: string[] = []; + const stream = new Writable({ write(chunk, _encoding, callback) { chunks.push(chunk.toString()); callback(); } }); + const app = express(); + app.use(createHttpLogger(pino({ redact: [...HTTP_LOG_REDACT_PATHS] }, stream))); + app.get("/api/health", (_req, res) => res.json({ ok: true })); + await request(app).get("/api/health").set("X-Paperclip-Local-Operator", "private-local-operator-token"); + expect(chunks.join("")).not.toContain("private-local-operator-token"); +}); + describe("HTTP logger redaction", () => { it.each([200, 400, 500])("keeps connector and observability credentials out of %i logs", async status => { const canaries = ["configuration-canary", "signing-canary", "client-canary", "bot-canary", "oauth-code-canary", "provider-echo-canary"]; diff --git a/server/src/middleware/http-log-redaction.ts b/server/src/middleware/http-log-redaction.ts index 88750f8d120..41d5a4cb9cb 100644 --- a/server/src/middleware/http-log-redaction.ts +++ b/server/src/middleware/http-log-redaction.ts @@ -12,6 +12,8 @@ export const HTTP_LOG_REDACT_PATHS = [ 'req.headers["x-csrf-token"]', 'req.headers["x-xsrf-token"]', 'req.headers["x-api-key"]', + // The local board page's operator token grants board access. + 'req.headers["x-paperclip-local-operator"]', // Cloud proxy credentials and signed assertions authorize tenant access. 'req.headers["x-paperclip-cloud-tenant-token"]', 'req.headers["x-paperclip-cloud-session-id"]', diff --git a/server/src/realtime/live-events-ws.ts b/server/src/realtime/live-events-ws.ts index 5fc1cb92685..89aa3595594 100644 --- a/server/src/realtime/live-events-ws.ts +++ b/server/src/realtime/live-events-ws.ts @@ -445,7 +445,7 @@ export function setupLiveEventsWebSocketServer( } const onRawSocketError = (err: Error) => { - logger.warn({ err, path: req.url }, "live websocket upgrade socket error"); + logger.warn({ err, path: req.url?.split("?")[0] }, "live websocket upgrade socket error"); }; const cleanupRawSocketListeners = () => { socket.off("error", onRawSocketError); @@ -494,7 +494,7 @@ export function setupLiveEventsWebSocketServer( }); }) .catch((err) => { - logger.error({ err, path: req.url }, "failed websocket upgrade authorization"); + logger.error({ err, path: req.url?.split("?")[0] }, "failed websocket upgrade authorization"); rejectUpgrade(socket, "500 Internal Server Error", "upgrade failed"); })); });