Registry Mirror
Skip to content

Conversation

@lakhansamani

@lakhansamani lakhansamani commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #344

Root cause

When a user reaches /app from an OIDC /authorize redirect, Root.tsx resumes /authorize after login only if the current URL still carries the authorize params (state, client_id, redirect_uri, code_challenge, ...). Forgot Password lost those params in two places:

  1. Login UI: login.tsx hard-coded the forgot-password redirect_uri to ${origin}/app/reset-password, so the params were never sent.
  2. Server: utils.GetForgotPasswordURL built the reset link as redirectURI + "?token=" + token. Any redirect URI that already had a query string came out malformed (...?a=b?token=...), so the server could not have carried the params even if the UI had sent them.

After the reset, AuthorizerResetPassword fell back to config.redirectURL/origin, which left the user on the Authorizer dashboard.

(ForgotPasswordRequest.state is still unused by the service. On its own it is not enough to resume the flow, and the full authorize context now travels on the redirect URI, so this PR doesn't wire it up.)

Fix

  • internal/utils/common.go: GetForgotPasswordURL parses the redirect URI and Sets token into its existing query. Because it uses Set, a token param supplied by the caller can't shadow the real one. A plain redirect URI produces the same link as before. A hash-routed redirect URI (for example https://app.example.com/#/reset-password) keeps the token inside the fragment route, which is where a hash router reads it, giving .../#/reset-password?token=T as before. Any query already in the fragment is merged in the same way, again with Set.
  • web/app/src/pages/login.tsx and Root.tsx: when the page is in an authorize context, the pending authorize params (query plus fragment, the same set Root already uses) are appended to the same-origin /app/reset-password redirect URI.
  • web/app/src/pages/rest-password.tsx: if the reset link carries an authorize context, after a successful reset the page removes token and does location.replace('/app?<authorize params>'). The user logs in with the new password and Root's existing logic resumes /authorize. Links without an authorize context behave as before.
  • web/app/src/utils/common.ts: the authorize-context check that was inline in Root.tsx moves into a shared isAuthorizeContextParams helper.
  • web/app/src/Root.tsx: a page load that started on /app/reset-password never auto-resumes /authorize or the SAML continue URL. This is captured once per page load in a module-level startedOnResetPassword, because for a signed-in user the router's catch-all <Navigate> moves the URL to /app on the client side, so checking the pathname on each render doesn't work. isAuthorizeContext is also forced to false in that case, so any token && isAuthorizeContext loading guard (as in fix(app): don't flash signed-in dashboard before authorize redirect #921) stays consistent. The resume path also never copies a token param into /authorize. Without this, a user who already had a session and opened a reset link, which anyone can request, would be silently authorized into the client. They now land on the plain /app dashboard. A signed-out user still resets, and the reset page then does a full navigation to /app with the params, where logging in resumes the flow.

Security notes

  • The forgot-password redirect_uri is still validated with IsValidRedirectURI against allowed origins, whatever its query says. There is a test for this.
  • The reset page only ever navigates to our own /app path. It never navigates to a URL taken from the query. The client's redirect_uri is used only by /authorize, which checks it against the client's registered redirect URIs as it always has.
  • No access or ID tokens are put in URLs. The reset token stays in the emailed link, as it always has, and is removed before the user is sent back to /app.
  • state and the other params are URL-encoded with URLSearchParams/url.Values, so they can't inject query structure or redirects.
  • Accepted risk: forgot_password needs no authentication, so whoever requests a reset chooses the authorize params in the reset link. That gives them nothing a crafted /authorize link doesn't already give them. Resuming lands on /authorize, which still validates redirect_uri against the client's registered URIs and still applies the DCR/CIMD consent gate. To get anything, the attacker would also need the victim's mailbox, since the reset token is mailed only to the account owner.
  • Cross-device resets fail safe: the authorize params travel in the link, not in browser storage. If the link is opened on another device, logging in there completes /authorize and sends the code to the client's validated redirect_uri on that device. That browser lacks the original state and PKCE code_verifier, so the client rejects the code and the user has to start sign-in again. The user is never sent anywhere that wasn't validated.

Tests

  • New internal/utils/common_test.go TestGetForgotPasswordURL: plain URI, merging into an existing authorize query, a supplied token param that must not shadow the real one, and two hash-routed cases (a bare fragment route, and a fragment route that has its own query). The hash-routed cases were added test-first after review and failed until the fragment handling went in.
  • New subtests in internal/integration_tests/forgot_password_test.go:
    • The authorize params survive into the stored redirect URI and the mailed reset link, and that link's token resets the password and allows login with the new one. Fails without the fix.
    • An untrusted-origin redirect URI carrying authorize params is still rejected.

Run locally:

  • go build ./... passed
  • go vet ./... passed
  • make test (SQLite) passed
  • make lint passed: golangci-lint 0 issues, prettier clean on both web apps
  • make build-app passed, and tsc --noEmit on web/app is clean

Not run: a browser end-to-end check of the UI flow, and make smoke.

Manual test steps

  1. make dev, then register an OAuth client with a redirect URI such as http://localhost:3000/callback.
  2. Open http://localhost:8080/authorize?client_id=<id>&response_type=code&redirect_uri=http://localhost:3000/callback&scope=openid%20profile%20email&state=abc&code_challenge=<S256>&code_challenge_method=S256&response_mode=query while logged out. You land on /app?....
  3. Click Forgot Password? and submit the email of an existing user.
  4. Open the reset link from the email. It should be /app/reset-password?client_id=...&state=abc&...&token=....
  5. Set a new password. You should be sent to /app?client_id=...&state=abc&..., with no token param.
  6. Log in with the new password. You should be redirected to http://localhost:3000/callback?code=...&state=abc.
  7. Regression check: start Forgot Password from a plain /app with no authorize params. The reset link is /app/reset-password?token=... and the post-reset behaviour is unchanged.

A user who reached the login UI from an OIDC /authorize redirect and used
Forgot Password was left on /app after resetting, instead of returning to
the client. The login UI dropped the authorize params from the reset link,
and the server built the link as redirectURI + "?token=", which could not
carry a query string anyway.

- utils.GetForgotPasswordURL merges the token into the redirect URI's
  existing query (Set, so a supplied token param cannot shadow it).
- The login page forwards the pending authorize params on the same-origin
  /app/reset-password redirect_uri (still validated server-side).
- The reset page, when those params are present, strips the token and
  returns to /app with them, so logging in resumes /authorize, which
  re-validates redirect_uri.

Fixes #344
…ze from reset page

- GetForgotPasswordURL: for hash-routed redirect URIs keep the token inside
  the fragment route (pre-existing behaviour) instead of moving it to the
  real query, merging into any fragment query with Set.
- Root.tsx: never auto-resume /authorize on /app/reset-password and never
  forward a token param to /authorize, so an existing session opening a
  reset link neither skips the form nor leaks the reset token.

Refs #344
… the reset page

The per-render pathname check was ineffective: for a signed-in user the
catch-all <Navigate> moves /app/reset-password to /app client-side, so the
resume effect re-ran on /app and silently authorized the user into the
client from a reset link (which anyone can request). Capture the initial
pathname once per page load and drop the authorize context when it was the
reset page; signed-in users land on the /app dashboard instead.

Refs #344
@lakhansamani
lakhansamani force-pushed the fix/344-forgot-password-preserve-authorize branch from 0ff4c7b to 9f0f7fe Compare November 26, 2026 06:50
@lakhansamani
lakhansamani merged commit cf22295 into main Nov 26, 2026
4 checks passed
@lakhansamani
lakhansamani deleted the fix/344-forgot-password-preserve-authorize branch November 26, 2026 06: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.

No redirection from LogIn page if I go there from Forgot Password email link.

1 participant