Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle cross-origin redirects in server function redirect hook #2329

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

haslersn
Copy link
Contributor

Fixes #2269

In client-side navigation we now handle redirects returned from server functions by resolving the location against the current origin as a base. The base is only relevant if the location doesn't already include an origin. This fixes cross-origin redirects.

Note: in order to handle redirects in the same way as the browser would handle them, we need to use the server function's URL (typically <origin>/api/something) as a base. I leave this as a TODO for a future leptos version, because it probably requires changing the signature of the server_fn redirect hook.

In order to not be affected by a future breaking change, users should already start making sure that their redirect locations either include an origin or at least start with a single slash (e.g. Location: /foo).

In client-side navigation we now handle redirects returned from
server functions by resolving the location against the current
origin as a base. The base is only relevant if the location
doesn't already include an origin. This fixes cross-origin
redirects.

Note: in order to handle redirects in the same way as the browser
would handle them, we need to use the server function's URL
(typically `<origin>/api/something`) as a base. I leave this as
a TODO for a future leptos version, because it probably
requires changing the signature of the `server_fn` redirect hook.

In order to not be affected by a future breaking change, users
should already start making sure that their redirect locations
either include an origin or at least start with a single slash
(e.g. `Location: /foo`).
@gbj
Copy link
Collaborator

gbj commented Feb 17, 2024

Okay, this looks good — Thank you!

@gbj gbj merged commit 001ca51 into leptos-rs:main Feb 17, 2024
60 checks passed
@haslersn haslersn deleted the fix-2269-prelim branch February 18, 2024 17:10
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.

Server actions: redirect to different origin does not work in HTTPS scenario
2 participants