Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6eb78e4
fix(ui): resolve login redirect loop when reverse proxy adds HttpOnly…
jaxhend Mar 13, 2026
a8864ea
fix: address Greptile review feedback
jaxhend Mar 13, 2026
2c5caac
fix: address second round of Greptile review feedback
jaxhend Mar 13, 2026
04f835e
Update ui/litellm-dashboard/src/utils/cookieUtils.ts
jaxhend Mar 13, 2026
22409da
Update ui/litellm-dashboard/src/utils/cookieUtils.ts
jaxhend Mar 13, 2026
461cf00
fix(ui): use sessionStorage instead of cookie for login token storage
jaxhend Mar 13, 2026
523d1c3
fix(ui): use shared getCookie in page.tsx and user_dashboard.tsx
jaxhend Mar 13, 2026
acdc614
fix(ui): scope deleteCookie sessionStorage cleanup to token key only
jaxhend Mar 13, 2026
a607754
Update ui/litellm-dashboard/src/utils/cookieUtils.ts
jaxhend Mar 13, 2026
20ad73f
Apply suggestion from @greptile-apps[bot]
jaxhend Mar 13, 2026
06260df
style: remove stray double blank line in user_dashboard.tsx
jaxhend Mar 13, 2026
35bd69e
fix(ui): guard storeLoginToken against empty/whitespace-only tokens
jaxhend Mar 13, 2026
01f8844
fix(ui): preserve sessionStorage token across beforeunload clear
jaxhend Mar 13, 2026
a093760
fix(ui): set JS-accessible cookie at /ui path as HttpOnly workaround
jaxhend Mar 19, 2026
bd878e7
fix(ui): use dynamic cookie path based on server_root_path
jaxhend Mar 19, 2026
40eaab5
refactor(ui): remove circular dependency in cookieUtils.ts
jaxhend Mar 19, 2026
11974ca
fix(ui): harden getUiCookiePath regex and add missing tests
jaxhend Mar 19, 2026
eb1a83e
Merge remote-tracking branch 'origin/main' into litellm_login_httponl…
jaxhend Mar 23, 2026
c16fdce
style: fix Black formatting in audit_logs.py
jaxhend Mar 23, 2026
61f5b68
Merge branch 'main' of https://github.com/BerriAI/litellm into litell…
jaxhend Mar 27, 2026
ce8bf55
Merge branch 'main' of https://github.com/BerriAI/litellm into litell…
jaxhend Mar 30, 2026
2905d47
fix CI: formatting, test params, remove token from login JSON
jaxhend Mar 30, 2026
b2c3334
fix: reformat with Black 23.x to match CI
jaxhend Mar 30, 2026
086c416
fix: keep token in login JSON body for UI storeLoginToken flow
jaxhend Mar 30, 2026
866405f
fix: use storeLoginToken in exchangeLoginCode, add credentials include
jaxhend Mar 30, 2026
0684a1e
revert: remove unrelated changes from HttpOnly cookie fix branch
jaxhend Mar 31, 2026
eff9e70
Revert "revert: remove unrelated changes from HttpOnly cookie fix bra…
jaxhend Mar 31, 2026
940789f
Revert "fix: use storeLoginToken in exchangeLoginCode, add credential…
jaxhend Mar 31, 2026
dcbe924
Revert "fix: keep token in login JSON body for UI storeLoginToken flow"
jaxhend Mar 31, 2026
ecd8cc5
Revert "fix: reformat with Black 23.x to match CI"
jaxhend Mar 31, 2026
7f14d41
Revert "fix CI: formatting, test params, remove token from login JSON"
jaxhend Mar 31, 2026
3298858
Merge branch 'BerriAI:main' into litellm_login_httponly_cookie_fix
jaxhend Mar 31, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11029,8 +11029,11 @@ async def login_v2(request: Request): # noqa: PLR0915
litellm_dashboard_ui += "/ui/"
litellm_dashboard_ui += "?login=success"

# Token is included in the response body so the UI can set a JS-accessible
# cookie even when a reverse proxy (e.g. nginx-ingress) adds HttpOnly to the
# server-set cookie, which would otherwise cause an infinite login redirect.
json_response = JSONResponse(
content={"redirect_url": litellm_dashboard_ui},
content={"redirect_url": litellm_dashboard_ui, "token": jwt_token},
status_code=status.HTTP_200_OK,
)
json_response.set_cookie(key="token", value=jwt_token)
Comment thread
jaxhend marked this conversation as resolved.
Resolved
Expand Down
8 changes: 4 additions & 4 deletions tests/test_litellm/proxy/test_proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def test_login_v2_returns_redirect_url_and_sets_cookie(monkeypatch):
)

