Skip to content

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]

[Fix] UI: Clear Admin Session Cookies Before Establishing Invited User's Session (#27227)

yuneng-jiangfa6a82ab0f9d
diff --git a/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.test.tsx b/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.test.tsx
index bf73e802cd8..965b0db47c3 100644
--- a/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.test.tsx
+++ b/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.test.tsx
@@ -61,6 +61,8 @@ describe("OnboardingForm", () => {
beforeEach(() => {
vi.clearAllMocks();
document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/";
+ document.cookie = "token=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/ui";
+ sessionStorage.clear();
});
it("should render loading view when credentials are loading", () => {
@@ -112,6 +114,58 @@ describe("OnboardingForm", () => {
expect(screen.getByTestId("form-body")).toHaveAttribute("data-variant", "reset_password");
});
+ it("should overwrite a prior admin sessionStorage token after successful claim", async () => {
+ // Simulate the prior admin session that the inviter left behind in the same tab.
+ sessionStorage.setItem("token", "ADMIN_SESSION_TOKEN");
+
+ mockUseOnboardingCredentials.mockReturnValue({
+ data: { token: "fake-jwt-token" },
+ isLoading: false,
+ isError: false,
+ });
+ mockClaimToken.mockImplementation((_params, options) => {
+ options.onSuccess({ token: "NEW_USER_TOKEN" });
+ });
+
+ render(<OnboardingForm variant="signup" />);
+
+ await act(async () => {
+ fireEvent.click(screen.getByRole("button", { name: "Submit" }));
+ });
+
+ // After signup the new user's token must replace the admin's sessionStorage entry,
+ // otherwise the HttpOnly-fallback path in getCookie() keeps returning the admin token.
+ expect(sessionStorage.getItem("token")).toBe("NEW_USER_TOKEN");
+ });
+
+ it("should set the new token cookie at path=/ui after successful claim", async () => {
+ mockUseOnboardingCredentials.mockReturnValue({
+ data: { token: "fake-jwt-token" },
+ isLoading: false,
+ isError: false,
+ });
+ mockClaimToken.mockImplementation((_params, options) => {
+ options.onSuccess({ token: "NEW_USER_TOKEN" });
+ });
+
+ const cookieSpy = vi.spyOn(document, "cookie", "set");
+ render(<OnboardingForm variant="signup" />);
+
+ await act(async () => {
+ fireEvent.click(screen.getByRole("button", { name: "Submit" }));
+ });
+
+ // The /ui path is what storeLoginToken writes to (and what LoginPage reads from);
+ // a cookie at path=/ alone leaves any pre-existing /ui-scoped admin cookie winning.
+ const newTokenCookieAtUiPath = cookieSpy.mock.calls.some(([value]) => {
+ const v = String(value);
+ return v.includes("token=NEW_USER_TOKEN") && v.includes("path=/ui");
+ });
+ expect(newTokenCookieAtUiPath).toBe(true);
+
+ cookieSpy.mockRestore();
+ });
+
it("should show claim error when claim response is missing final token", async () => {
mockUseOnboardingCredentials.mockReturnValue({
data: { token: "fake-jwt-token" },
diff --git a/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.tsx b/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.tsx
index 1e8afe7645e..add58102c57 100644
--- a/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.tsx
+++ b/ui/litellm-dashboard/src/app/onboarding/OnboardingForm.tsx
@@ -4,6 +4,7 @@ import { useSearchParams } from "next/navigation";
import { jwtDecode } from "jwt-decode";
import { useOnboardingCredentials, useClaimOnboardingToken } from "@/app/(dashboard)/hooks/onboarding/useOnboarding";
import { getProxyBaseUrl } from "@/components/networking";
+import { clearTokenCookies, storeLoginToken } from "@/utils/cookieUtils";
import { OnboardingLoadingView } from "./OnboardingLoadingView";
import { OnboardingErrorView } from "./OnboardingErrorView";
import { OnboardingFormBody } from "./OnboardingFormBody";
@@ -45,7 +46,12 @@ export function OnboardingForm({ variant }: OnboardingFormProps) {
setClaimError("Failed to start session. Please try again.");
return;
}
- document.cookie = `token=${data.token}; path=/; SameSite=Lax`;
+ // Invite signup is a principal-change boundary — the prior admin's
+ // cookies/sessionStorage must be invalidated before the new user's
+ // session is established, otherwise getCookie() can fall back to
+ // the inviter's token.
+ clearTokenCookies();
+ storeLoginToken(data.token);
const proxyBaseUrl = getProxyBaseUrl();
window.location.href = proxyBaseUrl
? `${proxyBaseUrl}/ui/?login=success`