ObjectStackObjectStack

Production readiness — the go-live list

Security headers, rate limiting, observability, and the go-live checklist for ObjectStack runtimes.

@objectstack/runtime ships first-class primitives for the cross-cutting concerns every production deployment needs: HTTP hardening, rate limiting, metrics, error reporting, and request-id correlation. Everything is pluggable — defaults are safe, opt-in is gradual, and the framework takes no hard dependency on Prometheus / OTel / Sentry / Redis.

This guide is the high-level overview. For the full reference (header defaults, adapter recipes, go-live checklist) follow the deep-dive links.

ConcernDefaultDeep dive
Security response headers (CSP / XCTO / X-Frame-Options / …)OnHARDENING.md
HSTSOff (opt-in once TLS is confirmed)HARDENING.md
Inbound rate limit (token bucket)Built in, off until server.security.rateLimit.enabledHARDENING.md § Rate limiting
CSRFAdapter-layer (bearer-auth = N/A)HARDENING.md
Auth / session / JWT lifecycleOn via @objectstack/plugin-auth (better-auth)HARDENING.md
Metrics (counter / histogram / gauge)Noop (no adapter)OBSERVABILITY.md
Error reporting (5xx only)Noop (no adapter)OBSERVABILITY.md
Request id (X-Request-Id)Auto-generated when enabledOBSERVABILITY.md
W3C Trace Context (traceparent)Parser exported; SDK wiring is host's jobOBSERVABILITY.md

Wiring everything together

A typical production server enables all four:

import { createDispatcherPlugin } from '@objectstack/runtime';
import { promMetrics } from './adapters/prom-metrics.js';     // your code
import { sentryReporter } from './adapters/sentry.js';        // your code

const dispatcher = createDispatcherPlugin({
  // Hardening
  securityHeaders: {
    hsts: { maxAge: 31536000, includeSubDomains: true, preload: true },
    // CSP defaults to deny-all (API server). Override here if you serve
    // a SPA from the same origin.
  },

  // Observability
  observability: {
    metrics: promMetrics,
    errorReporter: sentryReporter,
  },
});

That's it — every route the dispatcher mounts now:

  1. Sends conservative security headers.
  2. Echoes X-Request-Id (honored from caller, or freshly minted).
  3. Reports 5xx exceptions to Sentry (or your reporter) with the request id attached.

The http_requests_total{method,route,status} counter and the http_request_duration_ms{method,route} histogram are emitted at the transport (the IHttpServer.afterResponse observation seam), so they cover every inbound request on the server — auth, the REST data API and other raw-app mounts included, not only the dispatcher's own routes. The dispatcher offers its metrics registry to that seam automatically, and exactly one emitter is armed per server per family, so the wiring above is complete on its own and wiring the transport plugin too never double-counts. The route label is the registered pattern (/api/v1/data/:id), never the concrete path.

http_request_duration_ms measures the request as the transport sees it (middleware chain and body parse included), not the handler alone — so p95 is the latency a caller experiences minus the network.

