1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-08 11:52:55 +01:00

Merge pull request #1199 from DEVTomatoCake/fix/built-in-image-proxy

This commit is contained in:
Madeline 2024-08-28 12:39:31 +10:00 committed by GitHub
commit 31ac4a063c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -54,6 +54,8 @@ export const NO_AUTHORIZATION_ROUTES = [
/GET \/guilds\/\d+\/widget\.(json|png)/,
// Connections
/POST \/connections\/\w+\/callback/,
// Image proxy
/GET \/imageproxy\/[A-Za-z0-9+/]\/\d+x\d+\/.+/,
];
export const API_PREFIX = /^\/api(\/v\d+)?/;

View File

@ -67,7 +67,12 @@ export async function ImageProxy(req: Request, res: Response) {
if (!crypto.timingSafeEqual(Buffer.from(hash), Buffer.from(path[0])))
throw new Error("Invalid signature");
} catch {
console.log("Invalid signature, expected " + hash + " got " + path[0]);
console.log(
"[ImageProxy] Invalid signature, expected " +
hash +
" but got " +
path[0],
);
res.status(403).send("Invalid signature");
return;
}
@ -75,7 +80,7 @@ export async function ImageProxy(req: Request, res: Response) {
const abort = new AbortController();
setTimeout(() => abort.abort(), 5000);
const request = await fetch(path.slice(2).join("/"), {
const request = await fetch("https://" + path.slice(2).join("/"), {
headers: {
"User-Agent": "SpacebarImageProxy/1.0.0 (https://spacebar.chat)",
},