This site counts visits with analytics cookies only if you accept. Read the consent

Skip to content

SecuritySecurity Model

Security Model

Where your users' credentials travel through Courier — browser, proxy, server and API — what each layer passes on, refuses and writes down, and what to set in production.

14 min readUpdated both modes

What Courier secures, and what it leaves to your API

Courier carries calls from your application to your APIs. Deciding who a user is and what they may do stays with the API: Courier sends the credentials a call needs, to the API it is meant for, and nothing else, anywhere else. Along the way it refuses the calls another site sets off, keeps one user's answers away from another, and keeps credentials out of its logs, its caches and Studio.

This page follows the user's credentials through each layer. User Sessions describes how a session is set up, and Server Handler how the proxy route is mounted.

Where credentials travel

Where the call startsWhat holds the user's credentialsWhat Courier sends to the APIWhat it never sends
A page, calling the API directlyThe browser's own cookies, which it sends itself as far as its rules let itThe double-submit token a page can read, repeated on writes— the browser decides the rest
A page, through your proxy routeThe cookies and headers the browser sends to your applicationReferer, Origin, Authorization with a token your scripts set, User-Agent, X-Request-Id, the headers allowedHeaders or .headers() name, the session's cookies, and X-Forwarded-For the proxy writes from the connection and the chain the proxies in front recordedYour application's other cookies, Authorization in Basic, Digest, Negotiate or NTLM, and every header that claims a client address
Your server, while it serves a request — a page, a Server Action, a routeThe request being servedThe cookies session.cookies names, Authorization: Bearer from the bearer cookie, the double-submit header on writes, Referer with your origin, and the headers forward namesEverything else the request carries
A React Native appThe platform's cookie store, and the readable cookies Courier keeps from the API's answersThe double-submit token Courier kept, repeated on writes— the platform sends its own cookies
A stream (SSE)As for a call from the same placeThe same, again on every reconnectThe same
A channel (WebSocket)As for a call from the same placeOn Node and React Native, headers on the handshake; from a browser, the first frame on the socketCredentials in the address

The proxy serves only what you mark

A page reaches an endpoint through the proxy only where a mark opens it — .expose() on the endpoint, or expose on its group or its API — and any other is answered as a name the source does not define. A page's client learns the routes alone, nothing of the API's definition. See Exposing Endpoints.

The proxy passes on only what it names

The proxy forwards the browser's headers on a short list and those named in allowedHeaders or .headers(). The rest stay behind: the browser's cookies, which would reach whatever upstream a source points at, but those an API's session names; the logins a browser sends by itself to your own site; and the headers that claim a client address. A header your server sets is the one the API receives, whatever the page wrote, and the API's cookies come back on a path of their own, described below. See Header whitelisting and Cookies.

Only to the API's origin

A call that takes the user's session sends each of its requests to its API's origin, that of the call's prefixUrl or of the API's baseURL: a request that an endpoint's absolute URL, or a .via() closure, would take to another host is refused with ConfigurationError SESSION_OTHER_ORIGIN before it is sent, on a server, in a page and in an app alike. Give such a host an API of its own, or the endpoint { session: false }. A call that carries the user's credentials from a server follows a redirect only while it stays on the API's origin; a redirect anywhere else is answered with as it came, an upload's included. A session goes over plain HTTP only to the local machine or a private network, unless it sets allowHttp. The address csrf.from names is a path on the API's own origin.

Streams and channels

A stream carries the session as a call from the same place does, read again on every reconnect. A browser cannot put headers on a WebSocket handshake, so a Courier client sends what proves who it is in the socket's first frame, never in the address, where it would reach access logs and browser history. Through the proxy, the upstream socket is opened for each user with that user's session, never shared between users. See Streams and channels and Who a connection is.

React Native

A React Native app keeps its cookies where no script reads them, and sends them to every call to their host whether the API describes a session or not. The cookies a page could read — the double-submit token, a bearer token — Courier keeps from the answers of its own calls, for the host, domain and path they were set for, and a Domain of one label, such as com, is not taken. See The user's session.

What reaches the browser

An API's answer can renew the session, hand out a double-submit token, or sign the user out. On a server, Courier carries those cookies on — to the calls still to be made for the same request, and to the user's browser on your application's response — and only the cookies the session names, the double-submit cookie and the bearer cookie; any other cookie stays with the API. Each is made for your application's origin, for every path and Secure only where it can be, and session.relay: false keeps even the session's own cookies within the request. The rules, and where each framework can and cannot set a cookie, are in The cookies the API sets.

