Skip to content

Fix publicPath URL duplication when prefix appears as substring#3393

Open
laurakwhit wants to merge 4 commits into
mainfrom
fix/custom-paths
Open

Fix publicPath URL duplication when prefix appears as substring#3393
laurakwhit wants to merge 4 commits into
mainfrom
fix/custom-paths

Conversation

@laurakwhit
Copy link
Copy Markdown
Collaborator

@laurakwhit laurakwhit commented May 13, 2026

Description & motivation 💭

The substring /custom is short and generic enough to appear inside a URL path other than at position 0 (e.g. asset chunks like /_app/immutable/chunks/custom-XXXXX.js). Any time the middleware saw a request whose RequestURI contained /custom somewhere past position 0, it rewrote the req.URL to just the suffix and threw away the prefix. That mangled URL.Path then drove the redirect logic in buildUIIndexHandler.

This PRs fixes this by

  • Always reading RequestURI(which middleware doesn't touch) instead of a mix of RequestURI and URL.Path
  • Consolidating prefix check via hasPathPrefix(handles exact paths and sub-paths)
  • Anchoring the rewrite regex at the start by changing route.PublicPath to use middleware.RewriteWithConfig{ RegexRules: ... } with an explicitly-anchored pattern (^/custom/(.*?)$) to prevent the substring matching

It also inlines resolve() into withPrefix() so deprecated base path is no longer needed.

Note: 308 is cached aggressively by browsers. Once a wrong redirect target is cached, the doubled URL sticks around until cache is cleared.

Screenshots (if applicable) 📸

Design Considerations 🎨

Testing 🧪

How was this tested 👻

  • Manual testing
  • E2E tests added
  • Unit tests added

Steps for others to test: 🚶🏽‍♂️🚶🏽‍♀️

pnpm test src/lib/utilities/route-for-base-path.test.ts

pnpm test src/lib/utilities/route-for.test.ts

cd server && go test ./server/route/...

Run the following ⬇️

cd server

pnpm build:server 
pnpm dev:ui-server

docker build -t temporal-ui-local .
docker run -p 5252:8080 -e TEMPORAL_UI_PUBLIC_PATH=/custom -e TEMPORAL_ADDRESS=host.docker.internal:7233 temporal-ui-local

Then go to http://localhost:5252

  • Verify it redirects to /custom and does not cause an infinite loop
  • Verify /namespaces redirects to /custom/namespaces

Clear browser cache and then run the following (without a publicPath set) ⬇️

docker run -p 5252:8080 -e TEMPORAL_ADDRESS=host.docker.internal:7233 temporal-ui-local

Then go to http://localhost:5252

  • Verify the route works as expected

Checklists

Draft Checklist

Merge Checklist

Issue(s) closed

Docs

Any docs updates needed?

@laurakwhit laurakwhit requested a review from a team as a code owner May 13, 2026 20:46
@vercel
Copy link
Copy Markdown

vercel Bot commented May 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
holocene Ready Ready Preview, Comment May 13, 2026 8:46pm

Request Review

@laurakwhit laurakwhit linked an issue May 13, 2026 that may be closed by this pull request
Comment thread server/server/route/ui.go
if rawQuery != "" {
target += "?" + rawQuery
}
return c.Redirect(http.StatusPermanentRedirect, target)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should consider changing this to a 307 vs. a 308. Currently, any changes to the public path after rollout will require users to clear cached redirects.

@laurakwhit laurakwhit requested a review from rossnelson May 13, 2026 21:57
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.

Broken UI when using custom path since 2.48.1

1 participant