fix: serve an origin-relative base href - #356
Open
frdm666 wants to merge 1 commit into
Open
Conversation
Dekaf rendered a blank page with "Uncaught DOMException: The operation is insecure." whenever it was opened on a host other than the one in DEKAF_PUBLIC_BASE_URL - for example reaching a container published as 127.0.0.1:8091 via localhost, or running behind a reverse proxy. The page set an absolute <base href> built from DEKAF_PUBLIC_BASE_URL. Browsers resolve history.pushState() URLs against the document base URL, so react-router ended up pushing a URL on a different origin, which throws a SecurityError and kills the app while it mounts. Serve the path part of the public base URL as the base href instead, and build the gRPC-web and pulsar-auth URLs from the current origin, so the UI works on whatever host it is actually reached at. Paths under a reverse proxy prefix keep working, as the prefix is preserved. Fixes visortelle#349
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.
Problem
Dekaf renders a blank page when opened on a host other than the one in
DEKAF_PUBLIC_BASE_URL— e.g., a container published as127.0.0.1:8091butreached via
localhost:8091.The page carried an absolute
<base href>built from that setting, and thebrowser resolves everything relative against it. Two failure modes, depending on
whether that host is reachable from the client:
<script src="ui/static/dist/entrypoint.js">resolves tothe user's own machine:
Uncaught ReferenceError: pulsarUiEntrypoint is not defined.react-router calls
history.pushState()with a foreign-origin URL, whichbrowsers forbid:
Uncaught DOMException: The operation is insecure.Either way, the app dies while mounting, with no hint about what to fix.
What changed
DEKAF_PUBLIC_BASE_URLas the base href (/,or
/dekaf/behind a reverse-proxy prefix). A path always resolves against theorigin the page came from, so no mismatch is possible.
basePathfield on the UI config) — otherwise the app would render but failevery request with CORS.
Reverse-proxy prefixes still work:
DEKAF_PUBLIC_BASE_URL=http://localhost:8090/demoserves
<base href="/demo/" />.Test plan
Added
NAV-16(e2e/src/test/scala/routes/BasePathSpec.scala): opens Dekaf on127.0.0.1while the server is configured forlocalhost, asserts the UI rendersand that no
SecurityErroris raised. It navigates to/on purpose — the rootredirect is what triggers the failing history call; going straight to
/overviewpasses even with the bug.
Verified it fails without the fix. Also re-ran
OverviewSmokeSpec,NavigationSpec,CredentialsSpec,HealthCheckSpec— 10 tests, all green.Fixes #349