API server and console
The platform API is the FC_PLATFORM_ENABLED subsystem of fc-server: one
chi router on the API listener (:8080) carrying the programmable API, the OIDC provider, the
portal and field identity planes, the server-rendered console and the delivery callback. It is
stateless; run as many copies as you need behind a load balancer.
This page is about how that surface is built and protected. What each surface is for, and the compatibility promise, are on API surfaces; every operation is in the HTTP API reference.
Route tiers
Section titled “Route tiers”| Prefix | Tier | Authentication | Notes |
|---|---|---|---|
/api/* |
Public, programmable | Bearer token (or the session cookie from the console) | Authorization is a permission check inside each handler, never the URL prefix. Every write handler makes exactly one check |
/bff/* |
Console only | Session cookie | Shapes tuned to screens; not for SDKs |
/auth/*, /oauth/*, /.well-known/* |
The identity provider | Varies (public login, client authentication, session) | The OAuth and OIDC endpoints are hand-written and sit outside the authenticated group |
/portal/* |
The portal identity plane | Portal tokens | Separate principals (ptu_) |
/field/* |
Field-worker identity | Device-bound sessions | Its own per-IP rate governor |
/api/dispatch/process, /api/dispatch/settled |
Internal callbacks | The scheduler’s HMAC token | Called by the router |
/ui/* |
The console | Session cookie | Server-rendered |
/router/* |
The router’s dashboard and API | Basic auth | When the router runs in this process |
/api/openapi.json, /api/openapi.yaml, /q/openapi, /swagger-ui |
The OpenAPI document | None | Served outside the authenticated group for tooling |
/auth, /oauth, /.well-known, /api/dispatch, /api/me and /api/public are platform-owned
paths and do not move.
The API: huma and the lockfile
Section titled “The API: huma and the lockfile”Every /api operation is registered with huma through a small shared helper
(internal/platform/shared/apiroute), so the OpenAPI 3.1 document is generated from the Go types
the handlers actually use. Each subdomain package (internal/platform/<name>/api) exposes a
Register(api, state) that registerPlatformAPI calls; adding a subdomain is a repository, its use
cases, an api.State and one Register line.
The lockfile is the compatibility authority. api/openapi.lock.json is the committed document.
make dump-spec prints the live one without a database, make api-bump rewrites the lockfile, and
make api-diff (run in CI) fails if the code’s document differs from the lockfile. A change to a
response shape, a field name or an operation therefore shows up as a lockfile diff in review. See
the OpenAPI lockfile is the compatibility authority
and wire conventions.
Request bodies are lenient. huma generates request schemas with additionalProperties: false,
which would answer 400 to any client that sends a field the server does not know (for example a
newer SDK talking to an older platform). RelaxRequestBodies flips every request body to accept and
ignore unknown fields, in the server and in the spec dumper alike, so the lockfile matches what is
enforced. Response bodies are not relaxed.
One error envelope. A use case’s *usecase.Error is mapped to an HTTP status by its kind and
written as {"error": "<CODE>", "message": "...", "details": {...}}, the same shape whether the
route is a huma operation or a plain chi handler. Validation failures put per-field errors under
details.errors. Codes are listed in the error reference. Timestamps are
always microsecond ISO 8601.
Writes go through use cases. A handler decodes, then runs one use case through the unit of work, which validates, authorizes, executes and commits the state change, its domain events and its audit record in one transaction. See the write path.
Authentication and the request pipeline
Section titled “Authentication and the request pipeline”flowchart LR REQ["Request"] --> RID["RequestID, RealIP, Recoverer"] RID --> CID["CorrelationID"] CID --> AUTH["Authenticator<br/>bearer or fc_session"] AUTH --> CSRF["SessionCSRF<br/>cookie and unsafe method only"] CSRF --> PO["ProfileOnlyWithoutRole"] PO --> H["huma or chi handler<br/>permission check, use case"]
Authenticatorbuilds the caller’sAuthContextfrom anAuthorization: Beareraccess token or, for the console, thefc_sessioncookie. A request with neither is anonymous and is refused by any handler that needs a principal. The development fallback headerX-FC-Test-Principalis only honoured withFC_AUTH_ALLOW_TEST_HEADERS=true, whichfc-serverrefuses unlessAPP_ENVislocalortest.SessionCSRFapplies only when the session cookie authenticated the request and the method is unsafe. It requires browser provenance (Sec-Fetch-Site: same-originornone; without it, anOriginmatching the host or the public base URL; a request with neither header is refused) and a JSON body. Refusals are403 CROSS_ORIGIN_REQUEST. Bearer-token callers are not affected.- The passkey sign-in endpoints, which are public but mint the session cookie, get the same
provenance check as
/auth/login. ProfileOnlyWithoutRole: a user with no role reaches only their own profile (/auth/*,GET /api/me). See profile-only access.
The session cookie is HttpOnly, Secure outside development, and SameSite=Lax by default
(FC_SESSION_COOKIE_SAME_SITE: lax, strict or none).
chi’s RealIP middleware is on by default (FC_HTTP_REAL_IP_MIDDLEWARE) and trusts X-Real-IP
and the leftmost X-Forwarded-For hop. Turn it off when no proxy in front rewrites those headers. The
platform’s own rate limits do not rely on it: they key on the rightmost X-Forwarded-For hop.
The console
Section titled “The console”The console is server-rendered: Go templ components from the framework’s
UI kit, with Datastar for interaction, mounted under /ui
(internal/ui). Pages read repositories and run the same use cases and permission checks as the
corresponding API handlers, in process, so the console can never do something the API would
refuse. Mutations are POST only and answer Datastar requests with server-sent patches.
The /ui group has its own guards (internal/ui/guard): security headers, CSRF, session negotiation
and the role-less gate.
| Guard | What it does |
|---|---|
| Security headers | Content-Security-Policy with script-src 'self' 'unsafe-eval' (Datastar compiles expressions; no inline scripts), frame-ancestors 'none', X-Frame-Options: DENY, nosniff, Referrer-Policy: same-origin, Cache-Control: no-store |
| CSRF | Three layers: SameSite=Lax on the cookie; Sec-Fetch-Site or Origin provenance on every unsafe method (Go’s CrossOriginProtection); and an unsafe request with neither header is refused. No token is needed |
| Session negotiation | An HTML navigation without a session is redirected to /ui/auth/login?redirect=<path>; a Datastar action or fetch gets 401 |
| Role-less gate | A user with no role gets 403, as on the API |
The earlier Vue single-page console is gone. It was removed from the repository and the binary.
Its page URLs (/, /dashboard, the old sign-in paths and the rest) now answer 302 to their /ui
equivalent (internal/consoleredirect), so existing bookmarks keep working; API prefixes answer a JSON
404, and other methods than GET and HEAD answer 405. The redirect responses are no-store.
FC_CONSOLE is no longer read: setting it does nothing. See
the console moves to templ and Datastar.
The platform API sends no CORS headers: browsers reach /api from the console’s own origin, and
applications call it from their back ends with a bearer token. The allowed-origins list
(tnt_cors_allowed_origins, managed in the console) is used where a browser on another origin is
expected:
- the push gateway, whose stream and subscription routes answer CORS preflights for listed origins;
- the field-worker sign-in routes (
/field/*), under the same list and never with credentials; and - function endpoints, whose CORS policy is declared per endpoint in the function’s describe document and applied by the runner (a function cannot add or override those headers itself).
OAuth clients also carry an allowed-origins list. It is stored and editable, but nothing in the platform reads it today: the OAuth and OIDC endpoints send no CORS headers, so a browser application should exchange codes and refresh tokens from its own back end.
Rate limiting
Section titled “Rate limiting”Two layers, both in internal/platform/shared/ratelimit:
| Layer | Scope | Examples (defaults) |
|---|---|---|
Distributed policies (FC_RL_*) |
Cluster-wide, counted in Redis when FC_REDIS_URL is set and reachable, otherwise in PostgreSQL (iam_rate_limit_events) |
/oauth/token 600 per IP and 300 per client per minute; /oauth/authorize the same; password reset 20 per IP and 5 per email per hour |
| In-memory governors | Per instance, defence in depth in front of the policies | /oauth/token 120 per IP per minute (burst 60); the OIDC bridge 60 per minute (burst 30); /field/* 600 per IP per minute (burst 200) |
Field sign-in also has failure budgets per device, per client and per IP, which answer 429 with
Retry-After and emit a throttling event. Login backoff (slowing repeated password failures) is
separate and described under second factors. FC_RATE_LIMIT_DISABLE=1
replaces the distributed store with a no-op; use it only in tests.
The outbound delivery guard
Section titled “The outbound delivery guard”Subscription endpoints, connection targets, scheduled-job targets and an SDK dispatch job’s
targetUrl are customer input that the platform POSTs to from inside your network. The guard
(internal/netguard) refuses destinations that could expose the cluster:
- at write time, with
400 INVALID_ENDPOINTorINVALID_TARGET_URL; and - authoritatively at dial time, after DNS resolution, so a hostname that resolves to a forbidden address is refused too.
Cloud metadata (169.254.169.254, fd00:ec2::254), link-local, unspecified and multicast addresses
are always refused. Loopback and private ranges (RFC 1918, fc00::/7, CGNAT) are refused unless
allowed:
| Variable | Default | Effect |
|---|---|---|
FC_DELIVERY_ALLOW_LOOPBACK |
false |
Permit 127.0.0.0/8, ::1, localhost (development only) |
FC_DELIVERY_ALLOW_PRIVATE |
false |
Permit private ranges |
FC_DELIVERY_ALLOW_HOSTS |
none | host:port patterns (* wildcard) exempt from the checks: prefer this to opening every private range |
The function runner’s URLs (FC_FUNCTIONS_RUNNER_URL and the per-runtime variants) are exempted, but
only in the separate policy the platform uses for deliveries it wrote itself (a function’s
subscriptions and schedules); a customer-supplied URL is judged without that exemption, so no customer
can name the runner. The dispatch callback (FC_DISPATCH_PROCESSING_ENDPOINT) needs no exemption: only
the router dials it, and the router applies no policy. The guard sits where the platform delivers to
customer targets: the dispatch delivery callback and the scheduled-job dispatcher. The router applies
none, because its targets come from first-party configuration and from the platform’s own message
pointers. An IPv6 address that carries a zone (fe80::1%eth0 names a network interface) is refused
whatever FC_DELIVERY_ALLOW_LOOPBACK and FC_DELIVERY_ALLOW_PRIVATE say, because a delivery address may not name an interface.
fcdev allows loopback and private targets unless the
variables are set.
Tunables
Section titled “Tunables”| Variable | Default | Effect |
|---|---|---|
FC_API_PORT (PORT) |
8080 |
API listener |
FC_JWT_ISSUER (FC_EXTERNAL_BASE_URL) |
http://localhost:8080 |
The public base URL: token issuer, and a trusted origin for CSRF behind a proxy |
FC_SESSION_COOKIE_SAME_SITE |
lax |
Session cookie SameSite |
FC_HTTP_REAL_IP_MIDDLEWARE |
true |
Trust X-Real-IP and X-Forwarded-For for the request’s remote address |
FC_RL_*, FC_OAUTH_TOKEN_*, FC_OIDC_*, FC_FIELD_* |
see above | Rate limits |
FC_REDIS_URL |
none | Redis for the distributed rate-limit store |
FC_DELIVERY_ALLOW_* |
off | The outbound guard’s exceptions |
Everything else is in the environment reference, with rate limiting and the outbound delivery guard in their own sections.
Read next
Section titled “Read next”- API surfaces and compatibility and the HTTP API reference.
- Security model: how these pieces fit the threat model.
- Security hardening checklist.