You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "btlqql (via GitHub)" <gi...@apache.org> on 2026/10/02 03:49:16 UTC
[PR] fix(web): return to the previous page after a session re-login [rocketmq-dashboard]
btlqql opened a new pull request, #5336:
URL: https://github.com/apache/rocketmq-dashboard/pull/5336
### Which Issue(s) This PR Fixes
- Fixes #5245
### Brief Description
Two places dropped the operator's page on session expiry:
- `web/src/api/client.ts` — `handleSessionUnauthorized()` cleared the session and set
`window.location.href = '/login'`, discarding the current path and query string.
- `web/src/pages/login/index.tsx` — `onFinish` always ran `navigate('/', { replace: true })`, so
even a login page reached with a target in mind went home.
Now the 401 redirect carries the page the operator was on as an encoded `redirect` parameter
(`sessionExpiryRedirectUrl`, which redirects plainly when the session expires while `/login`
itself is open, so the login page never links to itself), and a successful login navigates to
`sanitizeLoginRedirect(searchParams.get('redirect'))` with the same `replace` navigation as before
(no back-button trap back into the login page). The target is only accepted when it is a same-app
absolute path: protocol-relative values (`//evil.example`), absolute external URLs, paths without a
leading slash and backslash variants all fall back to `/`.
### How Did You Test This Change?
New cases in `web/src/api/client.test.ts` (the redirect URL the 401 handler produces, both through
`handleSessionUnauthorized()` and through a real 401 from a protected request, with `window.location`
replaced because jsdom cannot navigate) and in `web/src/pages/login/index.test.tsx` (return to the
carried page, home without a parameter, and each rejected redirect shape). All were run first on the
unmodified tree (red) and then after the fix (green).
```
$ cd web && npx vitest run src/api/client.test.ts src/pages/login/index.test.tsx
# before the fix
× sends an expired session to the login page carrying the page it was on
AssertionError: expected '/login' to be '/login?redirect=%2Fops%2Falerts%3Flev…' // Object.is equality
× carries the current page when a protected request expires the session
AssertionError: expected '/login' to be '/login?redirect=%2Finstance%2Fmessage…' // Object.is equality
× returns to the page the operator was on when the login page carries a redirect
AssertionError: expected "vi.fn()" to be called with arguments: [ '/ops/alerts?level=error', …(1) ]
Test Files 2 failed (2)
Tests 3 failed | 24 passed (27)
# after the fix
✓ src/api/client.test.ts (17 tests) 52ms
✓ src/pages/login/index.test.tsx (10 tests) 2890ms
Test Files 2 passed (2)
Tests 27 passed (27)
$ cd web && npx tsc -b # exit 0, no diagnostics
$ cd web && npx eslint src/api/client.ts src/api/client.test.ts src/pages/login/index.tsx src/pages/login/index.test.tsx
# exit 0, no problems
```
### Checklist
- [x] One coherent change; unrelated modifications are not bundled in
- [x] Commit subject follows Conventional Commits
- [x] Tests added or updated for non-trivial changes
- [ ] New UI text has both Chinese and English entries under `web/src/i18n/` — not applicable: the
change adds no user-facing string (the existing login messages are reused unchanged)
- [x] Architecture constraints stay green — no `server/**` file is touched, so the ArchUnit checks
are unaffected; `npx tsc -b` and `npx eslint` are clean
- [ ] New source files carry the ASF license header — not applicable: no new source file
- [ ] Documentation touched where behaviour changed — not applicable: the session-expiry flow is not
described in README or `docs/`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(web): return to the previous page after a session re-login [rocketmq-dashboard]
Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins closed pull request #5336: fix(web): return to the previous page after a session re-login
URL: https://github.com/apache/rocketmq-dashboard/pull/5336
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(web): return to the previous page after a session re-login [rocketmq-dashboard]
Posted by "lizhimins (via GitHub)" <gi...@apache.org>.
lizhimins commented on PR #5336:
URL: https://github.com/apache/rocketmq-dashboard/pull/5336#issuecomment-6413399215
Thank you for this — the session-expiry redirect landed first through #7311 (merged into `rocketmq-studio` as `5e6c8971e`), so this PR is now a duplicate of the part that shipped:
- `web/src/api/client.ts` builds `/login?redirect=<path+query>` when a session turns out unauthorized, with the self-reference guard for an expiry while already on `/login`;
- `web/src/pages/login/index.tsx` honours it through a `sanitizeReturnPath` helper that rejects protocol-relative URLs (`//evil.com`), anything with a scheme, and backslashes.
Closing on that basis, not because the analysis was wrong — #5245 is closed as resolved by #7311.
One case in your branch is **not** covered by what landed, and it is worth keeping: the `AuthGate` in `web/src/App.tsx` still does `<Navigate to="/login" replace />` when the gate denies, which drops the page exactly the way the old `client.ts` did. That path is not an axios 401, so the client-side helper never runs. If you would like to follow up, a slim PR with just the `AuthGate` change — your `sessionExpiryRedirectUrl(location.pathname, location.search)` idea — plus its test would be welcome, and we will review it on its own merits.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org