From 9568d5de4f287bcc51b856ddbf10d7504cb26a62 Mon Sep 17 00:00:00 2001 From: Sameer Kankute Date: Mon, 9 Mar 2026 16:05:31 +0530 Subject: [PATCH] address greptile review feedback (greploop iteration 1) - Fix XSS: add _html_safe_json() to escape <, >, &, ' for safe script embedding - Remove duplicate /ui/mcp/oauth/callback route from discoverable_endpoints - Add test_mcp_oauth_callback_html_xss_safe; update callback tests for _build_mcp_oauth_callback_html Made-with: Cursor --- .../mcp_server/discoverable_endpoints.py | 39 ++++++++---------- .../mcp_server/test_discoverable_endpoints.py | 41 +++++++++++++------ 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py b/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py index e9ec8de83dd..2b36577f2d9 100644 --- a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py +++ b/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py @@ -420,6 +420,20 @@ async def callback(code: str, state: str): ) +def _html_safe_json(value: object) -> str: + """ + JSON-serialize a value for safe embedding inside HTML ', + state="normal_state", + ) + + # Payload must be escaped: < -> \u003c, > -> \u003e (safe for + assert '\\u003c/script\\u003e' in body + assert '\\u003cimg' in body +