ras-stack 0.39.0 → 0.39.1
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.
|
@@ -6,10 +6,18 @@ export function canonicalRedirect(requestUrl, options) {
|
|
|
6
6
|
const incoming = new URL(requestUrl);
|
|
7
7
|
if (incoming.host === canonical.host || options.pathsServedOnAnyHost?.has(incoming.pathname))
|
|
8
8
|
return null;
|
|
9
|
+
// A sibling process calling over the loopback interface is not a visitor who typed the wrong hostname.
|
|
10
|
+
// Redirecting it sends an internal request out to the public name, and its client may not follow the
|
|
11
|
+
// redirect, may drop the method, or may not be able to reach that name at all.
|
|
12
|
+
if (loopback(incoming.hostname))
|
|
13
|
+
return null;
|
|
9
14
|
return new URL(incoming.pathname + incoming.search + incoming.hash, canonical.origin).toString();
|
|
10
15
|
}
|
|
11
16
|
catch {
|
|
12
17
|
return null;
|
|
13
18
|
}
|
|
14
19
|
}
|
|
20
|
+
function loopback(hostname) {
|
|
21
|
+
return hostname === 'localhost' || hostname === '[::1]' || /^127(?:\.\d{1,3}){3}$/.test(hostname);
|
|
22
|
+
}
|
|
15
23
|
//# sourceMappingURL=canonical-host.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical-host.js","sourceRoot":"","sources":["../../src/server/canonical-host.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,OAAiC;IACrF,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE;QAAE,OAAO,IAAI,CAAA;IAC9C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAA;QACpC,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,IAAI,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAA;QACzG,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;IAClG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["export type CanonicalRedirectOptions = {\n canonicalUrl?: string\n pathsServedOnAnyHost?: ReadonlySet<string>\n}\n\nexport function canonicalRedirect(requestUrl: string, options: CanonicalRedirectOptions) {\n if (!options.canonicalUrl?.trim()) return null\n try {\n const canonical = new URL(options.canonicalUrl)\n const incoming = new URL(requestUrl)\n if (incoming.host === canonical.host || options.pathsServedOnAnyHost?.has(incoming.pathname)) return null\n return new URL(incoming.pathname + incoming.search + incoming.hash, canonical.origin).toString()\n } catch {\n return null\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"canonical-host.js","sourceRoot":"","sources":["../../src/server/canonical-host.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,iBAAiB,CAAC,UAAkB,EAAE,OAAiC;IACrF,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,IAAI,EAAE;QAAE,OAAO,IAAI,CAAA;IAC9C,IAAI,CAAC;QACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAA;QACpC,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI,IAAI,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAA;QACzG,uGAAuG;QACvG,qGAAqG;QACrG,+EAA+E;QAC/E,IAAI,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAAE,OAAO,IAAI,CAAA;QAC5C,OAAO,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,GAAG,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,CAAA;IAClG,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,QAAgB;IAChC,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnG,CAAC","sourcesContent":["export type CanonicalRedirectOptions = {\n canonicalUrl?: string\n pathsServedOnAnyHost?: ReadonlySet<string>\n}\n\nexport function canonicalRedirect(requestUrl: string, options: CanonicalRedirectOptions) {\n if (!options.canonicalUrl?.trim()) return null\n try {\n const canonical = new URL(options.canonicalUrl)\n const incoming = new URL(requestUrl)\n if (incoming.host === canonical.host || options.pathsServedOnAnyHost?.has(incoming.pathname)) return null\n // A sibling process calling over the loopback interface is not a visitor who typed the wrong hostname.\n // Redirecting it sends an internal request out to the public name, and its client may not follow the\n // redirect, may drop the method, or may not be able to reach that name at all.\n if (loopback(incoming.hostname)) return null\n return new URL(incoming.pathname + incoming.search + incoming.hash, canonical.origin).toString()\n } catch {\n return null\n }\n}\n\nfunction loopback(hostname: string) {\n return hostname === 'localhost' || hostname === '[::1]' || /^127(?:\\.\\d{1,3}){3}$/.test(hostname)\n}\n"]}
|