The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(router): redact cookies and preserve legacy classifier logs
moe-berric2176c786e0f
diff --git a/litellm/litellm_core_utils/sensitive_data_masker.py b/litellm/litellm_core_utils/sensitive_data_masker.pyindex 22dd4170963..b4c1beea33e 100644--- a/litellm/litellm_core_utils/sensitive_data_masker.py+++ b/litellm/litellm_core_utils/sensitive_data_masker.py@@ -15,6 +15,7 @@ _DEFAULT_SENSITIVE_PATTERNS: Final = frozenset("token","auth","authorization",+ "cookie","credential",# Plural form: Vertex uses ``vertex_credentials``; segment-exact# matching otherwise misses it because "credential" != "credentials".diff --git a/tests/test_litellm/litellm_core_utils/test_classifier_logging.py b/tests/test_litellm/litellm_core_utils/test_classifier_logging.pyindex c923225c750..ccf14ff06c7 100644--- a/tests/test_litellm/litellm_core_utils/test_classifier_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_classifier_logging.py@@ -33,6 +33,19 @@ def test_originating_snapshot_masks_nested_credentials_without_altering_source()assert body["metadata"]["nested"][0]["Authorization"] == "Bearer secret"[email protected]("header", ["Cookie", "cookie", "COOKIE", "sEt-CoOkIe"])+def test_originating_snapshot_redacts_cookie_headers_shared_with_caller_metadata(header: str) -> None:+ headers: Final = {header: "session=synthetic-session-credential", "content-type": "application/json"}+ body: Final = {"messages": [{"role": "user", "content": "hello"}], "metadata": {"headers": headers}}+ snapshot: Final = masked_originating_request({"proxy_server_request": {"body": body, "headers": headers}})+ assert snapshot == {+ "messages": [{"role": "user", "content": "hello"}],+ "metadata": {"headers": {header: "REDACTED", "content-type": "application/json"}},+ }+ assert headers[header] == "session=synthetic-session-credential"+ assert body["metadata"]["headers"][header] == "session=synthetic-session-credential"++@pytest.mark.parametrize("value", [None, "not-json", [], {"messages": object()}])def test_invalid_provider_payload_is_not_reported_as_captured(value: object) -> None:assert classifier_input_snapshot(value) is Nonediff --git a/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.py b/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.pyindex c8b6772d965..1551c3fd6e6 100644--- a/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.py+++ b/tests/test_litellm/litellm_core_utils/test_sensitive_data_masker.py@@ -358,7 +358,12 @@ def test_redact_credentials_in_payload_leaves_no_fragment_of_the_secret():"azure_ad_token": fake_token,"aws_secret_access_key": "fake-aws-secret-0000","vertex_credentials": {"private_key": "fake-pem"},- "extra_headers": {"Authorization": "Bearer fake-bearer-0000", "x-request-id": "abc123"},+ "extra_headers": {+ "Authorization": "Bearer fake-bearer-0000",+ "Cookie": "session=fake-session",+ "Set-Cookie": "session=fake-session; HttpOnly",+ "x-request-id": "abc123",+ },"model": "gpt-4o-mini","max_tokens": 17,"temperature": 0.25,@@ -373,6 +378,8 @@ def test_redact_credentials_in_payload_leaves_no_fragment_of_the_secret():assert "fake-bearer-0000" not in str(result)assert result["api_key"] == "REDACTED"assert result["extra_headers"]["Authorization"] == "REDACTED"+ assert result["extra_headers"]["Cookie"] == "REDACTED"+ assert result["extra_headers"]["Set-Cookie"] == "REDACTED"assert result["extra_headers"]["x-request-id"] == "abc123"assert result["model"] == "gpt-4o-mini"assert result["max_tokens"] == 17diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.jsonindex 76ac60a6453..e2a08a40bcb 100644--- a/ui/litellm-dashboard/eslint-suppressions.json+++ b/ui/litellm-dashboard/eslint-suppressions.json@@ -2325,11 +2325,6 @@"count": 4}},- "src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx": {- "no-nested-ternary": {- "count": 3- }- },"src/components/view_logs/LogDetailsDrawer/LogDetailsDrawer.tsx": {"no-nested-ternary": {"count": 2diff --git a/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.test.tsx b/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.integration.test.tsxsimilarity index 89%rename from ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.test.tsxrename to ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.integration.test.tsxindex e0d6a1d41e0..d538b16d6a2 100644--- a/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.test.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.integration.test.tsx@@ -272,6 +272,57 @@ describe("LogDetailContent", () => {expect(screen.queryByRole("tab", { name: "Request" })).not.toBeInTheDocument();});+ it.each(["object", "serialized", "messages only", "null captures"])(+ "preserves request inspection and copying for classifier logs with %s data",+ async (shape) => {+ const user = userEvent.setup();+ const messages = [{ role: "user", content: "legacy classifier prompt" }];+ const request = {+ messages,+ temperature: 0.5,+ ...(shape === "null captures" ? { classifier_input: null, originating_request_masked: null } : {}),+ };+ const storedRequest = shape === "serialized" ? JSON.stringify(request) : request;+ const logEntry: Partial<LogEntry> = {+ call_type: "acompletion",+ messages,+ proxy_server_request: shape === "messages only" ? undefined : storedRequest,+ metadata: { status: "success", internal_call_origin: "autorouter_classifier" },+ };+ render(<LogDetailContent logEntry={createLogEntry(logEntry)} />);++ expect(screen.getByText("legacy classifier prompt")).toBeInTheDocument();+ expect(screen.queryByRole("region", { name: "Classifier input" })).not.toBeInTheDocument();+ await user.click(screen.getByRole("tab", { name: "JSON", exact: true }));+ await user.click(screen.getByRole("button", { name: "Copy JSON", exact: true }));+ expect(await navigator.clipboard.readText()).toBe(+ JSON.stringify(shape === "messages only" ? messages : request, null, 2),+ );+ },+ );++ it.each(["classifier_input", "originating_request_masked"])(+ "shows partial classifier audits when only %s is captured",+ (field) => {+ render(+ <LogDetailContent+ logEntry={createLogEntry({+ call_type: "acompletion",+ proxy_server_request: JSON.stringify({+ [field]: { messages: [{ role: "user", content: "captured prompt" }] },+ }),+ metadata: { status: "success", internal_call_origin: "autorouter_classifier" },+ })}+ />,+ );++ expect(screen.getByRole("region", { name: "Classifier input" })).toBeInTheDocument();+ expect(screen.getByRole("region", { name: "Originating request, credentials masked" })).toBeInTheDocument();+ expect(screen.getByText("Not captured or message logging disabled")).toBeInTheDocument();+ expect(screen.queryByText("Request & Response")).not.toBeInTheDocument();+ },+ );+it("should display Request and Response tabs when JSON view is selected", async () => {const user = userEvent.setup();render(<LogDetailContent logEntry={createLogEntry()} />);diff --git a/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx b/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsxindex e29f2810926..69be5425ea1 100644--- a/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx+++ b/ui/litellm-dashboard/src/components/view_logs/LogDetailsDrawer/LogDetailContent.tsx@@ -73,6 +73,9 @@ export function LogDetailContent({ logEntry, isLoadingDetails = false, accessTokconst isClassifier =metadata.internal_call_origin === AUTOROUTER_CLASSIFIER_ORIGIN &&(logEntry.call_type === "completion" || logEntry.call_type === "acompletion");+ const rawRequest = formatData(logEntry.proxy_server_request || logEntry.messages);+ const hasClassifierAudit =+ isClassifier && (rawRequest?.classifier_input != null || rawRequest?.originating_request_masked != null);const hasMessages = checkHasMessages(logEntry.messages);const hasResponse = checkHasResponse(logEntry.response);@@ -93,10 +96,6 @@ export function LogDetailContent({ logEntry, isLoadingDetails = false, accessTok// Vector store dataconst hasVectorStoreData = checkHasVectorStoreData(metadata);- const getRawRequest = () => {- return formatData(logEntry.proxy_server_request || logEntry.messages);- };-const getFormattedResponse = () => {if (hasError && errorInfo) {return {@@ -202,14 +201,14 @@ export function LogDetailContent({ logEntry, isLoadingDetails = false, accessTok</div></div>) : null}- {!isLoadingDetails && isClassifier && (- <ClassifierAuditView request={getRawRequest()} response={getFormattedResponse()} />+ {!isLoadingDetails && hasClassifierAudit && (+ <ClassifierAuditView request={rawRequest} response={getFormattedResponse()} />)}- {!isLoadingDetails && !isClassifier && (+ {!isLoadingDetails && !hasClassifierAudit && (<RequestResponseSectionhasResponse={hasResponse}hasError={hasError}- getRawRequest={getRawRequest}+ getRawRequest={() => rawRequest}getFormattedResponse={getFormattedResponse}logEntry={logEntry}/>