fix: fixed logout url issue#12
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes the post-logout redirect host rewriting so the redirect goes to the correct platform portal domain by making the first DNS label configurable via SMB_NAME/NEXT_PUBLIC_SMB_NAME (defaulting to moneta).
Changes:
- Update logout redirect host rewriting to use
NEXT_PUBLIC_SMB_NAME(defaultmoneta). - Add runtime placeholder substitution support for
NEXT_PUBLIC_SMB_NAMEin the web Docker entrypoint and Dockerfile. - Wire
SMB_NAME/NEXT_PUBLIC_SMB_NAMEthrough Docker Compose and document it in.env.examplefiles.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| surfsense_web/lib/auth-utils.ts | Uses NEXT_PUBLIC_SMB_NAME to rewrite logout redirect host. |
| surfsense_web/docker-entrypoint.js | Adds placeholder replacement for __NEXT_PUBLIC_SMB_NAME__ using SMB_NAME/NEXT_PUBLIC_SMB_NAME. |
| surfsense_web/Dockerfile | Introduces build arg/env placeholder for NEXT_PUBLIC_SMB_NAME. |
| surfsense_web/.env.example | Documents NEXT_PUBLIC_SMB_NAME for local development. |
| docker/docker-compose.yml | Provides SMB_NAME to the web container in production compose. |
| docker/docker-compose.dev.yml | Adds NEXT_PUBLIC_SMB_NAME build arg wiring for dev compose builds. |
| docker/.env.example | Documents SMB_NAME for Docker-based deployments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const portalHost = window.location.hostname.replace(/^[^.]*\./, "moneta."); | ||
| // Docker: set SMB_NAME on the container; docker-entrypoint substitutes NEXT_PUBLIC_SMB_NAME. | ||
| // Local dev: set NEXT_PUBLIC_SMB_NAME in .env (default moneta). | ||
| const smbLabel = process.env.NEXT_PUBLIC_SMB_NAME?.trim() || "moneta"; |
There was a problem hiding this comment.
smbLabel is interpolated directly into the redirect host. If it contains dots, slashes, @, or other URL-special characters, this can produce an unexpected cross-domain redirect or an invalid URL. Consider validating it as a single DNS label (e.g., /^[a-z0-9-]+$/i) and falling back to the default when it doesn’t match.
| const smbLabel = process.env.NEXT_PUBLIC_SMB_NAME?.trim() || "moneta"; | |
| const rawSmbLabel = process.env.NEXT_PUBLIC_SMB_NAME?.trim(); | |
| const smbLabel = | |
| rawSmbLabel && /^(?!-)[a-z0-9-]{1,63}(?<!-)$/i.test(rawSmbLabel) ? rawSmbLabel : "moneta"; |
| // Local dev: set NEXT_PUBLIC_SMB_NAME in .env (default moneta). | ||
| const smbLabel = process.env.NEXT_PUBLIC_SMB_NAME?.trim() || "moneta"; | ||
| const portalHost = window.location.hostname.replace(/^[^.]*\./, `${smbLabel}.`); | ||
| window.location.href = `${window.location.protocol}//${portalHost}`; |
There was a problem hiding this comment.
The redirect uses window.location.hostname (no port) and builds protocol//host, which drops any non-default port the app is running on. This can break setups where SurfSense is accessed via an explicit port (e.g. localhost:3000 / mapped Docker ports). Consider preserving window.location.port when present (or using window.location.host and rewriting just the hostname portion).
| window.location.href = `${window.location.protocol}//${portalHost}`; | |
| const portSuffix = window.location.port ? `:${window.location.port}` : ""; | |
| window.location.href = `${window.location.protocol}//${portalHost}${portSuffix}`; |
|
Reviewed against the sso-rules invariant we merged in awais786/sso-rules#1 (required env, no default, fail loudly) and the sibling PRs in Outline #10 / Penpot #11 / Twenty #2 (all fail-fast). Closed my parallel PR #11 in favor of this one — your compose coverage ( The headline blocker is the
Concrete changes
const smbName = process.env.NEXT_PUBLIC_SMB_NAME!.trim();
if (!process.env.SMB_NAME && process.env.NEXT_PUBLIC_FASTAPI_BACKEND_AUTH_TYPE === "SSO") {
console.error("[entrypoint] ERROR: SMB_NAME env is required when AUTH_TYPE=SSO.");
console.error("[entrypoint] Set it to the portal hostname prefix (e.g. 'moneta').");
process.exit(1);
}
// ...
["__NEXT_PUBLIC_SMB_NAME__", process.env.SMB_NAME || ""],
Nits
Suggested pathEither: (a) push the changes above and merge as-is, or (b) merge today to unblock the cutover and land a small follow-up PR with the fail-fast + drop-defaults changes. I'm happy to open the follow-up if (b) is the call. |
Drops the SMB_NAME / NEXT_PUBLIC_SMB_NAME plumbing introduced for the
post-logout portal redirect. The previous approach required threading
the value through three files (.env.example → Dockerfile build-arg →
docker-entrypoint.js placeholder substitution → bundle); any broken
link silently routed logout to the wrong host.
Switching to a regex on window.location.hostname removes the env
dependency and works for any `<prefix>-<app>.<domain>` shape:
- foss-research.local.moneta.dev → foss.local.moneta.dev
- moneta-research.askii.ai → moneta.askii.ai
Reverts: docker/.env.example, docker/docker-compose*.yml,
surfsense_web/{.env.example,Dockerfile,docker-entrypoint.js} to upstream.
Description
Replace moneta value from SMB_NAME env var in logout urls.
Motivation and Context
FIX #
Screenshots
API Changes
Change Type
Testing Performed
Checklist