Conversation
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
force-pushed
the
fix/344-forgot-password-preserve-authorize
branch
from
November 26, 2026 06:50
0ff4c7b to
9f0f7fe
Compare
This was referenced Nov 26, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #344
Root cause
When a user reaches
/appfrom an OIDC/authorizeredirect,Root.tsxresumes/authorizeafter 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:login.tsxhard-coded the forgot-passwordredirect_urito${origin}/app/reset-password, so the params were never sent.utils.GetForgotPasswordURLbuilt the reset link asredirectURI + "?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,
AuthorizerResetPasswordfell back toconfig.redirectURL/origin, which left the user on the Authorizer dashboard.(
ForgotPasswordRequest.stateis 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:GetForgotPasswordURLparses the redirect URI andSetstokeninto its existing query. Because it usesSet, atokenparam 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 examplehttps://app.example.com/#/reset-password) keeps the token inside the fragment route, which is where a hash router reads it, giving.../#/reset-password?token=Tas before. Any query already in the fragment is merged in the same way, again withSet.web/app/src/pages/login.tsxandRoot.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-passwordredirect URI.web/app/src/pages/rest-password.tsx: if the reset link carries an authorize context, after a successful reset the page removestokenand doeslocation.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 inRoot.tsxmoves into a sharedisAuthorizeContextParamshelper.web/app/src/Root.tsx: a page load that started on/app/reset-passwordnever auto-resumes/authorizeor the SAML continue URL. This is captured once per page load in a module-levelstartedOnResetPassword, because for a signed-in user the router's catch-all<Navigate>moves the URL to/appon the client side, so checking the pathname on each render doesn't work.isAuthorizeContextis also forced to false in that case, so anytoken && isAuthorizeContextloading guard (as in fix(app): don't flash signed-in dashboard before authorize redirect #921) stays consistent. The resume path also never copies atokenparam 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/appdashboard. A signed-out user still resets, and the reset page then does a full navigation to/appwith the params, where logging in resumes the flow.Security notes
redirect_uriis still validated withIsValidRedirectURIagainst allowed origins, whatever its query says. There is a test for this./apppath. It never navigates to a URL taken from the query. The client'sredirect_uriis used only by/authorize, which checks it against the client's registered redirect URIs as it always has./app.stateand the other params are URL-encoded withURLSearchParams/url.Values, so they can't inject query structure or redirects.forgot_passwordneeds no authentication, so whoever requests a reset chooses the authorize params in the reset link. That gives them nothing a crafted/authorizelink doesn't already give them. Resuming lands on/authorize, which still validatesredirect_uriagainst 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./authorizeand sends the code to the client's validatedredirect_urion that device. That browser lacks the originalstateand PKCEcode_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
internal/utils/common_test.goTestGetForgotPasswordURL: plain URI, merging into an existing authorize query, a suppliedtokenparam 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.internal/integration_tests/forgot_password_test.go:Run locally:
go build ./...passedgo vet ./...passedmake test(SQLite) passedmake lintpassed: golangci-lint 0 issues, prettier clean on both web appsmake build-apppassed, andtsc --noEmiton web/app is cleanNot run: a browser end-to-end check of the UI flow, and
make smoke.Manual test steps
make dev, then register an OAuth client with a redirect URI such ashttp://localhost:3000/callback.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=querywhile logged out. You land on/app?..../app/reset-password?client_id=...&state=abc&...&token=..../app?client_id=...&state=abc&..., with notokenparam.http://localhost:3000/callback?code=...&state=abc./appwith no authorize params. The reset link is/app/reset-password?token=...and the post-reset behaviour is unchanged.