Skip to main content
This page gathers the controls that protect the horizon-api authentication routes. The values come from the code (backend/horizon-api/lib/common/rate-limit/auth-rate-limit.config.ts) and from the authenticate/security-hardening initiative.

How the limiter works

The limiter uses a shared counter in Upstash. Its mode is the server flag authenticate-rate-limit-mode of horizon-api, edited in Horizon Enterprise → Capabilities (it needs feature-flag:update-security). It replaced AUTH_RATE_LIMIT_ENFORCE in 2026.11.2; the variable is read only as a transitional fallback until 2026.11.3. Every environment runs shadow from the 2026.11.2 release night and moves to enforce after 7 days of logs. If the flag store cannot be read, the limiter enforces (safe default). Policies marked always are enforced whatever that value says. Policies marked silent answer the same as a successful request once over budget, so nothing is revealed. When Upstash does not respond, each policy decides: local uses a per-instance counter and closed answers 503. IPs are stored as a hash with a daily salt. The user key is the hash of the presented bearer, so a refreshed token starts with a new budget.

Limits per route

apple-notifications is counted after the JWS is verified, keyed by apple: plus the subject, because every event comes from Apple’s shared egress.

Lockout after failed attempts

With the server flag authenticate-login-lockout on (formerly AUTH_LOCKOUT_ENABLED), each account (identified by an HMAC of its e-mail) allows 5 failed password attempts in 15 minutes. The sixth attempt inside the window answers 423 and the account stays locked for 15 minutes. A successful sign-in clears the counter, and password recovery resets it too. The counter lives in Upstash; without Upstash it counts per instance. Support can unlock an account with:
It requires the auth:unlock-lockout permission. It answers 503 when the lock could not be deleted, so support does not report an unlock that did not happen.
Pending. The lockout is turned on once the client copy has shipped. The production target is to have both the limiter and the lockout enforced.

End-user IP forwarding

horizon-authenticate calls verify-email, magic-link/request, password sign-in and recovery from server actions. All those calls leave from the same server IP. So that the per-IP limit counts each person and not the server (ADR 0098):
  1. horizon-authenticate reads the user’s IP (x-vercel-forwarded-for, x-real-ip) and sends it in x-auth-client-ip, together with x-auth-bff-token.
  2. horizon-api uses that IP only when x-auth-bff-token matches its AUTH_BFF_SERVER_TOKEN.
That is why AUTH_BFF_SERVER_TOKEN must hold the same value (at least 32 characters) in horizon-api and in horizon-authenticate of each environment. portal-customer already uses it.
If it is missing or different, the whole environment shares the server IP budget: as soon as a handful of people sign in, verify-email and the magic link answer 429 for everyone.

Keyrings

They are different keyrings and are never mixed. Without AUTH_PROVIDER_TOKEN_KEYRING, Apple refresh tokens are not stored and cannot be revoked when the account is deleted. The steps are in Operations and maintenance.

Callback hardening

  • Tokens in the fragment. Deep links carry the tokens after #, never in the query.
  • 410 for query tokens. A GET to callback-redirect with tokens in the query answers 410 OAUTH_CALLBACK_UPGRADE_REQUIRED: always for Microsoft, and for the others when the authenticate-oauth-query-tokens-accepted flag is false. Usage is logged as oauth_query_tokens_used.
  • Provider identity. Each callback accepts only a session that holds its provider’s identity (Google google, Microsoft azure); app_metadata.provider does not count.
  • Unverified e-mail. Without an e-mail, or with an unverified one, no profile is created: the deep link returns error=unverified_email. For Microsoft the e-mail only counts as verified through email_confirmed_at or the Azure identity of the same address.
  • Redirect allowlist. redirect_url is checked against config/social-login/redirects.<environment>.json. With the security-social-redirect-enforce flag false it is only logged; the flag is true in every environment right after the 2026.11.2 Sync (T-105).
  • No caching. Session-bearing responses send cache-control: no-store and pragma: no-cache.

Accepted risks

Enumeration (ADR 0134). verify-email returns providers, so it reveals which enabled provider an e-mail uses. This is accepted because the route is rate-limited and returns no profile data. A mail scanner that runs JavaScript can burn a magic link; that is accepted too.

Open tasks

As of 2026-11-04 the authenticate/security-hardening initiative stands at 8%. The most relevant:

See also