From 2c8063b07205bc44150a2062327e5208a8975757 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 3 Mar 2025 17:24:41 -0800 Subject: [PATCH] fix clearTokenCookies --- ui/litellm-dashboard/src/utils/cookieUtils.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/ui/litellm-dashboard/src/utils/cookieUtils.ts b/ui/litellm-dashboard/src/utils/cookieUtils.ts index 857deda4bb8..35dd8d67058 100644 --- a/ui/litellm-dashboard/src/utils/cookieUtils.ts +++ b/ui/litellm-dashboard/src/utils/cookieUtils.ts @@ -13,18 +13,30 @@ export function clearTokenCookies() { const paths = ['/', '/ui']; const sameSiteValues = ['Lax', 'Strict', 'None']; - paths.forEach(path => { - // Basic clearing - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; - - // With domain - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; - - // Try different SameSite values - sameSiteValues.forEach(sameSite => { - const secureFlag = sameSite === 'None' ? ' Secure;' : ''; - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; - document.cookie = `token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; + // Get all cookies + const allCookies = document.cookie.split("; "); + const tokenPattern = /^token_\d+$/; + + // Find all token cookies + const tokenCookieNames = allCookies + .map(cookie => cookie.split("=")[0]) + .filter(name => name === "token" || tokenPattern.test(name)); + + // Clear each token cookie with various combinations + tokenCookieNames.forEach(cookieName => { + paths.forEach(path => { + // Basic clearing + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`; + + // With domain + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain};`; + + // Try different SameSite values + sameSiteValues.forEach(sameSite => { + const secureFlag = sameSite === 'None' ? ' Secure;' : ''; + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; SameSite=${sameSite};${secureFlag}`; + document.cookie = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path}; domain=${domain}; SameSite=${sameSite};${secureFlag}`; + }); }); });