Requests another site sets off

A page on another site can make the user's browser send your application a request, with the user's cookies on it. Courier refuses such a request wherever it would act for the user.

The proxy's origin rule

Every call the proxy serves — GET, POST, a stream and a channel — is checked for where it comes from. Sec-Fetch-Site decides wherever the browser sends it, and Origin where it says nothing else: a page of your application's passes, a page of another site only from an origin in allowedOrigins, and a request with neither header, which no browser made, is served. allowedHosts names the hosts your application answers to, so a name an attacker points at a developer's server — DNS rebinding — is answered 421, whatever X-Forwarded-Host its page adds. A list that cannot be read closes the application rather than opening it. The rules, the patterns a list takes and what each admits are in Origin validation and Host validation.

A GET to the proxy reaches only an endpoint that reads, and the variables of an endpoint marked sensitiveVariables are refused in an address: such a call goes as POST.

Writes made with the user's session

Your server makes calls with the user's session while it serves a request, and a write made then acts for the user. It is made only when the request being served is one of your application's own — a form, a Server Action or a fetch that passes the origin rule above, or a page the browser marks as your application's or as opened by the user. Anything else is refused with 403 before it reaches the API, and the log and Studio say why. A sign-in is guarded too, a write that does no harm when a stranger sets it off says so with session: "unguarded", and a read sent over POST is a read here. See Writes another site sets off.

Channels

A channel's socket passes the origin rule as it opens, so a page on another site cannot open one with the user's cookies. Its first frame may add the headers a browser could not put on the handshake, and never those a browser or a proxy sets — see Who a connection is.

AI agents

An endpoint reaches an agent only when it is marked .agent() or the project's agents policy offers it, and then as an MCP tool whose call runs through the endpoint's middleware and schemas like any other — see MCP Server.

  • Nothing offered by default. The policy lives in courier.config.ts, under review, and a server's start can narrow it, never widen it — see What agents may call.
  • No browser session. An agent's call carries none of the request it arrived on, and runs with what your middleware gives the principal authorize let in.
  • Callers you authorize. createMcpHandler cannot be created without authorize, and allow keeps a tool from a caller as if it did not exist — see In Your App.
  • Limits and confirmations. A tool's limit refuses a call beyond it before anything runs, and a person confirms what cannot be undone, out of the model's reach — see How often an agent may call and A person confirms.
  • What reaches the model is an answer, or an error cut short and cut of its credentials, never a response header — see How a call runs.
  • What Studio keeps. An agent's calls show with the tool and the client. Studio's own MCP endpoint answers only with Studio's token, hands an agent no credential, and sends a recorded write again only once the person confirms it — see Studio for Your Agent.

Webhooks

A webhook is a call made to your app by its sender, and defineWebhook checks each delivery before your handler sees it: its size as it arrives, its signature over the body exactly as it came, its age where the scheme signs one, and its body against the webhook's schema. A webhook without a secret refuses every delivery rather than take an unsigned one, and Studio can have a delivery sent to your app, which the app signs, so the secret stays where it is. See What a delivery passes.

Caches

cacheMiddleware({ scope: "public" }) never stores or serves an answer to a call that carries a session. scope: "session" keeps one partition per set of credentials a call sends, named by their SHA-256 digest so that no credential sits in a cache key, a Redis keyspace or a log line; without the API's session it reads them at its place in the chain, so it goes after the middleware that adds them: placed before, it keeps no answer sent with others, but answers a signed-in user with what a guest's call fetched. See the cache middleware.

What Courier writes down

  • Its log. An HTTPError carries the API's answer whole. Printed — by Courier's log, console.error, or Node's report of an uncaught error — it shows every header with each credential's value hidden, by the rules of redact(), and error.headers still holds them all for the code that reads them. Courier's server log loses every credential first — see Logs — and COURIER_LOG_FORMAT=json prints an error's name, message, code and status alone. logMiddleware logs a failed call's status, never the answer it carried, and a warning about something a client sent names it by what the server knows, never in the client's own words.
  • An upload's files. Under Node the proxy writes what an upload holds past uploadMemoryBytes to disk while its call runs, in a folder of the call's own that only the server's user may read, and removes it once the call has its answer — see where the proxy keeps an upload.
  • Studio. Studio keeps what it captured in .courier/studio.db, readable by your account alone, with every credential header's value written as [redacted]. An error's text, its cause and a request's address leave the page that holds Studio's token — written down, exported, told to an agent or shown to a page without the token — with their credentials cut; see No credential is kept. Studio makes changes only for a page opened with the token in .courier/studio-token — see Start Studio. A session file shared for a bug report carries no credential either, and to follow contract drift Studio keeps the shape of each answer, never a value.

