The proxy calls your APIs with your server's keys, for anyone who asks: the origin check refuses another site's page, while a script that sends no Origin is served, as a server and a CDN are. rateLimit holds each caller to what a person would make. Every call takes one from requests in each window, a write takes one from writes first, and a call past either is answered 429 before its body is read — the API never sees it:
courierHandler({
rateLimit: {
requests: 300, // calls one caller may make…
window: 60_000, // …in each minute
writes: { requests: 20, window: 60_000 }, // and of those, writes
},
})The budget
A budget lets its calls go at once and then frees one each window / requests, so a caller cannot spend two budgets across a window's edge. The answer to a refused call carries Retry-After, and every answer tells the caller its budgets in the IETF's RateLimit-Policy and RateLimit headers — "calls";q=300;w=60 and "calls";r=299;t=1; a page on a listed origin can read them too. A refused call's body is { "success": false, "code": "RATE_LIMITED", "message": … }, and Studio shows it refused.
Who a caller is
A caller is the user's address, read from the right of the forwarding chain past your own proxies — see The user's address — so a user cannot become another caller by writing an address of their own. Under Next.js, React Router and edge functions, which report no connection, that holds behind a proxy that appends the address it saw: Next.js reached directly keeps the X-Forwarded-For a user wrote. An IPv6 address counts by its /64 network, which one subscriber gets whole — one under NAT64's well-known prefix, 64:ff9b::/96, which a translator gives every IPv4 user it carries, by the IPv4 address it ends in. Many users behind one office's address share its budget; count signed-in users apart by their session with key, which returns undefined to leave a request unlimited. callerKeyOf(address) counts an address as the proxy does: an IPv6 address by its /64, and no address, or anything that is not one, as one caller, "unknown":
import { callerKeyOf } from "@noverax/courier/server"
courierHandler({
rateLimit: {
requests: 300,
window: 60_000,
key: (request) => sessionIdOf(request) ?? callerKeyOf(addressOf(request)),
},
})Counts across replicas
The counts are kept in the process, and a caller is forgotten no later than two windows after its last call — two seconds, for a window shorter than a second. Replicas behind one balancer share them in Redis, where every call is taken in one script on Redis's clock — see Redis:
import { createRedisRateLimitStore } from "@noverax/courier-redis"
courierHandler({
rateLimit: { requests: 300, window: 60_000, store: createRedisRateLimitStore({ redis }) },
})Browsers only
browsersOnly: true refuses with 403 a request that carries neither Sec-Fetch-Site nor Origin, as a script, curl or a crawler sends. It keeps that noise off your APIs and protects nothing — any client can send both headers — and it refuses server code that calls the proxy route over HTTP, and a same-origin read from a browser that sends neither, such as Safari before 16.4. The refusal's body is { "success": false, "code": "BROWSERS_ONLY", "message": … }. The WebSocket handler does not apply it.
Studio's Playground
Studio's Playground runs a Proxy-mode call from your server's process, so it sends neither header either. In development, Studio's runtime gives each such call a one-time pass, and the proxy lets a call that carries one past browsersOnly and past nothing else: allowedHosts, .expose(), rateLimit, the body limits and Courier's middleware still apply.
- The pass. 256 random bits in the
X-Courier-Studio-Passheader, good for one request within 30 seconds; each connection of a stream gets one of its own. An unknown, spent or expired pass is a request without one, answered the same. - Where it goes. Only to a proxy route on this machine —
localhost, an address in127.0.0.0/8or[::1]— or on the app's origin: the oneruntime.appOrigin,COURIER_APP_URLorAPP_URLnames, or, in development, the one the server tells of itself (see How the app learns its origin). No header a request sends decides that origin. A Playground call follows a redirect only on its route's own origin, so neither the pass nor the call's headers leave for one a redirect names. - Who sees it. Only the runtime attached in the process that serves the route can redeem it, and the proxy takes the header off every request before Courier's middleware and hooks, the upstream or Studio sees it — where the runtime lets it change an incoming request's headers. Under one that does not, as
Deno.serveand workerd, the pass is never honoured, and the header stays on for the middleware and Studio's events to see, shown there as a credential; the upstream never sees it. Your framework's own middleware runs before the route — an Expressapp.use, a Next.jsmiddleware.tsorproxy.ts, a SvelteKithandlehook — so it sees the header: keep it out of what such middleware logs, as you keepAuthorizationout. - In production nothing gets through on a pass: the runtime connects to Studio only in development, so it issues and redeems none there, and the proxy honours none where
NODE_ENVisproductionor where there is noprocessto ask.
When the route runs where the pass cannot be redeemed — an Edge route, a Cloudflare worker, an app behind a remote appOrigin, or a runtime that may not change the incoming request's headers, as under Deno.serve — or the pass does not arrive whole and in time — a proxy in front of the route takes the header off, the route is reached more than 30 seconds later, as while it compiles on first request, more than 256 calls are waiting for theirs, or the pass was already spent — the Playground answers browsersOnly refused this call and offers the ways past it: send the call again, run it in Direct mode, set browsersOnly: process.env.NODE_ENV === "production" so development answers every caller, or serve the proxy route on the Node runtime, in the process Studio's runtime is attached to.