npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

server-fetch

v1.0.10

Published

SSRF-safe fetch() for server-side use — validates IPs, enforces scheme/port, eliminates DNS rebinding via undici connect.lookup

Readme

server-fetch

CI npm version npm downloads bundle size license node TypeScript npm provenance codecov

Hardened fetch() for Node.js — safe against SSRF, DNS rebinding, oversized responses, and hung connections.

Validates URLs against private/reserved IP ranges, allows only HTTP(S) on ports 80/443, caps response bodies at 10 MB (configurable via maxResponseSize), times out at 10 s (configurable via timeout), and shares one DNS lookup between validation and TCP connect via undici's connect.lookup — no TOCTOU gap.

Install

pnpm add server-fetch undici

undici is a required peer dependency.

Usage

import { serverFetch } from 'server-fetch'

// Drop-in replacement for fetch() — rejects private IPs at connect time
const res = await serverFetch('https://example.com/api', {
  method: 'POST',
  body: JSON.stringify({ url: userInput }),
  timeout: 5000, // optional, defaults to 10_000 (10 s)
  maxResponseSize: 5 * 1024 * 1024, // optional, defaults to 10 MB; pass Infinity to disable
})

Options

| Option | Type | Default | Description | | ----------------- | ---------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | timeout | number (ms) | 10_000 (10 s) | Aborts the request if it doesn't complete in time. | | maxResponseSize | number (bytes) | 10_485_760 (10 MB) | Caps the response body size. Rejects synchronously if Content-Length exceeds the limit; otherwise undici throws ResponseExceededMaxSizeError during body consumption (.text(), .json(), …). Pass Infinity to disable. Must be a positive integer or Infinity — anything else throws SsrfError('INVALID_OPTION'). |

All other RequestInit options except signal are forwarded to undici.fetch unchanged.

Validate without fetching

For registration-time checks (e.g., saving a webhook URL):

import { validateUrl } from 'server-fetch'

// Resolves DNS and checks all returned addresses
const { hostname, resolvedIps, parsed } = await validateUrl(url)

Warning: Using validateUrl() then passing the URL to a separate fetch() reintroduces the DNS rebinding TOCTOU window. Use serverFetch() for actual requests.

Custom agent

import { createSsrfSafeAgent } from 'server-fetch'

// SSRF-safe lookup is always applied; your options are merged in
const agent = createSsrfSafeAgent({ connections: 10 })

What it blocks

Protocols: Only http and https are allowed.

Ports: Only 80 and 443.

IP ranges:

| IPv4 | Purpose | | ---------------- | --------------------------- | | 0.0.0.0/8 | "This network" | | 10.0.0.0/8 | Private (RFC 1918) | | 100.64.0.0/10 | Carrier-grade NAT | | 127.0.0.0/8 | Loopback | | 169.254.0.0/16 | Link-local / cloud metadata | | 172.16.0.0/12 | Private (RFC 1918) | | 192.0.0.0/24 | IETF protocol assignments | | 192.168.0.0/16 | Private (RFC 1918) | | 198.18.0.0/15 | Benchmarking | | 240.0.0.0/4 | Reserved |

| IPv6 | Purpose | | ----------------- | ----------------------- | | ::1/128 | Loopback | | ::/128 | Unspecified | | fc00::/7 | Unique local | | fe80::/10 | Link-local | | ::ffff:0:0:0/96 | SIIT IPv4-translated | | 64:ff9b::/96 | NAT64 well-known prefix | | 64:ff9b:1::/48 | NAT64 local-use prefix |

Error handling

All rejections throw SsrfError with a typed code:

import { serverFetch, SsrfError } from 'server-fetch'

try {
  await serverFetch(url)
} catch (e) {
  if (e instanceof SsrfError) {
    console.log(e.code) // INVALID_URL | BLOCKED_PROTOCOL | BLOCKED_PORT | BLOCKED_IP | DNS_FAILED | RESPONSE_TOO_LARGE | INVALID_OPTION
    console.log(e.url) // the offending URL
  }
}

How it works

  1. validateUrl() parses the URL, checks protocol/port, resolves DNS with { all: true }, and rejects if any address is private.
  2. serverFetch() calls validateUrl() for an early error, then fetches through an undici Agent whose connect.lookup hook validates the resolved IP inside the connection handshake — the same address that passes validation is the one used for TCP connect. No second DNS query, no rebinding window.

License

MIT