Repository navigation
fix(ui): use the dashboard session in hosted Lens frames - #257
Conversation
|
bugbot run Please review the final dashboard bearer handoff, including the paired Lens change and the attached live verification. |
|
@greptileai review. The final commit removes cookie reconciliation and uses the dashboard bearer. Fresh paired-app proof and rollout requirements are attached. |
|
bugbot run Please review 882ba47: copied trace links now reopen through the same-origin dashboard, and remount-test wording matches its coverage. |
|
@greptileai review Please check 882ba47 for hosted trace-link routing, standalone compatibility, and credential isolation. Actual iframe navigation passes with the root cookie absent. |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 908976a. Configure here.
Embedded Lens now uses the authenticated dashboard session for both its session check and data requests. It waits for a handoff from the same-origin parent and omits cookies from those requests, so a missing or different root cookie cannot select its account
Companion to BerriAI/litellm#54248. The gateway marks the iframe with
data-lens-auth="bearer-v1"and checks its origin and source before sending the existing bearer. The marker stays on the iframe across URL changes, and Inspect run stays in that frame. Standalone Lens and older dashboard parents keep their existing cookie behavior. Either upgrade order is supported. The shared-session fix becomes active when both changes are presentThe UI advertises
X-Lens-UI-Auth: bearer-v1. The existing HTTP clients take their credential and cookie policy from the host configuration. No new backend session, token exchange, cookie, or authorization policy is introducedUser Flow
Before, Lens asks for another login while the dashboard still works.
http://lens-shared.localhost:13098/ui/lens.After, Lens uses the login of the dashboard displaying it.
http://lens-shared.localhost:13098/ui/lens.Screenshots / Proof of Fix
The 20-second recording shows the real dashboard and Lens. A QA helper expires only the root cookie and reopens Lens, then the Traces page loads. Another helper logs in as a second local user and changes only the root cookie. The displayed admin dashboard and its Lens frame stay on the admin session. The helpers only prepare browser state; neither ships with the product.
lens-session-demo.mp4
The real two-tab check also passes. With an Admin dashboard tab still mounted, a second tab signs in as Internal User through the normal login form. Opening Lens in the first tab shows Internal User in the account menu, returns
internal_userfrom/lens/auth/session, and removes Lens's admin-only Alerts and Settings controls.This is a controlled reproduction of the cookie mismatch. Ordinary login works before and after. It does not establish the cause of the original intermittent cookie loss. The demo uses real LiteLLM, Lens, PostgreSQL, ClickHouse, and a dedicated Redis. No model inference is needed for this auth flow. Demo data is off.
The baseline browser screenshot ran LiteLLM
d039b6c80aca542adaef74127fa161a3172d9deeand Lens23a8088b2d6caba28048124be909534b5457d68d. The initial cookie-mismatch recording ran LiteLLMe3967a8fb46ab9ffa7953eaf8d24c114e6ec3c20and Lens76abc01942d38975b816be62b082cfe0b4acec08. The service comparison below reran both gateway revisions against Lens76abc01942d38975b816be62b082cfe0b4acec08. Both gateway revisions accept dashboard bearers already; this change connects the iframe to that existing path.Final browser navigation proof (
8ae1726gateway,882ba47Lens)With only the dashboard-path login cookie present, opened a real trace thread and clicked its earlier-turn Inspect run link. The iframe navigated to that run and completed a fresh parent handshake. Session, trace detail, span, and conversation requests returned 200 with a bearer and no session cookie
Clicked More run actions > Copy link, pasted the actual system clipboard into a new Chrome tab, and opened the result. It was
/ui/lens?trace=...&trace_ref=..., and the trace loaded under the dashboard's Admin account. No credential appears in the linkThe 24-second recording contains 144 actual browser captures. It shows Inspect run, Copy link, and the shared destination opening successfully. The two harmless synthetic turns were sent through the real OTLP ingestion API and stored in local ClickHouse. Demo data is off, and no model was called
lens-session-navigation.mp4
To reproduce, sign in, remove only the root
tokencookie while keeping the/uitoken, open a trace with an earlier conversation turn, click Inspect run, then copy its link and open it in another tab. Expect the run to load both times without another loginShared setup
Both gateway revisions use two uvicorn workers and the same dedicated Redis on 16398. PostgreSQL listens on 15488, Lens on 14318, and ClickHouse on 14323. The UI is on 13098 and its forwarding adapter on 14099.
Exact configuration, startup commands, and browser reproduction
Use isolated local databases. Export
DATABASE_URL,UI_USERNAME,UI_PASSWORD,LITELLM_MASTER_KEY,LITELLM_LENS_URL,LENS_GATEWAY_SECRET,LENS_ADMIN_TOKEN,LITELLM_LENS_SERVICE_TOKEN,CLICKHOUSE_PASSWORD, and credentials for an existing second local dashboard user asQA_SECOND_USERNAMEandQA_SECOND_PASSWORD. Credentials were loaded privately.LITELLM_LENS_URLpoints to port 14318; the gateway and Lens share the gateway secret.From the selected Lens checkout:
The local build reused an existing
CARGO_TARGET_DIR. Start Redis separately:redis-server --port 16398 --save "" --appendonly noSave as
$QA_DIR/config.yaml:From the selected LiteLLM checkout:
Save the following as
qa_forwarder.pyand runpython qa_forwarder.pywithhttpxinstalled. The local launcher obtained the second account from a private JSON file; the equivalent portable version below reads the same two values from environment variables.From
litellm/ui/litellm-dashboard:Sign in normally at
http://lens-shared.localhost:13098/ui/lens. Visit/__qa/missing-root, which removes only the root cookie and redirects to Lens. On the baseline, Lens shows the login error while the dashboard still works. With the paired changes, Lens and Traces load.Sign in as the first user again, then visit
/__qa/switch-account. This calls the real second user's login and changes only the root cookie. The final dashboard and Lens retain the first user's identity. This models a root-only account update; an external SSO provider was not exercised.The account-switch regression renders the real dashboard account menu alongside Lens with AuthProvider still mounted. After another account replaces the shared dashboard cookie, opening Lens uses the same account as that menu. The key and configured header come from the same
useAuthorizedtoken. The dashboard layout has a separate mounted AuthContext gate, which remains unchanged. This PR does not introduce a new dashboard-wide cross-tab login policy.Before (
d039b6c80aca542adaef74127fa161a3172d9dee)The browser fails at the Lens login shown above. Run
python session_probe.py beforewith the client below:{ "mode": "before", "normal_login_lens": 200, "controlled_root_cookie_loss": true, "dashboard_bearer": 200, "lens_cookie_only": 401, "lens_dashboard_bearer": 200, "same_dashboard_user": true, "no_cookie_created": true, "ui_bearer_capability": null, "shared_cookie_does_not_switch_tab_a": true, "second_tab_uses_its_dashboard_user": true, "shared_cookie_unchanged": true, "neither_tab_sets_cookie": true, "revoked_dashboard": 401, "revoked_lens": 401, "revoked_bearer_does_not_fall_back_to_other_cookie": true, "other_session_still_valid": true }After (
e3967a8fb46ab9ffa7953eaf8d24c114e6ec3c20, Lens76abc01942d38975b816be62b082cfe0b4acec08)The same browser flow opens Lens. Run
python session_probe.py after:{ "mode": "after", "normal_login_lens": 200, "controlled_root_cookie_loss": true, "dashboard_bearer": 200, "lens_cookie_only": 401, "lens_dashboard_bearer": 200, "same_dashboard_user": true, "no_cookie_created": true, "ui_bearer_capability": "bearer-v1", "shared_cookie_does_not_switch_tab_a": true, "second_tab_uses_its_dashboard_user": true, "shared_cookie_unchanged": true, "neither_tab_sets_cookie": true, "revoked_dashboard": 401, "revoked_lens": 401, "revoked_bearer_does_not_fall_back_to_other_cookie": true, "other_session_still_valid": true }The actual iframe's session, traces, and admin requests were also observed with a bearer, no session cookie, HTTP 200, and no Set-Cookie. The parent availability request may carry the browser cookie; its explicit dashboard bearer still selects the identity.
Credential-free service verification client
Save as
session_probe.py. It uses the environment variables above and prints only statuses and comparisons, never tokens.Verification
Gateway
8ae172642b16a3ef10361f6ddaef99ed6ac91069: all six required CI checks pass. Greptile reports 5/5, Bugbot reports no issues, and Veria reports no new security issues. Devin has zero outstanding findings. Its older-build proof request was manually marked fixed after the real cookie-mode browser test and screenshot were addedLens final tip
908976a8db150b9a34a007a713a8e25813cc1036has identical production code to the recorded882ba47; it only relocates the copied-link regression into the integration suite. All 61 focused tests and both UI typechecks pass. Devin completed its final analysis with zero outstanding findings and three marked fixed. The live navigation-proof request was manually marked fixed after the actual Inspect run test and recording. Bugbot reports no issues on this tip. The worker/UI contract and Slack-agent CI checks pass. The Rust and two standalone-container jobs are still running; the repository explicitly treats those three as optional. No companion Greptile response has been receivedLiteLLM has 199 passing focused backend tests and 38 passing focused UI tests. The account-ownership regressions render the real Account menu and cover paired key/header ownership, root-cookie removal/replacement, shared-cookie replacement, session removal, and initial expiry. Lens has 61 passing focused UI tests on the recorded product revision, both UI typechecks pass, and the final production UI build passes. The unchanged Rust implementation previously passed 30 UI tests and a binary build
The final service probe on
8ae1726confirms the dashboard and embedded Lens both return 200 after root-cookie loss; the cookie-only request returns 401. Bearers select their own users despite another user's cookie, and a revoked bearer returns 401 without falling back to that cookieThe initial cookie-mismatch recording and two-tab proof use gateway
e3967a8and Lens76abc019. Their shared-session behavior is unchanged by the later compatibility and copied-link fixes. The final 24-second navigation recording uses8ae1726and882ba47and rechecks bearer-authenticated requests with the root cookie absent. The actual older Lens build was also exercised separately on8ae1726LiteLLM's focused UI ESLint and backend gates pass. The local full dashboard typecheck encounters the existing generated
.next/dev/typeserror for the unchangedAgentControlPlaneViewlayout export. No lint or type gate was relaxedFocused verification commands
In LiteLLM:
In Lens:
Note
High Risk
Changes how embedded Lens authenticates API calls (bearer handoff, cookie omission, and share/navigation URLs), which is security-sensitive even though it reuses the dashboard token.
Overview
Embedded Lens no longer relies on browser cookies when it is mounted in a LiteLLM dashboard iframe marked with
data-lens-auth="bearer-v1". A newuseGatewayAuthhandshake postsauth-readyto the parent, waits for a validatedauthframe command (bearer + header name), and only then loads the workspace. While hosted,configureLensHttpand the shared API client send that bearer on every request withcredentials: "omit", so a missing or mismatched root cookie cannot pick the wrong account.The worker UI now advertises
X-Lens-UI-Auth: bearer-v1. Standalone or unmarked frames keep cookie-based sessions unchanged.Gateway-frame navigation is tightened: Inspect run opens in
_selfwhengatewayFrameNavigationis set, and Copy link builds share URLs from the parent dashboard path viagatewayFrameShareLocation, stripping iframe-only query noise.Reviewed by Cursor Bugbot for commit 908976a. Bugbot is set up for automated code reviews on this repo. Configure here.