🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(api): stop logging public API request payloads (#15399)
Hassieb Pakzadcc1a56078363
diff --git a/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.ts b/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.tsindex 262de905db..901882a51d 100644--- a/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.ts+++ b/web/src/__tests__/server/unit/create-authed-project-api-route-auth-errors.servertest.ts@@ -7,6 +7,7 @@ const {mockIsPrismaException,mockRateLimitRequest,mockTraceException,+ mockLoggerDebug,mockCreateUnstablePublicApiAuthError,mockSendUnstablePublicApiErrorResponse,} = vi.hoisted(() => ({@@ -14,6 +15,7 @@ const {mockIsPrismaException: vi.fn(),mockRateLimitRequest: vi.fn(),mockTraceException: vi.fn(),+ mockLoggerDebug: vi.fn(),mockCreateUnstablePublicApiAuthError: vi.fn((value) => value),mockSendUnstablePublicApiErrorResponse: vi.fn(),}));@@ -31,7 +33,7 @@ vi.mock("@langfuse/shared/src/db", () => ({vi.mock("@langfuse/shared/src/server", () => ({redis: null,logger: {- debug: vi.fn(),+ debug: mockLoggerDebug,info: vi.fn(),warn: vi.fn(),error: vi.fn(),@@ -245,6 +247,43 @@ describe("createAuthedProjectAPIRoute auth error handling", () => {});});+ it("does not include request query or body data in debug logs", async () => {+ mockVerifyAuthHeaderAndReturnScope.mockResolvedValueOnce(validAuth);++ const handler = createAuthedProjectAPIRoute({+ name: "Sensitive Route",+ querySchema: z.object({ token: z.string() }),+ bodySchema: z.object({+ secretKey: z.string(),+ extraHeaders: z.record(z.string(), z.string()),+ }),+ responseSchema: z.object({ ok: z.literal(true) }),+ fn: async () => ({ ok: true as const }),+ });+ const { req, res } = createMocks<NextApiRequest, NextApiResponse>({+ method: "PUT",+ headers: {+ authorization: "Basic test",+ },+ query: {+ token: "SENTINEL_QUERY_TOKEN",+ },+ body: {+ secretKey: "SENTINEL_SECRET_KEY",+ extraHeaders: {+ Authorization: "Bearer SENTINEL_HEADER_TOKEN",+ },+ },+ });++ await handler(req, res);++ expect(res.statusCode).toBe(200);+ expect(mockLoggerDebug).toHaveBeenCalledExactlyOnceWith(+ "Request to route Sensitive Route projectId project-1",+ );+ });+it("throws a 422 payload error when response serialization exceeds V8 string limits", async () => {mockVerifyAuthHeaderAndReturnScope.mockResolvedValueOnce(validAuth);diff --git a/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts b/web/src/features/public-api/server/createAuthedProjectAPIRoute.tsindex 9f8eaaa9d6..2d5594e123 100644--- a/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts+++ b/web/src/features/public-api/server/createAuthedProjectAPIRoute.ts@@ -86,11 +86,6 @@ export type AuthedProjectAPIRouteConfig<* events_only mode and would silently return stale or empty data.*/rejectInEventsOnlyMode?: boolean;- /**- * Redact or summarize the request body before logging. Use this for routes- * accepting user-authored content, secrets, or other sensitive payloads.- */- redactLogBody?: (body: unknown) => unknown;/** Stamps a top-level `_deprecation` object onto responses (LFE-10895). */deprecation?: ApiDeprecationInfo;fn: (params: {@@ -405,12 +400,6 @@ export const createAuthedProjectAPIRoute = <logger.debug(`Request to route ${routeConfig.name} projectId ${auth.scope.projectId}`,- {- query: req.query,- body: routeConfig.redactLogBody- ? routeConfig.redactLogBody(req.body)- : req.body,- },);let query: z.infer<TQuery>;diff --git a/web/src/pages/api/public/feedback.ts b/web/src/pages/api/public/feedback.tsindex 6faaab3817..964a6b49a0 100644--- a/web/src/pages/api/public/feedback.ts+++ b/web/src/pages/api/public/feedback.ts@@ -12,17 +12,6 @@ export default withMiddlewares({bodySchema: PostFeedbackBody,responseSchema: PostFeedbackResponse,successStatusCode: 201,- redactLogBody: (body) => {- const candidate =- typeof body === "object" && body !== null- ? (body as {- targetType?: unknown;- })- : {};- return {- targetType: candidate.targetType,- };- },fn: async ({ body, auth }) =>await submitFeedback({input: body,