Skip to content

Commit 1a16a50

Browse files
authored
Only check for differing origin on absolute URL redirects (#10033)
1 parent 80832fb commit 1a16a50

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.changeset/thirty-frogs-wave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Only check for differing origin on absolute URL redirects

packages/router/router.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ export const IDLE_BLOCKER: BlockerUnblocked = {
621621
location: undefined,
622622
};
623623

624+
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
625+
624626
const isBrowser =
625627
typeof window !== "undefined" &&
626628
typeof window.document !== "undefined" &&
@@ -1915,8 +1917,12 @@ export function createRouter(init: RouterInit): Router {
19151917
"Expected a location on the redirect navigation"
19161918
);
19171919

1918-
// Check if this an external redirect that goes to a new origin
1919-
if (isBrowser && typeof window?.location !== "undefined") {
1920+
// Check if this an absolute external redirect that goes to a new origin
1921+
if (
1922+
ABSOLUTE_URL_REGEX.test(redirect.location) &&
1923+
isBrowser &&
1924+
typeof window?.location !== "undefined"
1925+
) {
19201926
let newOrigin = init.history.createURL(redirect.location).origin;
19211927
if (window.location.origin !== newOrigin) {
19221928
if (replace) {
@@ -3093,10 +3099,8 @@ async function callLoaderOrAction(
30933099
"Redirects returned/thrown from loaders/actions must have a Location header"
30943100
);
30953101

3096-
let isAbsolute = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(location);
3097-
30983102
// Support relative routing in internal redirects
3099-
if (!isAbsolute) {
3103+
if (!ABSOLUTE_URL_REGEX.test(location)) {
31003104
let activeMatches = matches.slice(0, matches.indexOf(match) + 1);
31013105
let routePathnames = getPathContributingMatches(activeMatches).map(
31023106
(match) => match.pathnameBase

0 commit comments

Comments
 (0)