SystemsAuthentication flow

Security rules and local development

Handoff security rules and how to run Account, Admin, and Client locally.

Security rules and local development

Rules that every Ziteox Account handoff integration must keep, plus the local ports and env names for day-to-day development.

Security rules

RuleDetail
HTTPS in productionSession / handoff cookies use Secure only on HTTPS. Shared helper ziteoxCookieSecure turns Secure off if any configured app URL starts with http: (so localhost works). Per-site helpers (e.g. client) also key Secure off that site’s origin.
Host-only cookiesEach site sets its own session cookie with no domain attribute. Never share a parent-domain cookie (e.g. .ziteox.com).
Unique cookie namesPattern sb-zx-<app>-auth-token so apps do not overwrite each other on the same host.
One-time codesStored hashed; TTL 60 seconds; single use (claim).
PKCE S256Verifier on the site; challenge on Account; verified at token exchange.
State checkedHandoff cookie state must match the callback state (constant-time).
Exact redirect URIredirect_uri must match a registered callback_urls entry and its origin must be in allowed_origins. No wildcards.
Safe return_toSame-origin path only (/…). Absolute URLs and //… are rejected for handoff return.
Site secretServer-to-server only (client_secret on POST /api/handoff/token). Never expose to the browser or commit values.
Local sign-out onlySite /auth/signout calls signOut({ scope: "local" }). Do not global-sign-out from a product site.
Never prefetch logoutPrefer a POST form to /auth/signout. Account’s /logout is GET and uses global revoke — links there must use prefetch={false}. A prefetched /logout once signed users out everywhere.
Fail closed on registryUnknown client_id, DB error, or empty registry result → treat as unregistered; no handoff.
Never print secretsDo not log, echo, or document secret values. Env names only.
flowchart LR
  site[Site host-only cookie]
  account[Account host-only cookie]
  site -->|"signOut local"| siteOnly[Clears this site only]
  account -->|"GET /logout global"| everywhere[Revokes refresh tokens]

Local development

Ports

From each app’s package.json dev script:

AppPackagePort
Adminziteox-admin3000 (next dev, Next default)
Clientziteox-client3001 (next dev -p 3001)
Accountziteox-auth3002 (next dev -p 3002)

Browsers do not isolate cookies by port. Prefer distinct hostnames in local testing (admin.localhost, client.localhost, auth.localhost) when you need fully separate sessions.

Local site registry

On Account only, for non-production:

Env nameValueEffect
ZITEOX_SITE_REGISTRYlocalIn-memory registry from ADMIN_APP_URL / CLIENT_APP_URL (via localHandoffSitesFromEnv) instead of core.apps

Ignored when NODE_ENV=production — production always uses Supabase core.apps and fails closed without a service-role client.

A new app is not in that local fixture until you add it in packages/auth (see Add a new site or app).

Optional handoff store switch (also ignored in production): ZITEOX_HANDOFF_STORE=memory.

Point sites at local Account

Env nameTypical local value
AUTH_APP_URL / NEXT_PUBLIC_AUTH_APP_URLhttp://localhost:3002
ADMIN_APP_URLhttp://localhost:3000 (or http://admin.localhost:3000)
CLIENT_APP_URLhttp://localhost:3001 (or http://client.localhost:3001)
AUTH_APP_INTERNAL_URLSame as Account when the site calls the token API (optional; falls back to auth origin)

Matching dummy secrets

Use local-only dummy values that match on both sides:

SideEnv name
AccountZITEOX_SITE_SECRET_ADMIN, ZITEOX_SITE_SECRET_CLIENT, …
Each siteZITEOX_SITE_SECRET

Same string on Account’s ZITEOX_SITE_SECRET_<APP> and that site’s ZITEOX_SITE_SECRET. Never use production secrets locally.

Supabase still real

Account login (password, MFA, sessions) still talks to the Supabase project configured in env on Account. Local registry / memory handoff store do not replace Auth; they only stub site registration (and optionally the handoff code store).

Names only — never put values in git or docs.

NameRole
ZITEOX_SITE_REGISTRYDev: local in-memory site list
ZITEOX_HANDOFF_STOREDev: memory handoff codes
ZITEOX_SITE_SECRETSite copy of handoff client secret
ZITEOX_SITE_SECRET_<APP>Account copy per client id
AUTH_APP_URLAccount public origin
AUTH_APP_INTERNAL_URLSite → Account server-side base URL
ADMIN_APP_URL / CLIENT_APP_URLPortal origins (local fixture + redirects)
NODE_ENVproduction disables local registry / memory store switches