From 624a78fd5d29dd30a513e170689c39f583f19c05 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Mon, 23 Nov 2026 09:54:17 -0600 Subject: [PATCH] fix(logging): keep tool-call arguments out of failed request logs (#22635) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents call connected tools, such as Gmail, Google Drive and Google Docs, through the tool gateway > - The HTTP logger writes the request body for every response with status 400 or higher > - The logger removes only keys with credential names, so tool arguments stay in the log > - Tool calls often return 4xx for normal outcomes, such as 409 when an action needs approval > - So email recipients, email bodies and document text go into server logs > - This pull request removes the request body from the logs of the tool-call routes > - The benefit is that user content from connected accounts does not go into log storage ## Linked Issues or Issue Description Refs #22010 (stored connection data). No existing issue; the issue is described here. **What happened?** A failed or held tool call wrote its arguments to the server log. For example, a Gmail draft that waited for approval (HTTP 409) logged the recipients and the full message body. **What did you expect to happen?** The log keeps the route, the status and the error. The log does not keep the tool arguments. **Steps to reproduce** 1. Start an HTTP logger with the default redaction. 2. Send `POST /api/tool-gateway/tools/call` with tool parameters, and make the route answer with 409. 3. Read the log line. The `reqBody` field contains the parameters. ## What Changed - Add `isPrivateToolCallHttpRequest` in `server/src/middleware/http-log-policy.ts`. It matches these routes: - `/api/tool-gateway/tools/call` - `/api/tool-gateway/gateways/:gatewayId/mcp` - `/mcp/gateways/:gatewayPublicId` - `/mcp/native-runs/:runId` - `/mcp/runtime-tools` - `/mcp/runner` - `/api/mcp/project-tools` - `/api/issues/:issueId/mcp-app-views/:viewId/tool-calls` - `/api/tool-connections/:connectionId/test-calls` - In `server/src/middleware/logger.ts`, set `reqBody` to `[REDACTED]` for these routes when the status is 400 or higher. The log keeps the route path, the parameters and the redacted error context. - Add tests in `server/src/__tests__/http-log-redaction.test.ts` for statuses 400, 403, 409, 429 and 500, and a test that other routes keep their body. ## Verification - Red: the new test failed for all 5 statuses before the fix. The log contained the canary recipient, body and document text. - Green: `npx vitest run src/__tests__/http-log-redaction.test.ts src/__tests__/sentry.test.ts` (from `server/`): 2 files passed, 114 tests passed. - `pnpm verify` selected 2,977 of 3,852 test files (full-suite scope), so required CI supplies broad coverage. `tsc --noEmit` for `server` passed. ## Risks - Low risk. The change affects only log output for the five tool-call routes. - Failed tool calls no longer show their arguments in the log. To debug a call, use the tool invocation record, which stores a redacted summary. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, in Claude Code with tool use (shell, file edit, test runs). ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 --- .../src/__tests__/http-log-redaction.test.ts | 49 +++++++++++++++++++ server/src/middleware/http-log-policy.ts | 18 +++++++ server/src/middleware/logger.ts | 9 +++- 3 files changed, 74 insertions(+), 2 deletions(-) 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 (