mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
fix: multiple vulnerabilities
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import { apiUrl } from '$lib/server/api';
|
||||
|
||||
const methodsWithoutBody = new Set(['GET', 'HEAD']);
|
||||
|
||||
export async function proxyBackendRequest(
|
||||
prefix: string,
|
||||
path: string,
|
||||
request: Request,
|
||||
url: URL
|
||||
) {
|
||||
const targetUrl = new URL(`${prefix}/${path}`.replace(/\/+$/, ''), apiUrl);
|
||||
targetUrl.search = url.search;
|
||||
|
||||
const headers = new Headers(request.headers);
|
||||
headers.delete('host');
|
||||
|
||||
const init: RequestInit = {
|
||||
method: request.method,
|
||||
headers,
|
||||
redirect: 'manual'
|
||||
};
|
||||
|
||||
if (!methodsWithoutBody.has(request.method)) {
|
||||
init.body = await request.arrayBuffer();
|
||||
}
|
||||
|
||||
return fetch(targetUrl, init);
|
||||
}
|
||||
Reference in New Issue
Block a user