fix: enforce inbound media max-bytes during remote fetch

This commit is contained in:
Peter Steinberger
2026-02-21 23:02:17 +01:00
parent dd41fadcaf
commit 73d93dee64
10 changed files with 207 additions and 77 deletions

View File

@@ -92,6 +92,7 @@ describe("resolveForwardedMediaList", () => {
expect(fetchRemoteMedia).toHaveBeenCalledWith({
url: attachment.url,
filePathHint: attachment.filename,
maxBytes: 512,
});
expect(saveMediaBuffer).toHaveBeenCalledTimes(1);
expect(saveMediaBuffer).toHaveBeenCalledWith(expect.any(Buffer), "image/png", "inbound", 512);
@@ -132,6 +133,7 @@ describe("resolveForwardedMediaList", () => {
expect(fetchRemoteMedia).toHaveBeenCalledWith({
url: "https://media.discordapp.net/stickers/sticker-1.png",
filePathHint: "wave.png",
maxBytes: 512,
});
expect(saveMediaBuffer).toHaveBeenCalledTimes(1);
expect(saveMediaBuffer).toHaveBeenCalledWith(expect.any(Buffer), "image/png", "inbound", 512);
@@ -198,6 +200,7 @@ describe("resolveMediaList", () => {
expect(fetchRemoteMedia).toHaveBeenCalledWith({
url: "https://media.discordapp.net/stickers/sticker-2.png",
filePathHint: "hello.png",
maxBytes: 512,
});
expect(saveMediaBuffer).toHaveBeenCalledTimes(1);
expect(saveMediaBuffer).toHaveBeenCalledWith(expect.any(Buffer), "image/png", "inbound", 512);

View File

@@ -218,6 +218,7 @@ async function appendResolvedMediaFromAttachments(params: {
const fetched = await fetchRemoteMedia({
url: attachment.url,
filePathHint: attachment.filename ?? attachment.url,
maxBytes: params.maxBytes,
});
const saved = await saveMediaBuffer(
fetched.buffer,
@@ -307,6 +308,7 @@ async function appendResolvedMediaFromStickers(params: {
const fetched = await fetchRemoteMedia({
url: candidate.url,
filePathHint: candidate.fileName,
maxBytes: params.maxBytes,
});
const saved = await saveMediaBuffer(
fetched.buffer,