assert response.status_code == 200
assert (
response.json()
== {"redirect_url": "http://testserver/ui/?login=success"}
)
assert response.json() == {
"redirect_url": "http://testserver/ui/?login=success",
"token": "signed-token",
}
assert response.cookies.get("token") == "signed-token"

mock_authenticate_user.assert_awaited_once_with(
Expand Down
1 change: 1 addition & 0 deletions ui/litellm-dashboard/src/components/networking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as Networking from "./networking";
vi.mock("@/utils/cookieUtils", () => ({
clearTokenCookies: vi.fn(),
getCookie: vi.fn(),
setTokenCookie: vi.fn(),
}));
Comment thread
jaxhend marked this conversation as resolved.
Resolved

vi.mock("./molecules/notifications_manager", () => ({
Expand Down
6 changes: 5 additions & 1 deletion ui/litellm-dashboard/src/components/networking.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const getInProductNudgesCall = async (accessToken: string) => {
* Helper file for calls being made to proxy
*/
import { message } from "antd";
import { clearTokenCookies } from "@/utils/cookieUtils";
import { clearTokenCookies, setTokenCookie } from "@/utils/cookieUtils";
import { TagNewRequest, TagUpdateRequest, TagListResponse, TagInfoResponse } from "./tag_management/types";
import { Team } from "./key_team_helpers/key_list";
import { UserInfo } from "./view_users/types";
Expand Down Expand Up @@ -8976,6 +8976,7 @@ export interface LoginRequest {

interface LoginResponse {
redirect_url: string;
token?: string;
}

export const loginCall = async (username: string, password: string): Promise<LoginResponse> => {
Expand Down Expand Up @@ -9003,6 +9004,9 @@ export const loginCall = async (username: string, password: string): Promise<Log
}

const data = await response.json();
if (data.token) {
setTokenCookie(data.token);
}
return data;
};

Expand Down
38 changes: 37 additions & 1 deletion ui/litellm-dashboard/src/utils/cookieUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, beforeEach, vi } from "vitest";
import { clearTokenCookies, getCookie } from "./cookieUtils";
import { clearTokenCookies, getCookie, setTokenCookie } from "./cookieUtils";

describe("cookieUtils", () => {
beforeEach(() => {
Expand Down Expand Up @@ -118,6 +118,42 @@ describe("cookieUtils", () => {
});
});

describe("setTokenCookie", () => {
it("should set a token cookie readable by getCookie", () => {
setTokenCookie("my-jwt-token");
expect(getCookie("token")).toBe("my-jwt-token");
});

it("should overwrite an existing token cookie", () => {
setTokenCookie("old-token");
expect(getCookie("token")).toBe("old-token");

setTokenCookie("new-token");
expect(getCookie("token")).toBe("new-token");
});

it("should not throw when document is undefined (server-side rendering)", () => {
const originalDocument = global.document;
delete (global as any).document;

expect(() => setTokenCookie("token")).not.toThrow();

global.document = originalDocument;
});

it("should not throw when window is undefined (server-side rendering)", () => {
const originalWindow = global.window;
const originalDocument = global.document;
delete (global as any).window;
delete (global as any).document;

expect(() => setTokenCookie("token")).not.toThrow();

global.window = originalWindow;
global.document = originalDocument;
});
});

describe("getCookie", () => {
it("should return cookie value when it exists", () => {
document.cookie = "token=my-test-token; path=/";
Expand Down
10 changes: 10 additions & 0 deletions ui/litellm-dashboard/src/utils/cookieUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ export function clearTokenCookies() {
console.log("After clearing cookies:", document.cookie);
Comment thread
jaxhend marked this conversation as resolved.
Resolved
}

/**
* Sets the token cookie from a login response body.
* This ensures the token is JS-accessible even when a reverse proxy adds HttpOnly to server-set cookies.
*/
export function setTokenCookie(token: string) {
if (typeof window === "undefined" || typeof document === "undefined") return;
const isSecure = window.location.protocol === "https:";
document.cookie = `token=${token}; Path=/; SameSite=Lax${isSecure ? "; Secure" : ""}`;
Comment thread
jaxhend marked this conversation as resolved.
Resolved
}

/**
* Gets a cookie value by name
* @param name The name of the cookie to retrieve
Expand Down
Loading