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
| Rule | Detail |
|---|---|
| HTTPS in production | Session / 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 cookies | Each site sets its own session cookie with no domain attribute. Never share a parent-domain cookie (e.g. .ziteox.com). |
| Unique cookie names | Pattern sb-zx-<app>-auth-token so apps do not overwrite each other on the same host. |
| One-time codes | Stored hashed; TTL 60 seconds; single use (claim). |
| PKCE S256 | Verifier on the site; challenge on Account; verified at token exchange. |
| State checked | Handoff cookie state must match the callback state (constant-time). |
| Exact redirect URI | redirect_uri must match a registered callback_urls entry and its origin must be in allowed_origins. No wildcards. |
Safe return_to | Same-origin path only (/…). Absolute URLs and //… are rejected for handoff return. |
| Site secret | Server-to-server only (client_secret on POST /api/handoff/token). Never expose to the browser or commit values. |
| Local sign-out only | Site /auth/signout calls signOut({ scope: "local" }). Do not global-sign-out from a product site. |
| Never prefetch logout | Prefer 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 registry | Unknown client_id, DB error, or empty registry result → treat as unregistered; no handoff. |
| Never print secrets | Do 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:
| App | Package | Port |
|---|---|---|
| Admin | ziteox-admin | 3000 (next dev, Next default) |
| Client | ziteox-client | 3001 (next dev -p 3001) |
| Account | ziteox-auth | 3002 (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 name | Value | Effect |
|---|---|---|
ZITEOX_SITE_REGISTRY | local | In-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 name | Typical local value |
|---|---|
AUTH_APP_URL / NEXT_PUBLIC_AUTH_APP_URL | http://localhost:3002 |
ADMIN_APP_URL | http://localhost:3000 (or http://admin.localhost:3000) |
CLIENT_APP_URL | http://localhost:3001 (or http://client.localhost:3001) |
AUTH_APP_INTERNAL_URL | Same 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:
| Side | Env name |
|---|---|
| Account | ZITEOX_SITE_SECRET_ADMIN, ZITEOX_SITE_SECRET_CLIENT, … |
| Each site | ZITEOX_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).
Related env names
Names only — never put values in git or docs.
| Name | Role |
|---|---|
ZITEOX_SITE_REGISTRY | Dev: local in-memory site list |
ZITEOX_HANDOFF_STORE | Dev: memory handoff codes |
ZITEOX_SITE_SECRET | Site copy of handoff client secret |
ZITEOX_SITE_SECRET_<APP> | Account copy per client id |
AUTH_APP_URL | Account public origin |
AUTH_APP_INTERNAL_URL | Site → Account server-side base URL |
ADMIN_APP_URL / CLIENT_APP_URL | Portal origins (local fixture + redirects) |
NODE_ENV | production disables local registry / memory store switches |