Skip to content

fix(ui): preserve post-login redirect target through oauth2-proxy sign-in - #2532

Open
onematchfox wants to merge 2 commits into
kagent-dev:release/v0.10.xfrom
onematchfox:fix-preserve-login-url
Open

fix(ui): preserve post-login redirect target through oauth2-proxy sign-in#2532
onematchfox wants to merge 2 commits into
kagent-dev:release/v0.10.xfrom
onematchfox:fix-preserve-login-url

Conversation

@onematchfox

Copy link
Copy Markdown
Contributor

When oauth2-proxy intercepts an unauthenticated request it serves its sign-in page carrying the original destination as .Redirect (e.g. /oauth2/sign_in?rd=%2Fagents%2Ffoo). sign_in.html template ignored that and unconditionally redirected to /login, and /login's "Sign in with SSO" link was hardcoded to rd=/ -- so any login, expired- cookie or not, always landed back on the home page instead of the page the user was trying to reach.

Also contains a Helm update that ensures that this change will result in oauth2-proxy being redeployed to pick up the updated sign-in page template.

…n-in

When oauth2-proxy intercepts an unauthenticated request it serves its
sign-in page carrying the original destination as `.Redirect` (e.g.
`/oauth2/sign_in?rd=%2Fagents%2Ffoo`). `sign_in.html` template ignored that and unconditionally redirected to `/login`, and `/login`'s
"Sign in with SSO" link was hardcoded to `rd=/` -- so any login, expired-
cookie or not, always landed back on the home page instead of the page
the user was trying to reach.

Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
@onematchfox
onematchfox requested a review from a team as a code owner August 24, 2026 11:11
Copilot AI lite review requested due to automatic review settings August 24, 2026 11:11
@github-actions github-actions Bot added the bug Something isn't working label Aug 24, 2026
@onematchfox onematchfox changed the title fix(ui): preserve post-login redirect target through oauth2-proxy sign-in fix(ui): preserve post-login redirect target through oauth2-proxy sign-in Aug 24, 2026
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Aug 24, 2026
Adds env var to `oauth2-proxy`'s `Deployment` to ensure that it rolls out when content is updated. The vendored chart's `Deployment` doesn't support a checksum/config-style pod annotation for extra mounted ConfigMaps.

Signed-off-by: Brian Fox <878612+onematchfox@users.noreply.github.com>
@onematchfox
onematchfox force-pushed the fix-preserve-login-url branch from 8cfcd0e to 27fdd5f Compare August 24, 2026 11:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes lost post-auth navigation by preserving the original destination (rd) across the oauth2-proxy sign-in flow and the UI’s /login page, so users land back on the page they initially requested (instead of always returning to /).

Changes:

  • Added a sanitizeRedirect helper (with Jest tests) to prevent open-redirect style rd values and ensure only safe same-origin paths are forwarded.
  • Updated the /login page to read rd from query params, sanitize it, and pass it through to the “Sign in with SSO” link.
  • Updated the Helm oauth2-proxy sign-in template to forward oauth2-proxy’s .Redirect into /login?rd=..., and added a values-driven checksum env var intended to force a rollout when the template content changes.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
ui/src/lib/loginRedirect.ts Adds redirect-target sanitization logic to safely preserve post-login destinations.
ui/src/lib/tests/loginRedirect.test.ts Covers sanitizer behavior for safe paths and common open-redirect vectors.
ui/src/app/login/page.tsx Threads sanitized rd through the SSO start link so login returns users to their original page.
helm/kagent/values.yaml Adds an env var intended to change on template updates to trigger oauth2-proxy redeploys.
helm/kagent/templates/oauth2-proxy-templates.yaml Switches ConfigMap body to a named helper template to support hashing and reuse.
helm/kagent/templates/_helpers.tpl Defines the oauth2-proxy sign_in.html body that forwards .Redirect to /login?rd=....

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants