diff --git a/server/src/__tests__/http-log-redaction.test.ts b/server/src/__tests__/http-log-redaction.test.ts index 15a738ee89b..dfc81a2f8f6 100644 --- a/server/src/__tests__/http-log-redaction.test.ts +++ b/server/src/__tests__/http-log-redaction.test.ts @@ -649,6 +649,55 @@ describe("HTTP logger redaction", () => { expect(log.reqQuery).toBeUndefined(); }); + it.each([400, 403, 409, 429, 500])("keeps tool-call arguments out of %i logs", async status => { + const canaries = ["recipient-canary@example.com", "mail-body-canary", "doc-text-canary"]; + const chunks: string[] = []; + const stream = new Writable({ write(chunk, _encoding, callback) { chunks.push(chunk.toString()); callback(); } }); + const app = express(); + app.use(express.json()); + app.use(createHttpLogger(pino({ redact: [...HTTP_LOG_REDACT_PATHS] }, stream))); + app.use((_req, _res, next) => next(new HttpError(status, "Tool call failed"))); + app.use(errorHandler); + const paths = [ + "/api/tool-gateway/tools/call", + "/api/tool-gateway/gateways/gateway-1/mcp", + "/mcp/gateways/public-gateway-1", + "/mcp/native-runs/run-1", + "/mcp/runtime-tools", + "/mcp/runner", + "/api/mcp/project-tools", + "/api/issues/issue-1/mcp-app-views/view-1/tool-calls", + "/api/tool-connections/connection-1/test-calls", + "/API/Tool-Gateway/Tools/Call/", + ]; + for (const path of paths) { + const response = await request(app).post(path).send({ + toolName: "gmail.create_draft", + parameters: { to: [canaries[0]], body: canaries[1] }, + params: { arguments: { text: canaries[2] } }, + }); + expect(response.status).toBe(status); + } + const output = chunks.join(""); + for (const canary of canaries) expect(output).not.toContain(canary); + const logs = chunks.flatMap(chunk => chunk.trim().split("\n").filter(Boolean).map(line => JSON.parse(line))); + expect(logs).toHaveLength(paths.length); + for (const log of logs) expect(log.reqBody).toBe("[REDACTED]"); + }); + + it("keeps request bodies on other failed routes", async () => { + const chunks: string[] = []; + const stream = new Writable({ write(chunk, _encoding, callback) { chunks.push(chunk.toString()); callback(); } }); + const app = express(); + app.use(express.json()); + app.use(createHttpLogger(pino({ redact: [...HTTP_LOG_REDACT_PATHS] }, stream))); + app.use((_req, _res, next) => next(new HttpError(409, "Conflict"))); + app.use(errorHandler); + await request(app).post("/api/tool-gateway/sessions").send({ agentId: "agent-1" }); + const log = JSON.parse(chunks.join("").trim()) as { reqBody: unknown }; + expect(log.reqBody).toEqual({ agentId: "agent-1" }); + }); + it("redacts failed secret payload values from structured request logs", async () => { const chunks: string[] = []; const stream = new Writable({ diff --git a/server/src/middleware/http-log-policy.ts b/server/src/middleware/http-log-policy.ts index 40f97425a94..63ae4b7f3c4 100644 --- a/server/src/middleware/http-log-policy.ts +++ b/server/src/middleware/http-log-policy.ts @@ -74,6 +74,24 @@ export function isPrivateAgentCommentaryHttpRequest(url: string | undefined): bo return /^\/api\/companies\/[^/]+\/agent-commentary(?:\/|$)/i.test(pathname); } +const TOOL_CALL_HTTP_PATHS = [ + /^\/api\/tool-gateway\/tools\/call\/?$/i, + /^\/api\/tool-gateway\/gateways\/[^/]+\/mcp\/?$/i, + /^\/mcp\/gateways\/[^/]+\/?$/i, + /^\/mcp\/native-runs\/[^/]+\/?$/i, + /^\/mcp\/runtime-tools\/?$/i, + /^\/mcp\/runner\/?$/i, + /^\/api\/mcp\/project-tools\/?$/i, + /^\/api\/issues\/[^/]+\/mcp-app-views\/[^/]+\/tool-calls\/?$/i, + /^\/api\/tool-connections\/[^/]+\/test-calls\/?$/i, +]; + +export function isPrivateToolCallHttpRequest(url: string | undefined): boolean { + if (!url) return false; + const pathname = normalizePath(url).replace(/^https?:\/\/[^/]*/i, ""); + return TOOL_CALL_HTTP_PATHS.some((pattern) => pattern.test(pathname)); +} + /** Destination credentials stay private even on malformed settings requests. */ export function isPrivateAgentObservabilityHttpRequest(url: string | undefined): boolean { if (!url) return false; diff --git a/server/src/middleware/logger.ts b/server/src/middleware/logger.ts index dcf545bb707..d874058c4a6 100644 --- a/server/src/middleware/logger.ts +++ b/server/src/middleware/logger.ts @@ -10,6 +10,7 @@ import { isPrivateAgentObservabilityHttpRequest, isPrivateMuseHttpRequest, isPrivateDotPrincipalHttpRequest, + isPrivateToolCallHttpRequest, shouldSilenceHttpSuccessLog, } from "./http-log-policy.js"; import { @@ -213,6 +214,7 @@ export function createHttpLogger(baseLogger: Logger) { : {}), }; } + const toolCall = isPrivateToolCallHttpRequest(requestClassificationUrl(req)); if (ctx) { const secretSensitiveRoute = isSecretSensitiveHttpRequest( req.method, @@ -225,13 +227,16 @@ export function createHttpLogger(baseLogger: Logger) { errorContext: secretSensitiveRoute ? { name: "Error" } : redactSensitive(ctx.error), - reqBody: redactSensitive(ctx.reqBody), + reqBody: toolCall ? "[REDACTED]" : redactSensitive(ctx.reqBody), reqParams: redactSensitive(ctx.reqParams), + ...(toolCall && (req as any).route?.path ? { routePath: (req as any).route.path } : {}), }; } const props: Record = {}; const { body, params } = req as any; - if (body && typeof body === "object" && Object.keys(body).length > 0) { + if (toolCall) { + props.reqBody = "[REDACTED]"; + } else if (body && typeof body === "object" && Object.keys(body).length > 0) { props.reqBody = redactSensitive(body); } if (