Skip to content

Commit

Permalink
Merge pull request spacebarchat#1199 from DEVTomatoCake/fix/built-in-…
Browse files Browse the repository at this point in the history
…image-proxy
  • Loading branch information
MaddyUnderStars authored Aug 28, 2024
2 parents 7e60f8b + b73b4e9 commit 31ac4a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/api/middlewares/Authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?/;
Expand Down
9 changes: 7 additions & 2 deletions src/api/middlewares/ImageProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ 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;
}

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)",
},
Expand Down

0 comments on commit 31ac4a0

Please sign in to comment.