@@ -2,6 +2,7 @@ import type { ChannelType, Client, Message } from "@buape/carbon";
22import { StickerFormatType , type APIAttachment , type APIStickerItem } from "discord-api-types/v10" ;
33import { buildMediaPayload } from "../../channels/plugins/media-payload.js" ;
44import { logVerbose } from "../../globals.js" ;
5+ import type { SsrFPolicy } from "../../infra/net/ssrf.js" ;
56import { fetchRemoteMedia , type FetchLike } from "../../media/fetch.js" ;
67import { saveMediaBuffer } from "../../media/store.js" ;
78
@@ -53,6 +54,13 @@ const DISCORD_CHANNEL_INFO_CACHE = new Map<
5354> ( ) ;
5455const DISCORD_STICKER_ASSET_BASE_URL = "https://media.discordapp.net/stickers" ;
5556
57+ const DISCORD_MEDIA_SSRF_POLICY : SsrFPolicy = {
58+ // Discord CDN downloads should be trusted even when DNS/proxy resolution
59+ // maps to private/internal ranges (e.g. Clash TUN fake-ip 198.18.x.x).
60+ allowedHostnames : [ "cdn.discordapp.com" , "media.discordapp.net" ] ,
61+ allowRfc2544BenchmarkRange : true ,
62+ } ;
63+
5664export function __resetDiscordChannelInfoCacheForTest ( ) {
5765 DISCORD_CHANNEL_INFO_CACHE . clear ( ) ;
5866}
@@ -228,6 +236,7 @@ async function appendResolvedMediaFromAttachments(params: {
228236 filePathHint : attachment . filename ?? attachment . url ,
229237 maxBytes : params . maxBytes ,
230238 fetchImpl : params . fetchImpl ,
239+ ssrfPolicy : DISCORD_MEDIA_SSRF_POLICY ,
231240 } ) ;
232241 const saved = await saveMediaBuffer (
233242 fetched . buffer ,
@@ -320,6 +329,7 @@ async function appendResolvedMediaFromStickers(params: {
320329 filePathHint : candidate . fileName ,
321330 maxBytes : params . maxBytes ,
322331 fetchImpl : params . fetchImpl ,
332+ ssrfPolicy : DISCORD_MEDIA_SSRF_POLICY ,
323333 } ) ;
324334 const saved = await saveMediaBuffer (
325335 fetched . buffer ,
0 commit comments