Skip to content

fix(logout): use NEXT_PUBLIC_LOGOUT_REDIRECT_URL env, drop hostname regex#17

Closed
awais786 wants to merge 1 commit into
foss-mainfrom
fix/logout-use-env-url
Closed

fix(logout): use NEXT_PUBLIC_LOGOUT_REDIRECT_URL env, drop hostname regex#17
awais786 wants to merge 1 commit into
foss-mainfrom
fix/logout-use-env-url

Conversation

@awais786

@awais786 awais786 commented May 6, 2026

Copy link
Copy Markdown

Summary

  • Logout was deriving the portal host from `window.location.hostname` via regex. Three regexes have shipped across branches; none covers both deployment shapes.
  • Build pipeline already passes the right URL via `NEXT_PUBLIC_LOGOUT_REDIRECT_URL`. Read it directly — same image works for any hostname layout the deployer configures.
  • If env unset → `console.error` + return `false` instead of redirecting to a broken URL.

Symptom (sandbox)

On `https://research.foss.arbisoft.com\` → logout currently redirects to `https://foss.foss.arbisoft.com/\` (older regex `/^[^.]./, "foss."`) or stays on the same host and re-auths (newer regex `/^[^.]+\.(?=[^.]\.[^.]*\.)/`).

Why regex doesn't cut it

Regex shipped `foss-research.arbisoft.com` (prod) `research.foss.arbisoft.com` (sandbox)
`/^[^.]*./, "foss."` ✅ `foss.arbisoft.com` ❌ `foss.foss.arbisoft.com`
`/^([^-]+)-[^.]+\.(.+)/, "$1.$2"` ✅ `foss.arbisoft.com` ❌ unchanged → re-auth loop
`/^[^.]+\.(?=[^.]\.[^.]\.)/, ""` ❌ unchanged → re-auth loop ✅ `foss.arbisoft.com`

The deployer knows the portal URL. The SPA shouldn't try to guess.

Build wiring already exists

`foss-server-bundle-devstack` Makefile `dev.build.surfsense.web`:
```
docker build … --build-arg NEXT_PUBLIC_LOGOUT_REDIRECT_URL="https://$SMB_NAME.$PLATFORM_DOMAIN" …
```
Same arg is in the Dockerfile (`ARG NEXT_PUBLIC_LOGOUT_REDIRECT_URL=` → baked at build time as `process.env.NEXT_PUBLIC_LOGOUT_REDIRECT_URL`).

Test plan

  • Build image for sandbox (`SMB_NAME=foss`, `PLATFORM_DOMAIN=arbisoft.com`), confirm logout redirects to `https://foss.arbisoft.com/\`.
  • Build image for prod-style host (`PLATFORM_DOMAIN=arbisoft.com`, `SUBDOMAIN_PREFIX=foss-`), confirm logout redirects to `https://foss.arbisoft.com/\`.
  • Build image for local devstack (`PLATFORM_DOMAIN=local.moneta.dev`, `SUBDOMAIN_PREFIX=foss-`, `SMB_NAME=foss`), confirm logout redirects to `https://foss.local.moneta.dev/\`.
  • Build with arg unset → confirm console.error + no redirect.

Follow-ups (separate PRs, same pattern)

  • `Pressingly/plane` `apps/web/core/store/user/index.ts:264` — read `VITE_LOGOUT_REDIRECT_URL`
  • `Pressingly/outline` `app/stores/AuthStore.ts:357` — already has `env.OIDC_LOGOUT_URI` infrastructure; restore it
  • `Pressingly/penpot` `frontend/src/app/main/data/auth.cljs` — read injected `MPASS_SIGNOUT_URL` global from `config.js`

The logout redirect was deriving the portal host from
window.location.hostname via regex. Three different regexes have shipped
across branches, and none cover both deployment shapes:

  foss-research.arbisoft.com    → foss.arbisoft.com   (prod, "<app>-<smb>.<domain>")
  research.foss.arbisoft.com    → foss.arbisoft.com   (sandbox, "<app>.<smb>.<domain>")

Recent regex `/^[^.]+\.(?=[^.]*\.[^.]*\.)/` works for sandbox but
silently no-ops on prod (3-label hostname) → user stays on the app
host → ForwardAuth re-auth loop.
Older regex `/^[^.]*\./, "foss."` works for prod but produces
`foss.foss.arbisoft.com` on sandbox.

The build/deploy pipeline already passes the right URL via
`NEXT_PUBLIC_LOGOUT_REDIRECT_URL` (see
foss-server-bundle-devstack Makefile dev.build.surfsense.web —
`--build-arg NEXT_PUBLIC_LOGOUT_REDIRECT_URL="https://$SMB_NAME.$PLATFORM_DOMAIN"`).
Read it directly. Hostname inspection is no longer involved, so the
same image works for any layout the deployer configures.

If the env var is unset, log and bail out instead of redirecting to a
broken URL — surfaces misconfig immediately.
@awais786 awais786 closed this May 6, 2026
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.

1 participant