fix(auth): preserve deep-link route across cold-load re-auth (MAPPS-323) #359
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/MAPPS-323-deeplink-return-to"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
A cold load or bookmark of an authed deep link (e.g.
/tickets/new) while the user holds a valid OP session bounced to/dashboardinstead of the requested page. Fixes MAPPS-323.Two gaps:
start_login(&cfg, "")with an EMPTYreturn_to(src/lib.rs:59), dropping the path the user actually asked for./auth/callback(src/pages/auth_callback.rs) collapsed every same-originreturn_totoRoute::Dashboard(the inline comment admitted it: "the Dioxus router only knowsRoutevariants, so an internal path beyond/dashboardcollapses toDashboardfor the moment").How
oidc::current_return_to(): the currentpathnameplus the preserved original query. Query comes from theINITIAL_SEARCHsnapshot (taken inmain()), because the Dioxus router strips the livelocation.searchduring init. Returns""for the auth-plumbing routes (/login,/auth/callback, root) and off-wasm.current_return_to()tostart_login, so the requested deep link survives the authorize round-trip./auth/callbackrestores a concrete same-originreturn_tovialocation.set_href. The token bundle is already saved tosessionStoragejust above (lines 78-86), sorehydrate_from_storagere-authes the rebooted tree on the next boot - no re-login loop. Empty /"/"still router-push toDashboard(no reload), and a protocol-relative//hostis rejected (off-origin guard). A leading single/constrains the target to a same-origin path, so no scheme injection is possible.Test
just pre-commitgreen:cargo fmt --all --check,cargo clippy --all-targets -- -D warnings,cargo check --target wasm32-unknown-unknown,cargo test --lib(184 passed).goto('/tickets/new')as a regression guard.Discovered while verifying PMS-519 (mokosh-server e2e).
Self-review of the prior commit caught a regression: the interactive /login flow passes start_login(cfg, "/dashboard"), and the callback's new same-origin branch hard-navigated it via location.set_href - a redundant full-page reload (the callback is already a fresh boot) where the old code did a soft navigator.push(Dashboard). - Extract the wasm-free logic into pure, unit-tested helpers: sanitize_return_to(path, search) (the capture-side filter) and classify_return_to(return_to) -> ReturnTarget { Dashboard, Restore } (the callback-side decision). is_auth_plumbing is shared. - classify_return_to keeps "/dashboard" (plus "", "/", off-origin, protocol-relative, scheme, and the auth-plumbing routes) on the soft Dashboard push; only a concrete same-origin deep link is Restore (hard nav). /auth/callback now matches on it. - Add 5 unit tests: concrete deep links restore; /dashboard + empty + "/" stay soft (regression guard); //host, cross-origin, javascript:, and /login + /auth/callback all fall back to Dashboard. #MAPPS-323