Repository navigation
fix(auth): preserve safe login redirect path - #1522
Conversation
Honor safe internal ?redirect= targets after login and tenant selection so signing in from /customer-display returns to /customer-display instead of falling back to /pos. Fixes #1514
…splay tenant redirect
…afe redirect fallback
|
ⓘ Your Qodo trial ends soon. Ask your workspace admin to set up billing to keep reviews running after the trial. Manage billing |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
PR Summary by QodoPreserve safe customer-display redirects after login
AI Description
Diagram
High-Level Assessment
Files changed (6)
|
Code Review by Qodo
1. Login drops deep-link settings
|
Fixes #1514
Intent
also for customer diaplay in settings it shows: http://10.0.0.37:3001/customer-display/
but when i click on it, if i have to login etc and on login it does not keep path and goes back to pos?
What Changed
resolveSafeRedirectinAuthGuardand wired/auth/loginto navigate to a validated internal?redirect=path after authentication and tenant selection instead of always falling back togetLandingPage./customer-displayto redirect signed-in users without a selected tenant to/auth/login?select_tenant=true&redirect=/customer-displaywhen no paired display token is present.resolveSafeRedirect,/customer-displaylogin and tenant-selection redirects, and fallback handling for unsafe redirect targets, and updateddocs/architecture/frontend.md.Risk Assessment
✅ Low: The change cleanly preserves and validates same-origin login and tenant-selection redirects from /customer-display with deterministic and E2E test coverage.
Testing
Ran the deterministic auth UI unit suite (
npm run test:auth-ui-deterministic), built the backend and static desktop frontend (npm run build && npm run build:frontend), executed all 5 end-to-end tests infrontend/e2e/customer-display-pairing.spec.tsagainst an isolated server instance on ports 43101-43103, and drove 3 live Chromium scenarios on ports 43201-43203 with 4 screenshot artifacts captured in the evidence directory; all checks and scenarios passed.Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
frontend/src/components/layout/AuthGuard.tsx:178- InAuthGuard.tsx:178-186, the new?redirect=preservation underelse if (!currentTenant)is placed afterif (isPublicPath) return;(AuthGuard.tsx:172), while both/customer-displayand/auth/loginare inPUBLIC_PATHS(AuthGuard.tsx:54-55). As a result,AuthGuardnever executes this branch on/customer-displayor/auth/login(and non-public routes like/posdo not carry?redirect=inwindow.location.search). Meanwhile,CustomerDisplayPage(frontend/src/app/customer-display/page.tsx:768-772) only redirects whenpairedToken === null && !authLoading && !user, even thoughfrontend/src/app/customer-display/page.tsx:776andfrontend/src/app/customer-display/page.tsx:848require bothuserandcurrentTenant. Concrete sequence: when an unpaired browser has a valid multi-tenant token inlocalStoragewithout a selected tenant (user !== null,currentTenant === null,authLoading === false) and opens/customer-display/, neitherAuthGuardnorCustomerDisplayPageredirects to/auth/login?select_tenant=true&redirect=/customer-display, leaving/customer-display/stuck on the loading screen atfrontend/src/app/customer-display/page.tsx:848. Redirect fromCustomerDisplayPagewhenpairedToken === null && !authLoading && (!user || !currentTenant)(using/auth/login?select_tenant=true&redirect=/customer-displaywhenuseris present) and remove the unreachablewindow.location.search?redirect=lookup inAuthGuard.tsx:178-186(updatingtests/auth-ui-deterministic.test.ts:886-935accordingly).frontend/src/components/layout/AuthGuard.tsx:40-resolveSafeRedirect(frontend/src/components/layout/AuthGuard.tsx:37-48, consumed atfrontend/src/app/auth/login/page.tsx:156) only checkstrimmed.startsWith('//') || trimmed.startsWith('/\\')after.trim(), without rejecting embedded ASCII control characters (\t,\r,\n) or backslashes. For a concrete input such asraw = '/\t/evil.com'or'/\n\\evil.com',trimmed.startsWith('//')andtrimmed.startsWith('/\\')are bothfalse, soresolveSafeRedirectreturns'/\t/evil.com'; the WHATWG URL parser strips ASCII tab/CR/LF before parsing, resolving'/\t/evil.com'against the current origin tohttp://evil.com/. Reject control characters and backslashes (and verify same-origin pathname resolution vianew URL(trimmed, 'http://localhost')) inresolveSafeRedirect.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
npm run test:auth-ui-deterministicnpm run build && npm run build:frontendcd frontend && CI=1 E2E_BASE_URL=http://127.0.0.1:43101 E2E_KDS_BASE_URL=http://127.0.0.1:43102 E2E_SERVER_APP_BASE_URL=http://127.0.0.1:43103 npx playwright test e2e/customer-display-pairing.spec.ts --config=playwright.config.ts --project=chromium --retries=0Live Chromium Playwright run against isolatedtests/e2e-server.cjson ports 43201-43203 capturing screenshots for unauthenticated/customer-display/login redirect,select_tenant=true&redirect=/customer-displaytenant selection redirect, and unsafe?redirect=fallback to/pos✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.