fix: use public base URL for login redirects - #567
Open
bionicman wants to merge 1 commit into
Open
Conversation
Use the configured public origin for self-hosted login redirects so standalone deployments do not expose their internal listener URL. Preserve the request URL fallback when no public base URL is configured.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In a self-hosted standalone deployment behind a reverse proxy, Next.js constructs the middleware request URL from the internal listener address. As a result, visiting
/could redirect users to an internal URL such ashttps://localhost:3000/login, even when the proxy forwards the public host and protocol correctly.Use the configured
NEXT_PUBLIC_BASE_URLas the origin for the self-hosted login redirect. This is already Kan's canonical installation URL and is also used by the authentication setup and other absolute links. The request URL remains the fallback when the public base URL is missing or empty.This deliberately does not derive the redirect target from
HostorX-Forwarded-Host, which would require an explicit trusted-proxy boundary and could otherwise allow host-header-driven redirects.Reproduction
Run the standalone server behind a TLS-terminating reverse proxy and request
/with a public host:curl -I -H 'Host: kan.example.com' -H 'X-Forwarded-Proto: https' http://127.0.0.1:3000/Before this change, the response points to the internal listener:
Location: https://localhost:3000/loginAfter this change, with
NEXT_PUBLIC_BASE_URL=https://kan.example.com:Location: https://kan.example.com/loginType of change
Checklist
Testing
pnpm --filter @kan/web test— 11 tests passedgit diff --check upstream/main...HEADLinked issue
Not applicable: this is a self-hosting bug fix and does not change intended product behavior.