Sessions (2)
Rate limits
| Binding | What it limits | Default |
|---|---|---|
| rateLimiter | Every event and logout, by session or client address | Memory: a burst of 30, refilling 10 per second |
| publicRateLimiter | Sign-in through public views, per address and per account | Memory: 10 attempts, then one every 6 s |
| anonymousRateLimiter | Events from anonymous sessions on public views, per address (IPv6 per /64) | Memory: a burst of 30, then one per second (RT-1) |
| sessionStartLimiter | Anonymous sessions started, per address (IPv6 per /64) | Memory: a burst of 600, then 10 per second (RT-2) |
| loadRateLimiter | Page and state loads, per session, or per address without one (Sprint 12, RT-6) | luxel-host: the configured rateLimiter (global when it is shared); otherwise memory: a burst of 30, then 10 per second |
The memory session store keeps anonymous sessions under their own cap (maxAnonymousSessions, half of maxSessions by default); they only evict each other, never a signed-in session (RT-2).
With several nodes, an in-memory limiter multiplies the limit by the number of nodes. Use the shared PostgreSQL limiter, which takes each token with one atomic statement:
import { createPgRateLimiter } from '@luxel-framework/postgres'; export const rateLimiter = createPgRateLimiter({ pool, capacity: 30, refillPerSecond: 10 }); export const publicRateLimiter = createPgRateLimiter({ pool, capacity: 10, refillPerSecond: 1 / 6, table: 'luxel_login_bucket' });
Behind a proxy, every request comes from the proxy's address, so every client shares one address bucket. Set LUXEL_TRUST_PROXY=1 to take the client address from the last entry of X-Forwarded-For (the one your proxy appended). Only do this when the host is reachable through that one proxy alone: if clients can reach the host directly, they can choose their own address.
Replay guard
The replay guard remembers spent form tokens of static views until they expire. The default is in memory, bounded at 100 000 entries. When it is full of unexpired entries it refuses new claims (sign-ins wait until entries expire, at most 2 minutes): it never forgets a spent token early. Filling it takes 100 000 accepted sign-in attempts within 2 minutes, through the per-address limits. Measured in Sprint 11: about 0.2 µs per claim in memory, and about 0.4 ms and 120 bytes per claim in PostgreSQL, swept after expiry. With several nodes a token could be spent once per node, so use the shared one:
import { createPgReplayGuard } from '@luxel-framework/postgres'; export const replayGuard = createPgReplayGuard({ pool });
It keeps one row per nonce hash until the token expires, claimed with one atomic statement.
Several nodes
With LUXEL_ENV=production and LUXEL_NODES above 1, the host refuses to start unless:
- sessionStore is shared (PostgreSQL or delegated);
- rateLimiter is shared;
- with a static view: replayGuard and publicRateLimiter are shared too.
The template's bindings carry the multi-node setup as comments:
import pg from 'pg'; import { createPgRateLimiter, createPgReplayGuard, createPgSessionStore } from '@luxel-framework/postgres'; const pool = new pg.Pool({ connectionString: process.env.DATABASE_URL }); export const sessionStore = createPgSessionStore({ pool }); export const rateLimiter = createPgRateLimiter({ pool, capacity: 30, refillPerSecond: 10 }); export const publicRateLimiter = createPgRateLimiter({ pool, capacity: 10, refillPerSecond: 1 / 6, table: 'luxel_login_bucket' }); export const replayGuard = createPgReplayGuard({ pool });
No sticky sessions are needed with a shared store: any node serves any request. Your eventStore must be shared too (your database), so idempotency holds across nodes. See Production.
Normalized inputs (Sprint 12)
views.‹id>.normalize maps input names to "NFKC", "NFC" or "none". The gateway removes zero-width characters (U+200B–U+200D, U+2060, U+FEFF) and control characters other than tab and line breaks, then applies the Unicode normal form, before the sign-in limits and before your handler sees the value. NFKC also folds compatibility forms (full-width letters and other look-alikes), so victim and vic\u200Btim are the account victim. A view's identity input is NFKC by default; write normalize: { username: "none" } to keep it as typed. Use it for names people compare by eye (a payee, a reference); a free-text note is better left as written.