DEV Community

Canpolat Kaya
Canpolat Kaya

Posted on

Building an SSRF-safe API proxy for 1,047 public APIs in Next.js 15

When I built FreeAPI (https://findfreeapi.com/en), a catalog of 1,047 public APIs with an in-browser test runner, the hardest part was the proxy. Letting anyone send requests through your server to arbitrary URLs is a classic SSRF vector.

Simple URL blocklists fail against DNS rebinding (TOCTOU) and alternate IP encodings like bracketed IPv6 or decimal IPs. To handle that, I wrote a pinned-IP fetch wrapper that resolves DNS upfront, rejects private or reserved ranges, and connects directly to the validated IP.

Three other guardrails kept the server stable under anonymous traffic:

  • A strict 5 MB payload ceiling so a huge upstream file cannot exhaust memory.
  • An SHA-256 query-param cache and circuit breaker to avoid hammering slow third-party hosts.
  • A 60 requests per minute rate limit per IP for anonymous sandbox users.

Another surprise was how often public APIs return HTTP 200 with an HTML bot-block page instead of JSON. Instead of passing that back as a 502 server error, the proxy inspects the content type and returns a 422 so the UI can explain what happened.

The catalog itself is statically generated across 1,300+ Next.js 15 pages, with 609 no-auth APIs and 33 client-side utilities. If you have built a similar user-facing proxy, I am curious what edge cases bit you in production.

Top comments (0)