Skip to content

fix: prefix OAuth state cookie Path with the server.external-url path - #21

Merged
hpkoh merged 1 commit into
mainfrom
fix/state-cookie-behind-path-prefix
Oct 8, 2026
Merged

hpkoh merged 1 commit into
mainfrom
fix/state-cookie-behind-path-prefix

Conversation

@hpkoh

@hpkoh hpkoh commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator

Behind a reverse proxy that strips a path prefix, /auth/login set UC_OAUTH_STATE with Path=/api/1.0/unity-control/auth, the mount path the server sees. The browser returns to /callback under the prefix, so the cookie was never sent and the callback failed with "Missing login state".

redirect_uri is already built from server.external-url. Set and clear the state cookie on the same path: external-url path + mount path. No change when external-url is unset or has no path; UC_TOKEN (Path=/) is unaffected.

Closes #20.

What this does

Before After
redirect_uri <external-url>/api/1.0/unity-control/auth/callback unchanged
UC_OAUTH_STATE Path (set at /login, cleared at /callback) /api/1.0/unity-control/auth <external-url path>/api/1.0/unity-control/auth
UC_TOKEN Path / unchanged

With server.external-url=https://api.example.com/unitycatalog, the state cookie is now scoped to
/unitycatalog/api/1.0/unity-control/auth, the directory of redirect_uri, so the browser sends
it to /callback. The deletion uses the same path, since a cookie is only removed by a
Set-Cookie that names its path.

No change when external-url is unset or has no path. That covers every setup that serves the
server at the root of its host, including the deploy scripts in this repo.

Tests

New AuthServiceHostedLoginBehindPrefixTest (2 cases): external-url with a prefix and a trailing
slash; checks redirect_uri, the state cookie path, its deletion path at /callback, and that
UC_TOKEN stays at Path=/. Verified in reverse: without the fix, both cases fail.
AuthServiceHostedLoginTest (11 cases) still passes.

Behind a reverse proxy that strips a path prefix, /auth/login set
UC_OAUTH_STATE with Path=/api/1.0/unity-control/auth, the mount path the server sees. The browser returns to /callback under the prefix, so the
cookie was never sent and the callback failed with "Missing login state".

redirect_uri is already built from server.external-url. Set and clear the
state cookie on the same path: external-url path + mount path. No change when external-url is unset or has no path; UC_TOKEN (Path=/) is unaffected.

Closes #20.
@hpkoh
hpkoh force-pushed the fix/state-cookie-behind-path-prefix branch from 9945c3f to 6810070 Compare October 8, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hosted login fails behind a reverse proxy that strips a path prefix

2 participants