Repository navigation
Conversation
Author
|
CI shows I pre-ran the equivalent checks locally at this exact head (
Happy to adjust anything if you'd rather see a different shape. |
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.
Summary
Operators sometimes publish the admin console and the backend API under path prefixes of one shared hostname (for example
https://console.example.com/gateway/tokenhuband.../gateway/tokenhub-api). Today that layout breaks in several places: Next.js has nobasePath, absolute asset URLs escape the prefix,new URL()rejects a relative API base, the OAuth binding cookie is scoped to a fixed path, and CORS compares a browserOrigin(which has no path) against the full public base URL. This PR makes sub-path deployment work with configuration only.Related Issue
N/A
Changes
TOKENHUB_FRONTEND_BASE_PATHsupport viabasePathinfrontend/next.config.ts, plus root redirects that keep bare URLs working and never rewrite already-prefixed ones.frontend/lib/base-path.tsand apply it to hard-coded/brand/...and/provider-icons/...asset references, which Next does not rewrite.TOKENHUB_API_BASE_URLresolves against the page origin instead of throwing.backend/Dockerfile, all three Compose files,start.sh, and both.env.examplefiles; register the variable intools/env-contract.mjs.Type of Change
Verification
go build ./...go test ./internal/server/ -run 'TestOAuthSubpath|TestCORSDerivesOriginFromPrefixedPublicBaseURL|TestOAuthCallbackURLUsesOnlyConfiguredOrTrustedOrigins' -count=1node --test tools/*.test.mjs— 205 passednode tools/check-env-contract.mjsnode tools/check-doc-translations.mjs --base origin/main --head HEADnpm run test:domain— 198 passed;npm run typecheck;npm run lintTOKENHUB_FRONTEND_BASE_PATH=/gateway/tokenhub npm run build— build succeeds and.next/required-server-files.jsonreports the expectedbasePathgit diff --checkNot covered here: the RSC prefetch/proxy change from the same internal branch, which is a separate concern.
Compatibility, Security, and Operations
TOKENHUB_FRONTEND_BASE_PATHis build-time only; a prebuilt image cannot pick it up at runtime, so the image must be rebuilt to change it. Leaving it empty preserves current behavior in every code path touched here.The OAuth callback cookie is now scoped to the stored redirect URI's path rather than a fixed constant. For deployments without a path prefix the computed value is identical to the previous constant, so existing flows and cookies are unaffected.
CORS behavior changes only when
TOKENHUB_PUBLIC_BASE_URLcarries a path: the allowlist entry becomes the origin, which is what browsers send. An unparsableTOKENHUB_PUBLIC_BASE_URLnow fails closed instead of being treated as a literal allowed origin indev.Serving two applications from one origin means they share the browser security boundary; a sibling application's script can read same-origin storage in the same tab. The docs call this out and recommend a separate hostname when that trust is unacceptable.
Checklist
.envfiles, databases, backups, or runtime logs are included.start.sh, and deployment documentation where applicable.data/model-catalog.yamlremains tracked and catalog changes were reviewed where applicable.git diff --checkpasses.