openship icon indicating copy to clipboard operation
openship copied to clipboard

desktop-login redirects to a hardcoded dashboard origin, breaking the cookie set on the request's own host

Open inoguerols opened this issue 4 months ago • 4 comments

Bug

GET /api/auth/desktop-login sets a host-only session cookie scoped to whatever host the request was made to, but always redirects to a fixed dashboard origin (OPENSHIP_LOCAL_DASHBOARD_URL, default http://localhost:<dashboardPort>) regardless of which host the browser is actually on. If that fixed origin differs from the host the cookie was minted against, the browser lands on the dashboard without the cookie and gets bounced back to /login — dashboard looks completely broken/blank.

This is closely related to #27 (cross-site cookie between localhost dashboard and 127.0.0.1 API) but survives even the workaround suggested there. Opening the dashboard at http://127.0.0.1:<dashboardPort> instead of localhost does NOT fix it by itself, because apps/dashboard/src/app/(auth)/login/page.tsx always calls ${apiUrl}/api/auth/desktop-login (apiUrl = the fixed 127.0.0.1:<apiPort> origin), and that endpoint's redirect target is independently fixed too:

$ curl -sv http://127.0.0.1:4000/api/auth/desktop-login
< HTTP/1.1 302 Found
< location: http://localhost:3001                    # hardcoded default, ignores request host
< set-cookie: openship.session_token=...; Path=/; ...; SameSite=Lax   # host-only, scoped to 127.0.0.1

So no matter which host you start from, you always get bounced to localhost:3001 with a cookie that only exists on 127.0.0.1.

Workaround

Set OPENSHIP_LOCAL_DASHBOARD_URL=http://127.0.0.1:<dashboardPort> in the environment the openship up service runs under (for a launchd-managed service on macOS, add it to the generated plist's EnvironmentVariables and reload — the CLI doesn't expose a flag for this and doesn't forward the invoking shell's env into the service it registers). With both the API and the desktop-login redirect pinned to 127.0.0.1, and the dashboard opened at http://127.0.0.1:<dashboardPort>, the cookie and the redirect target finally agree and login works.

Suggested fix

Derive the redirect target from the incoming request (e.g. Origin/Referer, restricted to the already-trusted origins list) instead of a single fixed OPENSHIP_LOCAL_DASHBOARD_URL/default — same idea as the localApiOverride() fix mentioned in #27, applied to the desktop-login redirect instead of the injected API origin.

Env: macOS host (Apple Silicon), openship 0.1.11 (latest on npm), self-hosted/desktop mode, openship up running as a launchd service (not --foreground), no cloud account connected.

inoguerols avatar Jul 20 '26 09:07 inoguerols

on it, thank you

Hydralerne avatar Jul 20 '26 09:07 Hydralerne

on it thank you

Hydralerne avatar Jul 20 '26 09:07 Hydralerne

Opened a fix: #49 — moved the alignLoopbackOrigin helper (added for #27) into @repo/core and used it server-side in desktopLogin to align the redirect target with the request's Host header when both are loopback, instead of always trusting the fixed OPENSHIP_LOCAL_DASHBOARD_URL/default.

inoguerols avatar Jul 20 '26 10:07 inoguerols

fixed

Hydralerne avatar Jul 22 '26 19:07 Hydralerne