SystemsAuthentication flow

Site registration and secrets

How Account registers first-party apps and verifies per-site handoff secrets.

Site registration and secrets

Account (auth.ziteox.com) only hands users off to apps listed in core.apps. Each app also shares a per-site secret with Account for the server-to-server token exchange.

core.apps registration columns

Migration 20261031200000_app_site_registration.sql adds handoff policy columns on core.apps. Secrets are not stored in SQL.

ColumnMeaning
allowed_originsExact origins allowed for the handoff redirect_uri (e.g. https://admin.ziteox.com)
callback_urlsExact registered callback URLs for handoff
require_staffWhen true, Account requires a staff role before issuing a handoff code
require_second_factorWhen true, Account requires AAL2 / second factor before issuing a handoff code
max_second_factor_age_secondsMax age of second-factor verification on the portal session; null = no freshness rule

Current registrations

App keyAllowed originCallbackStaffTwo-stepMax 2FA age
adminhttps://admin.ziteox.comhttps://admin.ziteox.com/auth/handoffyesyes12h (43200)
clienthttps://client.ziteox.comhttps://client.ziteox.com/auth/handoffnononone (null)

How Account reads the registry

Account loads sites through SupabaseSiteRegistry (packages/auth → handoff/registry.ts):

  • Reads core.apps with the service role
  • Caches each lookup for 60 seconds in memory
  • Fails closed: unknown client_id, DB error, or empty result → site is treated as unregistered → no sign-in / handoff

Dev only: ZITEOX_SITE_REGISTRY=local (and not production) uses an in-memory registry built from ADMIN_APP_URL / CLIENT_APP_URL. Production always uses Supabase.

Exact callback match (isRegisteredRedirect)

A redirect is accepted only when all of these hold:

  1. client_id resolves to a registered site
  2. redirect_uri is an exact string match in that site’s callback_urls
  3. The origin of redirect_uri is listed in that site’s allowed_origins

Path-only differences, wrong origins, or cross-app callbacks are rejected.

Per-site secret

Each registered app shares one secret with Account.

WhereEnv var name
Account (Cloudflare Worker secret, one per app)ZITEOX_SITE_SECRET_<APP> — uppercase client id, e.g. ZITEOX_SITE_SECRET_ADMIN, ZITEOX_SITE_SECRET_CLIENT
Admin / Client host env (Vercel or Cloudflare)ZITEOX_SITE_SECRET (that site’s own copy)

How it is used:

  • Sent only server-to-server in the handoff token exchange (client_secret on POST /api/handoff/token)
  • Account compares with verifySiteSecret in constant time
  • Wrong or missing secret → invalid_client; the one-time code is not burned on a failed secret check

Generate and rotate

  1. Generate a strong random value (e.g. 32+ random bytes, hex or base64)
  2. Set ZITEOX_SITE_SECRET_<APP> on Account and ZITEOX_SITE_SECRET on the site to the same value
  3. Redeploy both sides
  4. Never commit, log, or paste the value into docs, tickets, or chat

Names only — never put values in git or docs.

NameMeaning
AUTH_APP_URL / NEXT_PUBLIC_AUTH_APP_URLPublic origin of the Account / auth app (auth.ziteox.com)
AUTH_APP_INTERNAL_URLServer-side base URL sites use to call Account (token exchange); falls back to the public auth origin
ADMIN_APP_URLAdmin site origin (admin.ziteox.com)
CLIENT_APP_URLClient site origin (client.ziteox.com)
ZITEOX_SITE_REGISTRYDev switch: local uses in-memory site registration (ignored in production)
ZITEOX_SITE_SECRETThis site’s copy of the handoff client secret
ZITEOX_SITE_SECRET_ADMIN / ZITEOX_SITE_SECRET_CLIENTAccount-side secrets for the admin and client apps