@zedtech/zedkit-server
Key rate limits by client address behind a proxy
Take the client key from the last `X-Forwarded-For` entry, which the proxy appended, not the spoofable first one.
alpha
Usage
At a glance
- Who: Developers rate-limiting public endpoints that sit behind one reverse proxy.
- What: Take the client key from the last
X-Forwarded-Forentry, which the proxy appended, not the spoofable first one. - Use when: With
MemoryRateLimiterbehind exactly one trusted proxy that appends to the header. - Avoid when: Behind several proxies or a CDN — use your framework's trusted-proxy setting instead.
- See also: Rate-limit calls per key
Install
pnpm add @zedtech/zedkit-serverLatest: 1.1.0 (via changesets).
Example
import { clientKeyFromForwardedFor, MemoryRateLimiter } from "@zedtech/zedkit-server";
const limiter = new MemoryRateLimiter();
const key = clientKeyFromForwardedFor(request.headers.get("x-forwarded-for"));
if (!limiter.allow(key, 30)) return tooManyRequests();Wraps: (none)
Give each checkout its own test database
Derive a stable per-checkout database name and refuse unsafe names before they reach DROP.
Refuse private targets before calling a customer URL
Reject non-http(s) URLs and loopback, private, link-local, cloud-metadata and special-use hosts before any request is made.