@wardenjs/ssr-ssrf
v0.2.0
Published
SSRF-safe outbound fetch for Node.js: host allowlist, private-address blocking and DNS pinning against rebinding.
Maintainers
Readme
@wardenjs/ssr-ssrf
Part of warden's server track: security controls as decorators for any Fetch-API handler (Next.js route handlers, Hono, Bun, Deno, Workers). Here SSR means server side, not server-side rendering.
Outbound HTTP to URLs that input can influence, without reaching your
internal network. Node only (needs node:dns and node:https).
npm i @wardenjs/ssr @wardenjs/ssr-ssrfimport { createSafeFetch } from '@wardenjs/ssr-ssrf';
const safeFetch = createSafeFetch({ allowedHosts: ['api.partner.com', '.cdn.partner.com'] });
const { status, body } = await safeFetch(userSuppliedUrl);- https only, no credentials in the URL, ports 443 and 8443 by default.
- Hosts: exact names, or
.example.comfor its subdomains. - Every resolved address is checked against private, loopback, link-local (cloud metadata), CGNAT and IPv4-mapped ranges, and the connection is pinned to the checked address, so DNS rebinding cannot redirect it.
- Redirects off by default. When enabled, each hop is re-validated, 303 becomes GET, and Authorization and Cookie are dropped across hosts.
- Timeout, byte cap, identity encoding (no decompression bombs).
- Throws
SsrfBlockedError(a 502HttpErrorwith a generic message).
Does not cover fetches made on your behalf by other software: image optimisers, headless browsers, XML parsers.
