Skip to content

Return users to the page they asked for after OIDC login - #572

Draft
somethingnew2-0 wants to merge 1 commit into
mainfrom
pcollins/issue-566-fix-c1b678
Draft

Return users to the page they asked for after OIDC login#572
somethingnew2-0 wants to merge 1 commit into
mainfrom
pcollins/issue-566-fix-c1b678

Conversation

@somethingnew2-0

Copy link
Copy Markdown
Collaborator

Closes #566.

A signed-out user following a link to a group page should land on that group page once the IdP is done with them, not on the home page. Two gaps kept that from happening.

The query string was dropped. The next captured on the login bounce was request.url.path. The SPA keeps list filters, search terms, sort order and pagination in the query string, so that's the shareable part of a deep link — without it the user arrives at an unfiltered page.

XHR was bounced to the IdP. An unauthenticated /api/* request got the same 307 a browser navigation gets. fetch can't complete an interactive login: it follows the redirect into the IdP's cross-origin HTML, fails CORS, and the SPA surfaces a generic "unexpected error". Someone whose session expired while the app was open was stuck there with no way back short of a manual reload. Requests that aren't a top-level navigation now get a 401 carrying a login_url extension member, and the client escalates to a real navigation with its own location (query string and fragment included) as next.

Navigation is detected from Sec-Fetch-Mode, falling back to sniffing Accept for clients that omit it, rather than from the request path. Path-based detection would have been simpler but would have broken browsing to /api/docs on deployments that enable it.

While in here, next now also rejects paths under /oidc/ — a crafted link could otherwise return the user to /oidc/logout (undoing the login they just completed) or /oidc/login (looping). Third-party hosts were already rejected.

Note this is partly pre-existing behaviour the reporter hasn't seen yet: the next round trip itself landed with the FastAPI migration (#425) and isn't in a release, so on v1.6.1 the redirect always goes to /. This PR closes the remaining gaps on top of it.

🤖 Generated with Claude Code

Closes #566.

A signed-out user following a link to a group page should land on that
group page once the IdP is done with them, not on the home page. Two gaps
kept that from happening.

The `next` captured on the login bounce was `request.url.path`, dropping
the query string. The SPA keeps list filters, search terms, sort order and
pagination there, so a shared deep link arrived stripped of most of its
meaning.

And an unauthenticated `/api/*` request was answered with the same 307 to
the IdP that a browser navigation gets. `fetch` can't complete an
interactive login: it follows the redirect into the IdP's cross-origin
HTML, fails CORS, and the SPA renders a generic error. A user whose
session expired mid-session was stuck there with no way back short of a
manual reload. Requests that aren't a top-level navigation now get a 401
carrying `login_url`, and the client escalates to a real navigation with
its own location as `next`.

Navigation is detected from `Sec-Fetch-Mode` (falling back to sniffing
`Accept` for clients that omit it) rather than from the path, so a browser
pointed at `/api/docs` still gets the login bounce.

`next` also now rejects paths under `/oidc/`, which would otherwise let a
crafted link log the user straight back out or loop the login.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

After auth, redirect to intended URL

1 participant