@zubra/router 6.0.5 → 6.0.6
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/package.json +1 -1
- package/src/answers.js +6 -2
package/package.json
CHANGED
package/src/answers.js
CHANGED
|
@@ -15,10 +15,14 @@ export function checkedLocation({ location, external }, url) {
|
|
|
15
15
|
throw new RouteError(`redirect() to ${JSON.stringify(location)}: not a URL`);
|
|
16
16
|
}
|
|
17
17
|
if (!['http:', 'https:'].includes(target.protocol)) throw new RouteError(`redirect() to a ${target.protocol} URL is refused`);
|
|
18
|
-
|
|
18
|
+
// This host by http or https is this site: behind a proxy that ends TLS, the request's URL is
|
|
19
|
+
// http:// while the page is https://. It's written as a path, so the browser stays on the
|
|
20
|
+
// scheme it's on (an http:// location never takes an https page down to http).
|
|
21
|
+
const here = target.host === url.host;
|
|
22
|
+
if (!here && !external) throw new RouteError(`redirect() to ${target.origin}, another site: say redirect(to, { external: true }) if that's meant`);
|
|
19
23
|
// A path on this site that begins `//` (from `https://site//evil.example`, `.//evil.example` or
|
|
20
24
|
// `..//evil.example`) is protocol-relative in a Location header: one slash keeps it here.
|
|
21
|
-
return
|
|
25
|
+
return here ? '/' + (target.pathname + target.search + target.hash).replace(/^[/\\]+/, '') : target.href;
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
/** `return notFound()`: the path has nothing behind it (no such farm). The response is a 404. */
|