@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
27 lines (26 loc) • 1.06 kB
TypeScript
/**
* Safe Fetch — SSRF-hardened binary download helper.
*
* Combines:
* - `assertSafeUrl` (validates and rejects blocked IPs)
* - undici `Agent` with custom `connect.lookup` so the actual connection
* uses the IP we validated (closes the DNS-rebinding window where the
* resolver returns a public IP for the guard but a private IP for the
* real request).
* - `readBoundedBuffer` for size cap.
* - `redirect: "manual"` so a 3xx → private-IP redirect can't bypass
* the guard.
*
* Use this for **every** download of an external (caller-supplied or
* third-party-returned) URL. Direct `fetch(url)` of such URLs is unsafe.
*
* @module utils/safeFetch
*/
import type { SafeDownloadOptions } from "../types/index.js";
/**
* Safely download a binary asset from an external URL.
*
* @throws {Error} if the URL is unsafe, the response is too large, a redirect
* is encountered, or the HTTP status indicates failure.
*/
export declare function safeDownload(url: string, options: SafeDownloadOptions): Promise<Buffer>;