@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/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # `@remix-run/router`
2
2
 
3
- ## 1.23.1-pre-v6.0
3
+ ## 1.23.2-pre-v6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Validate redirect locations ([#14707](https://github.com/remix-run/react-router/pull/14707))
8
+
9
+ ## 1.23.1
4
10
 
5
11
  ### Patch Changes
6
12
 
@@ -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
  *
@@ -2531,7 +2531,7 @@ function createRouter(init) {
2531
2531
  // If the user didn't explicity indicate replace behavior, replace if
2532
2532
  // we redirected to the exact same location we're currently at to avoid
2533
2533
  // double back-buttons
2534
- let location = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename);
2534
+ let location = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename, init.history);
2535
2535
  replace = location === state.location.pathname + state.location.search;
2536
2536
  }
2537
2537
  await startRedirectNavigation(request, result, true, {
@@ -3171,7 +3171,7 @@ function createRouter(init) {
3171
3171
  }
3172
3172
  let location = redirect.response.headers.get("Location");
3173
3173
  invariant(location, "Expected a Location header on the redirect Response");
3174
- location = normalizeRedirectLocation(location, new URL(request.url), basename);
3174
+ location = normalizeRedirectLocation(location, new URL(request.url), basename, init.history);
3175
3175
  let redirectLocation = createLocation(state.location, location, {
3176
3176
  _isRedirect: true
3177
3177
  });
@@ -4954,16 +4954,30 @@ function normalizeRelativeRoutingRedirectResponse(response, request, routeId, ma
4954
4954
  }
4955
4955
  return response;
4956
4956
  }
4957
- function normalizeRedirectLocation(location, currentUrl, basename) {
4957
+ function normalizeRedirectLocation(location, currentUrl, basename, historyInstance) {
4958
+ // Match Chrome's behavior:
4959
+ // https://github.com/chromium/chromium/blob/216dbeb61db0c667e62082e5f5400a32d6983df3/content/public/common/url_utils.cc#L82
4960
+ let invalidProtocols = ["about:", "blob:", "chrome:", "chrome-untrusted:", "content:", "data:", "devtools:", "file:", "filesystem:",
4961
+ // eslint-disable-next-line no-script-url
4962
+ "javascript:"];
4958
4963
  if (ABSOLUTE_URL_REGEX.test(location)) {
4959
4964
  // Strip off the protocol+origin for same-origin + same-basename absolute redirects
4960
4965
  let normalizedLocation = location;
4961
4966
  let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
4967
+ if (invalidProtocols.includes(url.protocol)) {
4968
+ throw new Error("Invalid redirect location");
4969
+ }
4962
4970
  let isSameBasename = stripBasename(url.pathname, basename) != null;
4963
4971
  if (url.origin === currentUrl.origin && isSameBasename) {
4964
4972
  return url.pathname + url.search + url.hash;
4965
4973
  }
4966
4974
  }
4975
+ try {
4976
+ let url = historyInstance.createURL(location);
4977
+ if (invalidProtocols.includes(url.protocol)) {
4978
+ throw new Error("Invalid redirect location");
4979
+ }
4980
+ } catch (e) {}
4967
4981
  return location;
4968
4982
  }
4969
4983