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

Respect redirects to external url destinations #4579

Conversation

cephalization
Copy link
Contributor

@cephalization cephalization commented Nov 11, 2022

redirect('https://www.google.com/') should go to http://www.google.com/

We should not prepend the request origin to the destination URL if they are external.

Closes: #4570

  • Docs
  • Tests

Testing Strategy:

New and existing integration tests pass. Still need to copy build into my remix app to test there.

redirect('https://www.google.com/') should go to http://www.google.com/

We should not prepend the request origin to the destination URL if they
are external.
@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2022

⚠️ No Changeset found

Latest commit: f8397a9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 11, 2022

Hi @cephalization,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@cephalization
Copy link
Contributor Author

cephalization commented Nov 11, 2022

This is a very naïve PR but it reflects my desired behavior of remix redirect.

I am sure there are changes to be made to make this scalable, particularly around the startsWith('http") call.

Just wanted to get this draft up to show that I am working on this.

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Nov 11, 2022

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@machour machour linked an issue Nov 11, 2022 that may be closed by this pull request
@brophdawg11 brophdawg11 self-assigned this Nov 14, 2022
@brophdawg11 brophdawg11 marked this pull request as ready for review November 14, 2022 20:07
@brophdawg11
Copy link
Contributor

Thanks @cephalization! For ease of ongoing dev during this transition of Remix onto RR 6.4, we are temporarily keeping a duplicate copy of the @remix-run/router code inside the Remix repo. I fixed this over at the source in remix-run/react-router#9590 (in a slightly different manner) but we definitely want to keep this new integration test you added here! Once we get that PR merged, I'll get this PR synced up with the router changes and get this merged as well 👍

@@ -817,7 +817,8 @@ export function resolvePath(to: To, fromPathname = "/"): Path {
} = typeof to === "string" ? parsePath(to) : to;

let pathname = toPathname
? toPathname.startsWith("/")
? // we don't want to prepend the fromPathname on root or external toPathnames'
toPathname.startsWith("/") || toPathname.startsWith("http")
Copy link
Collaborator

Choose a reason for hiding this comment

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

@brophdawg11 do we want to accept other protocols? (app:// itunes:// ..)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah definitely. I did this in RR the way it's checked in Remix today which should account for other protocols: https://github.com/remix-run/react-router/pull/9590/files#diff-c6f085a772081501e6db2af3eee90b15fe7cd7c965d2f220c2a3c5c7772bc0c4R2568

@cephalization
Copy link
Contributor Author

Thanks @cephalization! For ease of ongoing dev during this transition of Remix onto RR 6.4, we are temporarily keeping a duplicate copy of the @remix-run/router code inside the Remix repo. I fixed this over at the source in remix-run/react-router#9590 (in a slightly different manner) but we definitely want to keep this new integration test you added here! Once we get that PR merged, I'll get this PR synced up with the router changes and get this merged as well 👍

Awesome, thanks! Just ping me when/where I can help.

@brophdawg11
Copy link
Contributor

Looks like this got automatically closed when we merged/deleted the other branch. I cherry-picked these commits into #4627 so @cephalization keeps the authorship of them!

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.

Broken Routing: Remix + React Router integration branch
5 participants