@remix-run/router 1.23.1-pre-v6.0 → 1.23.2-pre-v6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/router.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.23.1-pre-v6.0
2
+ * @remix-run/router v1.23.2-pre-v6.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -2122,7 +2122,7 @@ function createRouter(init) {
2122
2122
  // If the user didn't explicity indicate replace behavior, replace if
2123
2123
  // we redirected to the exact same location we're currently at to avoid
2124
2124
  // double back-buttons
2125
- let location = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename);
2125
+ let location = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename, init.history);
2126
2126
  replace = location === state.location.pathname + state.location.search;
2127
2127
  }
2128
2128
  await startRedirectNavigation(request, result, true, {
@@ -2728,7 +2728,7 @@ function createRouter(init) {
2728
2728
  }
2729
2729
  let location = redirect.response.headers.get("Location");
2730
2730
  invariant(location, "Expected a Location header on the redirect Response");
2731
- location = normalizeRedirectLocation(location, new URL(request.url), basename);
2731
+ location = normalizeRedirectLocation(location, new URL(request.url), basename, init.history);
2732
2732
  let redirectLocation = createLocation(state.location, location, {
2733
2733
  _isRedirect: true
2734
2734
  });
@@ -4434,16 +4434,30 @@ function normalizeRelativeRoutingRedirectResponse(response, request, routeId, ma
4434
4434
  }
4435
4435
  return response;
4436
4436
  }
4437
- function normalizeRedirectLocation(location, currentUrl, basename) {
4437
+ function normalizeRedirectLocation(location, currentUrl, basename, historyInstance) {
4438
+ // Match Chrome's behavior:
4439
+ // https://github.com/chromium/chromium/blob/216dbeb61db0c667e62082e5f5400a32d6983df3/content/public/common/url_utils.cc#L82
4440
+ let invalidProtocols = ["about:", "blob:", "chrome:", "chrome-untrusted:", "content:", "data:", "devtools:", "file:", "filesystem:",
4441
+ // eslint-disable-next-line no-script-url
4442
+ "javascript:"];
4438
4443
  if (ABSOLUTE_URL_REGEX.test(location)) {
4439
4444
  // Strip off the protocol+origin for same-origin + same-basename absolute redirects
4440
4445
  let normalizedLocation = location;
4441
4446
  let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
4447
+ if (invalidProtocols.includes(url.protocol)) {
4448
+ throw new Error("Invalid redirect location");
4449
+ }
4442
4450
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4443
4451
  if (url.origin === currentUrl.origin && isSameBasename) {
4444
4452
  return url.pathname + url.search + url.hash;
4445
4453
  }
4446
4454
  }
4455
+ try {
4456
+ let url = historyInstance.createURL(location);
4457
+ if (invalidProtocols.includes(url.protocol)) {
4458
+ throw new Error("Invalid redirect location");
4459
+ }
4460
+ } catch (e) {}
4447
4461
  return location;
4448
4462
  }
4449
4463
  // Utility method for creating the Request instances for loaders/actions during