http_request_errors_total was retired in 17.2.0 (#9834). Nothing declares or emits it any more, so a dashboard keyed on that name reads a flat zero — that is the removal, not a healthy server. Alert on http_requests_total{status=~"5.."} instead: the transport emits it for every inbound surface, whereas the retired counter only ever saw the dispatcher's own routes and only when a handler threw, missing every error answered politely with a status. Unhandled exceptions specifically still reach the errorReporter, which is the signal that counter was mistaken for.

A transport that does not implement the seam reports no HTTP metrics: zero on http_requests_total there means "not instrumented", never "no traffic". The shipped Hono adapter implements it; verify a custom adapter with typeof server.afterResponse === 'function' before trusting its numbers.

A flat cache_* means "no configured consumer", and that reading is the opposite of the one above: the @objectstack/service-cache adapters are instrumented and do hold the host's registry, so a zero on cache_lookups_total is a true count — of a service nothing asked anything of. Nothing consults the cache service unconditionally; every production consumer is a rate-limit or budget counter store gated on an explicit declaration (better-auth's rate_limit_max / rate_limit_window_seconds, the dispatcher's inbound and per-endpoint rateLimit budgets, the per-number OTP send budget). Declare none and the family sits at 0 under normal traffic, so treat a cache hit-rate panel as reporting on your configuration before you treat it as reporting on your cache.

Rate limiting is built into the runtime and needs no adapter code — it is off until the stack declares a budget:

export default defineStack({
  // …
  server: {
    security: {
      rateLimit: { enabled: true, windowMs: 60_000, maxRequests: 300 },
    },
    // Your reverse proxies' own addresses (never a range clients connect
    // from): X-Forwarded-For is believed only from them, and read from the
    // right, past them.
    trustProxy: { networks: ['10.20.0.0/28'] },
  },
});

objectstack serve then meters every request the server routes (CORS preflights excepted) against one token bucket per caller, and answers an over-budget caller 429 with Retry-After. The bucket is keyed by the signed-in principal, and by the caller's address for anonymous traffic. That address is the connection's peer address unless server.trustProxy is declared. Its trusted-network form, { networks: [...] }, believes X-Forwarded-For only on a connection from inside networks (your proxies), and reads it from the right: every entry inside networks is a hop of yours, and the first entry outside them is the client. Every address inside networks is taken for a proxy, so list only your proxies' addresses, never a range your clients connect from; a prefix length of 0 is refused. header: 'x-real-ip' reads X-Real-IP instead, for a proxy that sets that header. true believes the leftmost X-Forwarded-For entry (else X-Real-IP) from any connection, so it is sound only when a reverse proxy you control overwrites that header on every request, never one that appends to it; under true the server warns once when a multi-entry X-Forwarded-For arrives, and true is refused from the next major. Behind a proxy with server.trustProxy unset, all anonymous traffic shares the proxy's one bucket. The counters live in the kernel cache service, which objectstack serve serves in memory, per process: on several nodes the effective limit is the budget times the node count until a shared cache service is registered. Key rules, multi-node and per-class budgets: HARDENING.md § Rate limiting.

Go-live checklist

  • HSTS enabled (after TLS is confirmed and you accept the lock-in).
  • Browsers reach the public origin over HTTP/2 (DevTools shows h2 for the Console's scripts), so the first screen's script files (well over a hundred) do not queue on six HTTP/1.1 connections. See Self-hosting § Serve HTTP/2 to browsers.
  • CSP tuned for your serving topology (deny-all API, looser for SPA-on-same-origin).
  • server.security.rateLimit enabled with a budget sized for your traffic; the boot log shows Inbound rate limit armed. Sign-in can take its own tighter budget (rate_limit_max / rate_limit_window_seconds in Setup → Authentication).
  • server.trustProxy matches the topology: behind reverse proxies, the trusted-network form naming them ({ networks: [...] }); true only behind a proxy that overwrites X-Forwarded-For, never one that appends to it; unset otherwise.
  • Multi-node: a shared cache service is registered, or each node enforces the budget on its own (the in-memory default is per process).
  • Metrics adapter wired; /metrics endpoint (Prom) or OTel exporter producing data; alerts wired for error rate + p95 latency per route.
  • Error reporter wired; synthetic 5xx test reaches Sentry / Datadog / Rollbar.
  • Log records include requestId and cross-check with the response X-Request-Id header.
  • better-auth session TTL / refresh / revoke verified (curl checklist in HARDENING.md).
  • CORS admits exactly the cross-origin front-ends you serve. With no OS_CORS_ORIGIN none is admitted (same-origin pages, the Console included, need no entry); otherwise it lists each origin explicitly, never * — the server refuses * at boot while credentials are on. See HARDENING.md § CORS.
  • Cross-tenant negative tests in CI.
  • Multi-org deployments: tenant isolation is active, not degraded — confirm features.degradedTenancy is false in /auth/config. A deployment requesting multi-org without @objectstack/organizations now refuses to boot unless OS_ALLOW_DEGRADED_TENANCY=1; never set that flag in production. See Tenancy Modes & Membership.
  • OS_ALLOW_DRIVER_CONNECT_FAILURE is unset. A data driver that cannot connect at startup refuses the boot, so a bad OS_DATABASE_URL, a rotated password, or a closed network path surfaces as a failed deploy instead of a "started" server that 500s every request. The same applies to a declared datasource that objects bind to explicitly (datasource: 'analytics'): those objects have no fallback, so a misconfigured analytics URL fails the deploy instead of leaving a server where most pages work and that one subset errors. Setting the flag boots without the database and never reconnects; never set it in production.
  • OS_AUTOMATION_SCHEDULED_WORK_ENABLED is a decision, not a default. Package-authored scheduled work — time-triggered flows and packaged defineJob cron jobs — is OFF in every posture until this is set, so a deployment that expects a packaged digest, sweep or reminder to fire must set it explicitly. Confirm the effective value with os doctor, and read the startup summary: anything listed there as disabled by deployment policy is not broken, it is simply not switched on. Leaving it off is also a legitimate answer — an unsized clock-driven workload is a real cost — but it should be one somebody made. Under isolated, every flow you do arm must declare config.organization. Under group the declaration is optional — an undeclared sweep acts as each swept record's organization — but check the bind lines for any record-less cron flow that writes per-organization rows: it carries no organization and those writes are refused, so it needs a declaration. See Tenancy Modes & Membership.
  • Backup / restore drill documented and tested.
  • Data-retention windows reviewed (ADR-0057): the platform's default lifecycle declarations bound telemetry (activity 14d, job runs 30d, notifications 90d, audit 90d-hot); extend per environment/tenant via the lifecycle.retention_overrides setting before go-live if your compliance regime needs longer, and register an archive datasource if audit data must move to cold storage instead of being retained hot. The sealed audit log expires by whole checkpoints under its global window: a tenant-scoped override does not change it.

CDN / reverse-proxy caching of /meta object schemas

Object schemas are the hottest metadata read — every list, form and detail render fetches one — so they are the first thing an operator reaches for when putting a CDN or reverse proxy in front of the runtime. Since ADR-0106 those responses are per-caller, and the rules below are what keep that safe.

  • The response is already marked private. GET /meta/object/:name answers Cache-Control: private, no-cache — store it in the client, revalidate on every use, never in a shared cache. A proxy configured to ignore private (proxy_ignore_headers Cache-Control, an "override TTL" rule, an edge worker that caches by URL alone) would serve one user's projection to another. Do not add such a rule for /meta or /metadata.
  • The ETag carries the caller's field visibility. The validator is the shared document hash plus, for a restricted caller, a ~<fingerprint> suffix hashing the set of fields that caller cannot read. Consequences worth knowing before tuning anything:
    • A caller who can read every field produces no suffix, so their ETag and body are byte-identical to pre-ADR-0106 releases — existing cache hit rates on unrestricted deployments are unchanged.
    • Callers in the same permission cohort share one validator, and therefore share 304s. Cache storage stays O(objects), not O(users × objects).
    • A permission change moves the fingerprint, so a stale 304 self-invalidates on the next revalidation. There is nothing to purge after editing a permission set.
    • Never strip or rewrite ETag on these routes (some proxies drop it when they compress). Without it every read falls back to a full body, and a proxy that replaces it with its own hash of the served body erases the cohort dimension.
  • A private, no-store response means field visibility could not be resolved. In that degraded window the runtime serves the unmasked schema deliberately — failing closed would brick every render of the object and can deadlock console bootstrap, since permission sets are themselves metadata — and marks it un-storable so it cannot be replayed to anyone else. It also emits a structured warning and increments objectstack_meta_field_visibility_undetermined_total. Alert on that counter: a deployment sitting in this state is disclosing more than it intends, and it is meant to be a hydration blip, not a resting state.
  • A 503 FIELD_VISIBILITY_UNRESOLVED is the security service being unhealthy, not the metadata store. The runtime refuses the read rather than disclose an unmasked schema. It is safe to retry and must not be cached.
  • To deliberately restore the old, unmasked behaviour on a trusted deployment, the supported switch is OS_ALLOW_UNMASKED_OBJECT_METADATA=1 (or per-server metadata.maskObjectFields: false) — not a caching rule that hides the per-caller dimension. The switch also governs object visibility: with it set, every caller is served every object, including objects they may not read, which the mask otherwise answers as objects that do not exist.

Response compression on each door

Who compresses a response depends on the door that serves it:

DoorWho compresses
Self-hosted server: @objectstack/plugin-hono-server, what os dev and os start runThe server, by default: brotli or gzip for compressible responses of 1 KB or more. See Response Compression.
Hosted door: createHonoApp from @objectstack/hono on Cloudflare Workers, Deno Deploy, Bun or Vercel EdgeThe platform or CDN in front of it. The application does not compress there: it sends no Content-Encoding and no Vary: Accept-Encoding.

On the hosted door, check that the platform compresses JSON, JavaScript and CSS responses, and turn it on there if it does not (a runtime you serve yourself may not compress at all: put a proxy or CDN in front of it), rather than adding compression to the app. Either way, keep the ETag unchanged when a layer compresses: saves send it back as If-Match and the server compares it strongly, so a layer that weakens it to W/ makes those saves fail.

What's NOT in the runtime (yet)

  • OTel context propagation. We export parseTraceparent / formatTraceparent so the host can wire traceparent into its OTel SDK, but we don't bundle the SDK itself. The OTel API surface is large and host-specific (Node vs. edge vs. browser).
  • A Prometheus /metrics endpoint. Adapters mount their own scrape endpoint after wiring the MetricsRegistry. We give you the recipe, not the endpoint, because TLS / auth / path conventions vary.
  • A built-in audit log immutability layer. @objectstack/plugin-audit writes sys_audit_log records via ObjectQL afterInsert/afterUpdate/afterDelete hooks and seals them (ADR-0154), so a change or delete made outside the platform shows in os audit verify. Sealing detects; it does not prevent: write-once storage is the host's choice (append-only S3, immudb, etc.).

On this page