mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 23:06:17 +01:00
fix(local): keep the operator token out of logs and sign only real loopback addresses
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6578e6848e
commit
755b620f88
5 files changed
+19
-3
No files matched your search
@@ -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/);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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"];
|
||||
|
||||
@@ -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"]',
|
||||
|
||||
@@ -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");
|
||||
}));
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user