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.
| Column | Meaning |
|---|---|
allowed_origins | Exact origins allowed for the handoff redirect_uri (e.g. https://admin.ziteox.com) |
callback_urls | Exact registered callback URLs for handoff |
require_staff | When true, Account requires a staff role before issuing a handoff code |
require_second_factor | When true, Account requires AAL2 / second factor before issuing a handoff code |
max_second_factor_age_seconds | Max age of second-factor verification on the portal session; null = no freshness rule |
Current registrations
| App key | Allowed origin | Callback | Staff | Two-step | Max 2FA age |
|---|---|---|---|---|---|
admin | https://admin.ziteox.com | https://admin.ziteox.com/auth/handoff | yes | yes | 12h (43200) |
client | https://client.ziteox.com | https://client.ziteox.com/auth/handoff | no | no | none (null) |
How Account reads the registry
Account loads sites through SupabaseSiteRegistry (packages/auth → handoff/registry.ts):
- Reads
core.appswith 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:
client_idresolves to a registered siteredirect_uriis an exact string match in that site’scallback_urls- The origin of
redirect_uriis listed in that site’sallowed_origins
Path-only differences, wrong origins, or cross-app callbacks are rejected.
Per-site secret
Each registered app shares one secret with Account.
| Where | Env 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_secretonPOST /api/handoff/token) - Account compares with
verifySiteSecretin constant time - Wrong or missing secret →
invalid_client; the one-time code is not burned on a failed secret check
Generate and rotate
- Generate a strong random value (e.g. 32+ random bytes, hex or base64)
- Set
ZITEOX_SITE_SECRET_<APP>on Account andZITEOX_SITE_SECRETon the site to the same value - Redeploy both sides
- Never commit, log, or paste the value into docs, tickets, or chat
Related environment variable names
Names only — never put values in git or docs.
| Name | Meaning |
|---|---|
AUTH_APP_URL / NEXT_PUBLIC_AUTH_APP_URL | Public origin of the Account / auth app (auth.ziteox.com) |
AUTH_APP_INTERNAL_URL | Server-side base URL sites use to call Account (token exchange); falls back to the public auth origin |
ADMIN_APP_URL | Admin site origin (admin.ziteox.com) |
CLIENT_APP_URL | Client site origin (client.ziteox.com) |
ZITEOX_SITE_REGISTRY | Dev switch: local uses in-memory site registration (ignored in production) |
ZITEOX_SITE_SECRET | This site’s copy of the handoff client secret |
ZITEOX_SITE_SECRET_ADMIN / ZITEOX_SITE_SECRET_CLIENT | Account-side secrets for the admin and client apps |