@juspay/neurolink
Version:
The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002
33 lines (32 loc) • 1.46 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
* only ever dials addresses 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.
*
* When the environment configures a proxy for the URL (HTTPS_PROXY / ALL_PROXY,
* and the host is not in NO_PROXY) the download goes through that proxy and
* nowhere else: there is no fallback to a direct connection. The proxy resolves
* the host name, so DNS pinning cannot apply; the URL is vetted by
* `assertSafeUrlForProxy` instead (see there for what that covers).
*
* @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>;