Skip to content

Conversation

@greenlynx
Copy link

Fixes #85462

@ijjk ijjk added the type: next label Dec 1, 2025
@ijjk
Copy link
Member

ijjk commented Dec 1, 2025

Allow CI Workflow Run

  • approve CI run for commit: dd1ac32

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ijjk
Copy link
Member

ijjk commented Dec 1, 2025

Allow CI Workflow Run

  • approve CI run for commit: b5c0bf9

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer


res.setHeader(
'Location',
appRelativeRedirectUrl?.toString() ?? redirectUrl
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
appRelativeRedirectUrl?.toString() ?? redirectUrl
appRelativeRedirectUrl
? `${appRelativeRedirectUrl.pathname}${appRelativeRedirectUrl.search}${appRelativeRedirectUrl.hash}`
: redirectUrl

The Location header is being set to the full URL string including a dummy protocol/host (e.g., http://n/path) instead of just the pathname and search/hash. This will cause redirects to fail or behave unexpectedly.

View Details

Analysis

Location header includes invalid dummy host instead of just pathname

What fails: MPA (Multi-Page Application) action redirects set Location header to full URL with dummy host http://n/path instead of just /path

How to reproduce: In packages/next/src/server/app-render/action-handler.ts, when an MPA Server Action redirects with redirect('/'), the Location header is set using appRelativeRedirectUrl?.toString() which includes the dummy host used for URL parsing.

Result: Location header is set to http://n/path?query#hash instead of /path?query#hash. Browsers attempting to follow this redirect would try to connect to host "n" and fail.

Expected: According to RFC 7231, the Location header should contain either:

  • An absolute URI with real host: https://example.com/path
  • A URI-reference (pathname-only): /path

The code already demonstrates the correct pattern in lines 283 and 344, where it accesses pathname, search, and hash properties directly instead of calling .toString() on the URL object.

Fix: Changed line 1096 from appRelativeRedirectUrl?.toString() ?? redirectUrl to:

appRelativeRedirectUrl
  ? ` 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pre-hydration redirect from server actions does not prepend base path

2 participants