Filter proxied headers

pull/513/head
Zef Hemel 2023-08-23 20:00:40 +02:00
parent 5a88254cde
commit 5079d3e68e
2 changed files with 22 additions and 2 deletions

View File

@ -469,9 +469,18 @@ export class HttpServer {
url = `https://${url}`;
}
try {
const safeRequestHeaders = new Headers();
for (const headerName of ["Authorization", "Accept", "Content-Type"]) {
if (request.headers.has(headerName)) {
safeRequestHeaders.set(
headerName,
request.headers.get(headerName)!,
);
}
}
const req = await fetch(url, {
method: request.method,
headers: request.headers,
headers: safeRequestHeaders,
body: request.hasBody
? request.body({ type: "stream" }).value
: undefined,
@ -521,3 +530,10 @@ function utcDateString(mtime: number): string {
function authCookieName(host: string) {
return `auth:${host}`;
}
function copyHeader(fromHeaders: Headers, toHeaders: Headers, header: string) {
const value = fromHeaders.get(header);
if (value) {
toHeaders.set(header, value);
}
}

View File

@ -156,7 +156,11 @@ async function handleLocalFileRequest(
url = `https://${url}`;
}
console.info("Proxying federated URL", path, "to", url);
return fetch(url, { method: "GET", headers: request.headers });
return fetch(url, {
method: request.method,
headers: request.headers,
body: request.body,
});
} else {
console.error(
"Did not find file in locally synced space",