Security
The frontend server sits between the browser and the backend. It holds what the browser must never see: the access and refresh tokens, the session secret, the bootstrap credential and the modules' private options.
Credentials
- The bootstrap credential (
DMS_BOOTSTRAP_SECRET) goes only into the CLI's server-to-server requests to the backend, in thex-dms-bootstrapheader. Those requests fetch the frontend manifest and report the modules that the server serves. Browser traffic never sends or receives the credential. Pass it through the environment and not through--bootstrap-secret, because every process on the machine can read a command line. - A discovered development credential goes only to the backend that published it. If you point
-bat a staging or production host from inside a running project, the CLI withholds the local credential and does not send it there. - Generated files that hold secrets, the manifest cache and the private module options, can be read only by their owner, in a workspace that only its owner can open. The development server refuses to serve them, or the modules' server code, whatever the query.
Sessions and cookies
- The session lives in a sealed,
HttpOnlycookie. The tokens stay on the server. The browser gets page props that the sign-in module'spublicSessionbuilds. DMS_SESSION_SECRETseals the cookie. It is 32 characters or more, and it stays the same across restarts.startneeds one, anddevmakes one per workspace when it is unset.startsetsSecurecookies (DMS_COOKIE_SECURE=true), so the browser sends them only over HTTPS.devdoes not, because it runs over HTTP.- Module cookies are sealed, scoped to the backend,
HttpOnlyandSameSite=Lax, and kept apart per module. They areSecureunder the same rule as the session cookie. See Server routes.
Same-origin checks
A state-changing request must carry the frontend's own Origin when the server proxies it with the session or when it reaches a module route.
The exceptions are explicit:
| Exception | Authentication boundary |
|---|---|
A proxy prefix declared with auth: "none" | Never sends the session. |
| A public endpoint | Never sends the session. |
A module route that passes { sameOrigin: false } | Authenticates its caller another way. |
Every backend request carries the x-dms-ui-* headers of the browser request as the browser sent them, whatever their name after the prefix. They are dropped when the browser marks the request as sent from another origin or site, by its Origin or its Sec-Fetch-Site. The server never adds such a header itself, never builds one from a query string, a form field or a cookie, and drops one that a server route passes to event.backend or that a server render passes to its backend read. A module route that calls the backend with its own fetch sets its own headers. No HTML form can set a header, so a backend route can require an x-dms-ui-* header that its module's client code sets. That refuses a submission which a page built from blocks makes with the user's session.
Behind a reverse proxy
On a hosting platform
DMS_CLIENT_IP_HEADER names the header that a hosting platform overwrites with the client's address on every request. On AntelopeJS Cloud, that header is X-Client-IP, and the platform sets the variable itself. The server uses the header as follows:
- When a request carries the header, the server takes the client's address from it. It takes the scheme and the host from the platform's
X-Forwarded-ProtoandX-Forwarded-Host. - When the header is absent, as on a private call from another service, the server falls back to
DMS_TRUSTED_PROXY_HOPS. - When the variable is unset, which is the default, the server reads no such header.
- On every backend request, the server sets that same header to the client address it resolved, and replaces any value that a caller sent. A backend configured with the same name (the DMS's
auth.clientIpHeader) then records the same address without counting hops.
Set DMS_CLIENT_IP_HEADER only when the platform overwrites that header and nothing else can reach the server. Otherwise a client chooses its own address.
Counting proxies
DMS_TRUSTED_PROXY_HOPS is the number of reverse proxies in front of the server, counted from the right of X-Forwarded-For. It defaults to 0.
- With
0, the server takes the client's address from the socket, and replaces anyX-Forwarded-Forthat the client sent. - Above
0, the server trusts that many hops from the right. When it proxies, it extends the client'sX-Forwarded-Forwith the socket's address.
Forwarding the client's country
DMS_COUNTRY_HEADER names the header in which a trusted proxy sets the client's country:
- The default is
CF-IPCountry. - An empty value relays none.
- Like the client address, the server relays the header to the backend only from a trusted proxy. A trusted proxy is one that sets the platform's client address header, or any proxy when
DMS_TRUSTED_PROXY_HOPSis above0.
Name the same header in the backend's auth.signInCountry.header.
Set DMS_TRUSTED_PROXY_HOPS to the exact number of proxies you run. A higher value lets a client choose the address that the backend rate-limits and logs.
The development server
ajs dms dev listens on 127.0.0.1 unless HOST names another address, so only the machine it runs on can reach it. It serves module sources to Vite. It never serves the generated secrets (generated-server-options.json, .manifest-cache.json) or the modules' server code (dms.server.*, server/).
Trusting module code
A module's dms.server.ts runs in the frontend server's process, next to the session secret. Every route it declares can read and write the session, tokens included.
The frontend server trusts that code as much as the module's backend half. Install a module only when you trust its server code as much as the DMS's own.