Skip to content

fix: preserve absolute URLs in local proxy query params - #60

Merged
kitfoster merged 3 commits into
mainfrom
fix/local-proxy-preserve-query-urls
Jun 2, 2026
Merged

fix: preserve absolute URLs in local proxy query params#60
kitfoster merged 3 commits into
mainfrom
fix/local-proxy-preserve-query-urls

Conversation

@kitfoster

@kitfoster kitfoster commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #49.

The local proxy was corrupting absolute URLs embedded in query parameters in two places:

  1. Request URL normalizationreplaceAll(/\/[\\/]+/g, '/') ran against the whole URL, collapsing https://https:/ inside query strings. Now scoped to the path portion only via normalizeRepeatedSlashesInPath.
  2. Redirect Location rewriting — the non-anchored regex /https:\/\/[^/]+\// could match https:// later in the header (inside a query param), not just the upstream origin. Replaced with proper URL parsing in rewriteRedirectLocation, which uniformly handles relative and absolute locations and preserves the query without re-corrupting it.

Test plan

  • New unit test: handleRequest does not 307-normalize a request whose query contains an absolute URL.
  • New unit tests for rewriteRedirectLocation covering both a relative Location with an absolute URL in the query and an absolute upstream Location that needs the origin rewritten back to localhost.

@vercel

vercel Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
nextjs-app-docs Ready Ready Preview, Comment Jun 2, 2026 12:23pm
nextjs-app-marketing Ready Ready Preview, Comment Jun 2, 2026 12:23pm
nextjs-pages-blog Ready Ready Preview, Comment Jun 2, 2026 12:23pm
nextjs-pages-dashboard Ready Ready Preview, Comment Jun 2, 2026 12:23pm
react-router-docs Ready Ready Preview, Comment Jun 2, 2026 12:23pm
react-router-vite-base-path Ready Ready Preview, Comment Jun 2, 2026 12:23pm
react-router-web Ready Ready Preview, Comment Jun 2, 2026 12:23pm
single-spa-root Ready Ready Preview, Comment Jun 2, 2026 12:23pm
single-spa-shared Ready Ready Preview, Comment Jun 2, 2026 12:23pm
single-spa-web Ready Ready Preview, Comment Jun 2, 2026 12:23pm
sveltekit-docs Ready Ready Preview, Comment Jun 2, 2026 12:23pm
sveltekit-web Ready Ready Preview, Comment Jun 2, 2026 12:23pm

Request Review

@kitfoster kitfoster changed the title Fix local proxy URL rewrites inside query params fix: preserve absolute URLs in local proxy query params Jun 2, 2026
new URL(loc, 'http://localhost') always yields an http/https URL, so the
guard never falsed. Just assign protocol/host unconditionally.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kitfoster
kitfoster merged commit 5fbc4e3 into main Jun 2, 2026
20 checks passed
@kitfoster
kitfoster deleted the fix/local-proxy-preserve-query-urls branch June 2, 2026 14:19
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.

Local proxy rewrites nested absolute URLs inside redirect query params

2 participants