@@ -320,7 +320,12 @@ describe("resolveMedia getFile retry", () => {
320320 it ( "uses caller-provided fetch impl for file downloads" , async ( ) => {
321321 const getFile = vi . fn ( ) . mockResolvedValue ( { file_path : "documents/file_42.pdf" } ) ;
322322 const callerFetch = vi . fn ( ) as unknown as typeof fetch ;
323- const callerTransport = { fetch : callerFetch , sourceFetch : callerFetch } ;
323+ const dispatcherAttempts = [ { dispatcherPolicy : { mode : "direct" as const } } ] ;
324+ const callerTransport = {
325+ fetch : callerFetch ,
326+ sourceFetch : callerFetch ,
327+ dispatcherAttempts,
328+ } ;
324329 fetchRemoteMedia . mockResolvedValueOnce ( {
325330 buffer : Buffer . from ( "pdf-data" ) ,
326331 contentType : "application/pdf" ,
@@ -339,6 +344,13 @@ describe("resolveMedia getFile retry", () => {
339344 expect ( fetchRemoteMedia ) . toHaveBeenCalledWith (
340345 expect . objectContaining ( {
341346 fetchImpl : callerFetch ,
347+ dispatcherAttempts,
348+ shouldRetryFetchError : expect . any ( Function ) ,
349+ readIdleTimeoutMs : 30_000 ,
350+ ssrfPolicy : {
351+ allowRfc2544BenchmarkRange : true ,
352+ hostnameAllowlist : [ "api.telegram.org" ] ,
353+ } ,
342354 } ) ,
343355 ) ;
344356 } ) ;
@@ -369,6 +381,36 @@ describe("resolveMedia getFile retry", () => {
369381 ) ;
370382 } ) ;
371383
384+ it ( "allows an explicit Telegram apiRoot host without broadening the default SSRF allowlist" , async ( ) => {
385+ const getFile = vi . fn ( ) . mockResolvedValue ( { file_path : "documents/file_42.pdf" } ) ;
386+ fetchRemoteMedia . mockResolvedValueOnce ( {
387+ buffer : Buffer . from ( "pdf-data" ) ,
388+ contentType : "application/pdf" ,
389+ fileName : "file_42.pdf" ,
390+ } ) ;
391+ saveMediaBuffer . mockResolvedValueOnce ( {
392+ path : "/tmp/file_42---uuid.pdf" ,
393+ contentType : "application/pdf" ,
394+ } ) ;
395+
396+ await resolveMediaWithDefaults ( makeCtx ( "document" , getFile ) , {
397+ apiRoot : "https://telegram.internal:8443/custom/" ,
398+ dangerouslyAllowPrivateNetwork : true ,
399+ } ) ;
400+
401+ expect ( fetchRemoteMedia ) . toHaveBeenCalledWith (
402+ expect . objectContaining ( {
403+ url : `https://telegram.internal:8443/custom/file/bot${ BOT_TOKEN } /documents/file_42.pdf` ,
404+ ssrfPolicy : {
405+ hostnameAllowlist : [ "api.telegram.org" , "telegram.internal" ] ,
406+ allowedHostnames : [ "telegram.internal" ] ,
407+ allowPrivateNetwork : true ,
408+ allowRfc2544BenchmarkRange : true ,
409+ } ,
410+ } ) ,
411+ ) ;
412+ } ) ;
413+
372414 it ( "uses local absolute file paths directly for media downloads" , async ( ) => {
373415 const getFile = vi . fn ( ) . mockResolvedValue ( { file_path : "/var/lib/telegram-bot-api/file.pdf" } ) ;
374416
0 commit comments