@orochibraru/svelte-smol 1.6.0 → 1.6.2
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/templates/handler.ts +25 -1
- package/package.json +1 -1
|
@@ -166,7 +166,10 @@ const ssr = async (request: Request, bunServer: Bun.Server<undefined>) => {
|
|
|
166
166
|
return asset;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
const baseOrigin =
|
|
169
|
+
const baseOrigin =
|
|
170
|
+
same_host_remote_origin(request, url) ||
|
|
171
|
+
origin ||
|
|
172
|
+
get_origin(request.headers);
|
|
170
173
|
const path = request.url.slice(request.url.split("/", 3).join("/").length);
|
|
171
174
|
const newRequest = new Request(baseOrigin + path, request);
|
|
172
175
|
|
|
@@ -233,3 +236,24 @@ function get_origin(headers: Headers) {
|
|
|
233
236
|
|
|
234
237
|
return port ? `${protocol}://${host}:${port}` : `${protocol}://${host}`;
|
|
235
238
|
}
|
|
239
|
+
|
|
240
|
+
// Remote function calls are CSRF-checked against the request origin. When the
|
|
241
|
+
// browser's Origin header matches the Host, use it instead of ORIGIN.
|
|
242
|
+
function same_host_remote_origin(request: Request, url: URL) {
|
|
243
|
+
const request_origin = request.headers.get("origin");
|
|
244
|
+
if (
|
|
245
|
+
!request_origin ||
|
|
246
|
+
!url.pathname.startsWith(`${base}/${manifest.appDir}/remote/`)
|
|
247
|
+
) {
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
const parsed = new URL(request_origin);
|
|
252
|
+
const host =
|
|
253
|
+
(host_header && request.headers.get(host_header)) ||
|
|
254
|
+
request.headers.get("host");
|
|
255
|
+
return parsed.host === host ? parsed.origin : null;
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|