@cloudflare/pages-shared 0.3.5 → 0.4.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.
|
@@ -11,7 +11,7 @@ function mergeHeaders(base: HeadersInit, extra: HeadersInit) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function stripLeadingDoubleSlashes(location: string) {
|
|
14
|
-
return location.replace(/^(\/|%2F|%2f|%5C|%5c|\\)+(.*)
|
|
14
|
+
return location.replace(/^(\/|%2F|%2f|%5C|%5c|%09|\s|\\)+(.*)/g, "/$2");
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export class OkResponse extends Response {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
SPLAT_REGEX,
|
|
7
7
|
PLACEHOLDER_REGEX,
|
|
8
8
|
} from "./constants";
|
|
9
|
-
import { validateUrl } from "./validateURL";
|
|
9
|
+
import { validateUrl, urlHasHost } from "./validateURL";
|
|
10
10
|
import type {
|
|
11
11
|
InvalidRedirectRule,
|
|
12
12
|
ParsedRedirects,
|
|
@@ -109,6 +109,19 @@ export function parseRedirects(input: string): ParsedRedirects {
|
|
|
109
109
|
continue;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
// We want to always block the `/* /index.html` redirect - this will cause TOO_MANY_REDIRECTS errors as
|
|
113
|
+
// the asset server will redirect it back to `/`, removing the `/index.html`. This is the case for regular
|
|
114
|
+
// redirects, as well as proxied (200) rewrites. We only want to run this on relative urls
|
|
115
|
+
if (/\/\*?$/.test(from) && /\/index(.html)?$/.test(to) && !urlHasHost(to)) {
|
|
116
|
+
invalid.push({
|
|
117
|
+
line,
|
|
118
|
+
lineNumber: i + 1,
|
|
119
|
+
message:
|
|
120
|
+
"Infinite loop detected in this rule and has been ignored. This will cause a redirect to strip `.html` or `/index` and end up triggering this rule again. Please fix or remove this rule to silence this warning.",
|
|
121
|
+
});
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
|
|
112
125
|
if (seen_paths.has(from)) {
|
|
113
126
|
invalid.push({
|
|
114
127
|
line,
|
|
@@ -120,10 +133,7 @@ export function parseRedirects(input: string): ParsedRedirects {
|
|
|
120
133
|
seen_paths.add(from);
|
|
121
134
|
|
|
122
135
|
if (status === 200) {
|
|
123
|
-
|
|
124
|
-
// so if it's present, we can error to the user that proxying only expects relative urls
|
|
125
|
-
const [proxyTo, error] = validateUrl(to, true, true, true);
|
|
126
|
-
if (error) {
|
|
136
|
+
if (urlHasHost(to)) {
|
|
127
137
|
invalid.push({
|
|
128
138
|
line,
|
|
129
139
|
lineNumber: i + 1,
|
|
@@ -131,8 +141,6 @@ export function parseRedirects(input: string): ParsedRedirects {
|
|
|
131
141
|
});
|
|
132
142
|
continue;
|
|
133
143
|
}
|
|
134
|
-
rules.push({ from, to: proxyTo as string, status, lineNumber: i + 1 });
|
|
135
|
-
continue;
|
|
136
144
|
}
|
|
137
145
|
|
|
138
146
|
rules.push({ from, to, status, lineNumber: i + 1 });
|
|
@@ -55,3 +55,8 @@ export const validateUrl = (
|
|
|
55
55
|
: 'URLs should either be relative (e.g. begin with a forward-slash), or use HTTPS (e.g. begin with "https://").',
|
|
56
56
|
];
|
|
57
57
|
};
|
|
58
|
+
|
|
59
|
+
export function urlHasHost(token: string): boolean {
|
|
60
|
+
const host = URL_REGEX.exec(token);
|
|
61
|
+
return Boolean(host && host.groups && host.groups.host);
|
|
62
|
+
}
|