Limits at the edge

WhatDefaultOption
Calls from one caller through the proxyNone — set onerateLimit
Requests no browser sent, Studio's Playground in development asideServedbrowsersOnly
A JSON body to the proxy1 MBmaxBodyBytes
An upload to the proxy10 MBmaxUploadBytes
Parts of one upload: its fields, its files and the call's options1000maxUploadParts
What every upload keeps in memory at once64 MBtotalUploadMemoryBytes
What every upload keeps on disk at once1 GBtotalUploadDiskBytes
An upload's text fields, together1 MBmaxBodyBytes
A pause between two pieces of a request body30 seconds, then 408bodyIdleTimeoutMs
A request body's whole arrival5 minutes, then 408bodyTimeoutMs
A stream's lifetime30 minutessseMaxLifetimeMs
A WebSocket message64 KBmaxMessageSize
Connections from one address, an IPv6 address's /64 counted as one50maxConnectionsPerIP
Messages per connection100 a secondmaxMessagesPerSecond
Subscriptions per connection100maxSubscriptionsPerConnection
Wait for a channel's first frame3 secondsauthTimeoutMs

Subscribing, leaving and re-authenticating are counted apart from other messages, so a flood of messages cannot hold back an unsubscribe. A request the server cannot read — an upgrade whose address or Host no URL can name, a frame that is not one a client sends — is answered or closed on its own, and a failure while one connection is served ends that connection, never the process the others live in.

Development and production

DevelopmentProduction
A page on another local portAdmitted while allowedOrigins is empty and the app is served locally, so Studio can drive it — see Origin validationNever
Hosts answered while allowedHosts is emptyThe local machine's names and IP addressesEvery name
The app's origin, for Studio's PlaygroundTaken, when not configured, from a request whose own Host is localhost, 127.0.0.1 or [::1] on the port the server accepted it on, sent from this machine, as far as the framework tells — see appOriginNever taken from a request
Studio's Playground under browsersOnlyLet through on a one-time pass only Studio's runtime in the process serving the route redeems — see Studio's PlaygroundRefused, as a script is: no pass is honoured

Courier counts as in development wherever NODE_ENV is not production, so set it on every server you deploy, a custom Node server included. It reads each variable of its own — NODE_ENV, COURIER_ALLOWED_ORIGINS, COURIER_ALLOWED_HOSTS, COURIER_TRUSTED_PROXIES among them — as the environment's own: Node looks a name the environment does not have up on Object.prototype, and a variable code elsewhere in the process put there leaves the setting unset. A NODE_ENV your bundler writes into the build is read as written. A production closes every allowance development makes wherever it is found, on Object.prototype too unless your bundler wrote development into the build, and only a process the runtime owns can say development: a value there may make a check stricter, never weaker. The one setting production loosens — a host no allowedHosts names is served in production — takes production only from the environment's own NODE_ENV or your bundler's.

In production

  • Set NODE_ENV=production.
  • Reach your APIs over HTTPS, and leave allowHttp unset. Trust an internal certificate authority with NODE_EXTRA_CA_CERTS or an API's own dispatcher, never by turning the certificate check off — see Proxies & Certificates.
  • Name the session's cookies exactly, and a prefix only where every cookie under it belongs to the session.
  • List in allowedOrigins only pages you serve, and in allowedHosts the names your application answers to — in the code, or in COURIER_ALLOWED_ORIGINS and COURIER_ALLOWED_HOSTS where it runs.
  • Mark session: "unguarded" only on writes that do no harm when a stranger sets them off, and never declare a write .reads().
  • Forward the client's address only behind a proxy on the local machine or a private network.
  • Print the log as JSON wherever it leaves the machine, with COURIER_LOG_FORMAT=json.
  • Keep Studio on your own machine: it is a development tool, and its port is never one to expose.
  • Give an MCP endpoint an authorize that identifies each caller, a confirmSecret shared by its replicas, and offer .agent() only on endpoints you would hand to an agent.

Reporting a vulnerability

Report a security issue privately through GitHub's vulnerability reporting on the repository — never in a public issue. What is in scope, and how quickly you will hear back, is in SECURITY.md.