diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index a52e763ea14..27132c90e05 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -645,7 +645,6 @@ from litellm.proxy.utils import ( _is_valid_team_configs, evict_config_param, get_config_param, - get_cookie_path_from_server_root_path, get_custom_url, get_error_message_str, get_server_root_path, diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.test.ts b/ui/litellm-dashboard/src/utils/cookieUtils.test.ts index a6f39b96996..1810f59f66d 100644 --- a/ui/litellm-dashboard/src/utils/cookieUtils.test.ts +++ b/ui/litellm-dashboard/src/utils/cookieUtils.test.ts @@ -142,6 +142,20 @@ describe("cookieUtils", () => { vi.restoreAllMocks(); }); + it("should clear token cookie at the server root path when the root path contains a /ui segment", () => { + const originalLocation = window.location; + vi.stubGlobal("location", { ...originalLocation, pathname: "/foo/ui/bar/ui/" }); + + const cookieSpy = vi.spyOn(document, "cookie", "set"); + + clearTokenCookies(); + + expect(cookieSpy).toHaveBeenCalledWith(expect.stringContaining("path=/foo/ui/bar;")); + + vi.unstubAllGlobals(); + vi.restoreAllMocks(); + }); + it("should clear sessionStorage token", () => { sessionStorage.setItem("token", "stored-token"); clearTokenCookies(); diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts index d4b2c6a2490..f8466257220 100644 --- a/ui/litellm-dashboard/src/utils/cookieUtils.ts +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -14,9 +14,12 @@ function getUiCookiePath(): string { if (typeof window === "undefined") return "/ui"; // Match "/ui" only as a full path segment (followed by "/" or end of string) // to avoid false matches like "/my-ui-tool/login" → "/my-ui". - const match = window.location.pathname.match(/\/ui(?=\/|$)/); - if (match && match.index !== undefined) { - return window.location.pathname.substring(0, match.index + 3); + // The UI mounts at the last "/ui" segment (SERVER_ROOT_PATH + "/ui"), so use the + // last match to stay correct when the root path itself contains a "/ui" segment. + const matches = [...window.location.pathname.matchAll(/\/ui(?=\/|$)/g)]; + const lastMatch = matches[matches.length - 1]; + if (lastMatch && lastMatch.index !== undefined) { + return window.location.pathname.substring(0, lastMatch.index + 3); } return "/ui"; }