{"vsa":"0.9.0","type":"StaticManifest","manifestVersion":"1.0.0","viewId":"docs-v0-2-sessions-2","title":"Sessions (2) · Docs v0.2","requires":[{"name":"zone.text","version":"^1.0.0"}],"optional":[{"name":"render.dom","version":"^1.0.0"},{"name":"projection.slots","version":"^1.0.0"}],"trustDomain":"self","dataClass":"public","zones":[{"zoneId":"l-1","kind":"text","label":"Luxel"},{"zoneId":"l-2","kind":"text","label":"Docs"},{"zoneId":"l-3","kind":"text","label":"Demo"},{"zoneId":"l-4","kind":"text","label":"Numbers"},{"zoneId":"l-5","kind":"text","label":"Security"},{"zoneId":"l-6","kind":"text","label":"Releases"},{"zoneId":"l-7","kind":"text","label":"Roadmap"},{"zoneId":"l-8","kind":"text","label":"Blog"},{"zoneId":"l-9","kind":"text","label":"Español"},{"zoneId":"t-10","kind":"text","label":"Docs v0.2"},{"zoneId":"l-11","kind":"text","label":"Docs v0.1: 0.1.0 betas →"},{"zoneId":"l-12","kind":"text","label":"Search documentation →"},{"zoneId":"t-13","kind":"text","label":"Start"},{"zoneId":"l-14","kind":"text","label":"Overview"},{"zoneId":"l-15","kind":"text","label":"Getting started"},{"zoneId":"l-16","kind":"text","label":"Primeros pasos"},{"zoneId":"l-17","kind":"text","label":"Concepts"},{"zoneId":"t-18","kind":"text","label":"Guide"},{"zoneId":"l-19","kind":"text","label":"Views"},{"zoneId":"l-20","kind":"text","label":"Screens"},{"zoneId":"l-21","kind":"text","label":"Testing screens"},{"zoneId":"l-22","kind":"text","label":"Forms"},{"zoneId":"l-23","kind":"text","label":"Collections"},{"zoneId":"l-24","kind":"text","label":"Charts"},{"zoneId":"l-25","kind":"text","label":"Polling"},{"zoneId":"l-26","kind":"text","label":"Languages"},{"zoneId":"l-27","kind":"text","label":"Server"},{"zoneId":"l-28","kind":"text","label":"Sessions"},{"zoneId":"l-29","kind":"text","label":"Production"},{"zoneId":"l-30","kind":"text","label":"Behind a gateway"},{"zoneId":"l-31","kind":"text","label":"Tooling"},{"zoneId":"l-32","kind":"text","label":"From React or Next.js"},{"zoneId":"t-33","kind":"text","label":"Reference"},{"zoneId":"l-34","kind":"text","label":"Typical React mistakes"},{"zoneId":"l-35","kind":"text","label":"API"},{"zoneId":"l-36","kind":"text","label":"Diagnostics"},{"zoneId":"l-37","kind":"text","label":"Support matrix"},{"zoneId":"t-38","kind":"text","label":"Security"},{"zoneId":"l-39","kind":"text","label":"Security guide"},{"zoneId":"l-40","kind":"text","label":"Threat model"},{"zoneId":"l-41","kind":"text","label":"Claims and evidence"},{"zoneId":"t-42","kind":"text","label":"Project"},{"zoneId":"l-43","kind":"text","label":"Known gaps"},{"zoneId":"l-44","kind":"text","label":"Upgrading to 0.2.0-alpha.1"},{"zoneId":"l-45","kind":"text","label":"Changelog"},{"zoneId":"l-46","kind":"text","label":"Index of all sections"},{"zoneId":"t-47","kind":"text","label":"Luxel v0.2 · Guide · part 2 of 2"},{"zoneId":"t-48","kind":"text","label":"Sessions (2)"},{"zoneId":"t-49","kind":"text","label":"Rate limits"},{"zoneId":"t-50","kind":"text","label":"Binding"},{"zoneId":"t-51","kind":"text","label":"What it limits"},{"zoneId":"t-52","kind":"text","label":"Default"},{"zoneId":"t-53","kind":"text","label":"rateLimiter"},{"zoneId":"t-54","kind":"text","label":"Every event and logout, by session or client address; and, by client address, every request without a session on the routes listed below (a:‹address>, one budget per address), plus route redirects in a bucket of their own (r:‹address>); an "},{"zoneId":"t-55","kind":"text","label":"address that is no route is not limited (Sprint 13.5, A8)"},{"zoneId":"t-56","kind":"text","label":"Memory: a burst of 30, refilling 10 per second"},{"zoneId":"t-57","kind":"text","label":"publicRateLimiter"},{"zoneId":"t-58","kind":"text","label":"Sign-in through public views, per address and per account"},{"zoneId":"t-59","kind":"text","label":"Memory: 10 attempts, then one every 6 s"},{"zoneId":"t-60","kind":"text","label":"anonymousRateLimiter"},{"zoneId":"t-61","kind":"text","label":"Events from anonymous sessions on public views, per address (IPv6 per /64)"},{"zoneId":"t-62","kind":"text","label":"Memory: a burst of 30, then one per second (RT-1)"},{"zoneId":"t-63","kind":"text","label":"sessionStartLimiter"},{"zoneId":"t-64","kind":"text","label":"Anonymous sessions started, per address (IPv6 per /64)"},{"zoneId":"t-65","kind":"text","label":"Memory: a burst of 600, then 10 per second (RT-2)"},{"zoneId":"t-66","kind":"text","label":"loadRateLimiter"},{"zoneId":"t-67","kind":"text","label":"Page and state loads, per session, or per address without one (Sprint 12, RT-6)"},{"zoneId":"t-68","kind":"text","label":"luxel-host: the configured rateLimiter (global when it is shared); otherwise memory: a burst of 30, then 10 per second"},{"zoneId":"t-69","kind":"text","label":"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)."},{"zoneId":"t-70","kind":"text","label":"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:"},{"zoneId":"t-71","kind":"text","label":"import { createPgRateLimiter } from '@luxel-framework/postgres';\n\nexport const rateLimiter = createPgRateLimiter({ pool, capacity: 30, refillPerSecond: 10 });\n"},{"zoneId":"t-72","kind":"text","label":"export const publicRateLimiter = createPgRateLimiter({ pool, capacity: 10, refillPerSecond: 1 / 6, table: 'luxel_login_bucket' });"},{"zoneId":"t-73","kind":"text","label":"A request without a session (none, expired or invalid) spends one token of its client address's rateLimiter bucket, a:‹address>, before it gets any answer on these routes: the state load (/_luxel/view/…), the event and sign-out routes, any "},{"zoneId":"t-74","kind":"text","label":"other /_luxel/ address, pages (the redirect to the sign-in page included), a page address with another method (405), and a dynamic surface's page and both manifest routes (in memory and from the shared store). These share that one budget, "},{"zoneId":"t-75","kind":"text","label":"so a burst from one address gets 429 with Retry-After whatever it asks for (Sprint 13.5, A8)."},{"zoneId":"t-76","kind":"text","label":"A route redirect (an id address's 302, a trailing slash's 308) spends from a bucket of its own per address, r:‹address> (the same size), not from a:‹address>."},{"zoneId":"t-77","kind":"text","label":"An address that is no route (404) is not limited."},{"zoneId":"t-78","kind":"text","label":"A request that carries no Cookie header takes its address token before the session lookup, so once the budget is spent it causes no lookup at all. A request with a cookie is looked up first (its bucket is its session's); when no session "},{"zoneId":"t-79","kind":"text","label":"matches, it then spends the address token: a cookie that matches no session still costs one lookup per request."},{"zoneId":"t-80","kind":"text","label":"A malformed event (another method, a query string) or a sign-out with another method is refused without a lookup."},{"zoneId":"t-81","kind":"text","label":"A limiter or session resolver that fails (it throws or rejects) gets 500."},{"zoneId":"t-82","kind":"text","label":"Not limited: public files (hashed, immutable), /healthz, /favicon.ico, an address that is no route (404), and the 421 / 503 a host answers for a name it does not serve or a revoked build. The default memory limiters keep at most "},{"zoneId":"t-83","kind":"text","label":"DEFAULT_LIMITER_KEYS (100 000) buckets each (the least recently used goes first); the PostgreSQL limiter removes idle rows but has no such bound."},{"zoneId":"t-84","kind":"text","label":"Behind a proxy, every request comes from the proxy's address, so every client shares one address bucket: every client without a session then shares one budget (30, then 10 a second by default), and a burst from one of them gets 429 for all "},{"zoneId":"t-85","kind":"text","label":"of them. Set LUXEL_TRUST_PROXY to your proxy's address or CIDR (several, separated by commas, behind several proxies). For a request from a listed peer the host reads X-Forwarded-For from the right, skips the listed proxies and takes the "},{"zoneId":"t-86","kind":"text","label":"first address that is not one. A request from any other peer keeps its socket address: a client that reaches the host directly cannot choose its address with a forged header. There is no trust-all value: 1, a CIDR wider than /8 (IPv4) or "},{"zoneId":"t-87","kind":"text","label":"/16 (IPv6) or entries that together cover more than a /6 (IPv4) or /14 (IPv6) refuses to start."},{"zoneId":"t-88","kind":"text","label":"Replay guard"},{"zoneId":"t-89","kind":"text","label":"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 "},{"zoneId":"t-90","kind":"text","label":"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 "},{"zoneId":"t-91","kind":"text","label":"claim in PostgreSQL, swept after expiry. With several nodes a token could be spent once per node, so use the shared one:"},{"zoneId":"t-92","kind":"text","label":"import { createPgReplayGuard } from '@luxel-framework/postgres';\nexport const replayGuard = createPgReplayGuard({ pool });"},{"zoneId":"t-93","kind":"text","label":"It keeps one row per nonce hash until the token expires, claimed with one atomic statement."},{"zoneId":"t-94","kind":"text","label":"Several nodes"},{"zoneId":"t-95","kind":"text","label":"With LUXEL_ENV=production and LUXEL_NODES above 1, the host refuses to start unless:"},{"zoneId":"t-96","kind":"text","label":"sessionStore is shared (PostgreSQL or delegated);"},{"zoneId":"t-97","kind":"text","label":"rateLimiter is shared;"},{"zoneId":"t-98","kind":"text","label":"with a static view: replayGuard and publicRateLimiter are shared too."},{"zoneId":"t-99","kind":"text","label":"The template's bindings carry the multi-node setup as comments:"},{"zoneId":"t-100","kind":"text","label":"import pg from 'pg';\nimport { createPgRateLimiter, createPgReplayGuard, createPgSessionStore } from '@luxel-framework/postgres';\nconst pool = new pg.Pool({ connectionString: process.env.DATABASE_URL });\n"},{"zoneId":"t-101","kind":"text","label":"export const sessionStore = createPgSessionStore({ pool });\nexport const rateLimiter = createPgRateLimiter({ pool, capacity: 30, refillPerSecond: 10 });\n"},{"zoneId":"t-102","kind":"text","label":"export const publicRateLimiter = createPgRateLimiter({ pool, capacity: 10, refillPerSecond: 1 / 6, table: 'luxel_login_bucket' });\nexport const replayGuard = createPgReplayGuard({ pool });"},{"zoneId":"t-103","kind":"text","label":"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 "},{"zoneId":"l-104","kind":"text","label":"Production"},{"zoneId":"t-105","kind":"text","label":"."},{"zoneId":"t-106","kind":"text","label":"Normalized inputs (Sprint 12)"},{"zoneId":"t-107","kind":"text","label":"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 "},{"zoneId":"t-108","kind":"text","label":"the sign-in limits and before your handler sees the value. NFKC also folds compatibility forms (full-width letters and other look-alikes), so ｖｉｃｔｉｍ and vic\\u200Btim are the account victim. A view's identity input is NFKC by default; write "},{"zoneId":"t-109","kind":"text","label":"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."},{"zoneId":"l-110","kind":"text","label":"Previous: Sessions"},{"zoneId":"l-111","kind":"text","label":"Previous: Server"},{"zoneId":"l-112","kind":"text","label":"Next: Production"},{"zoneId":"l-113","kind":"text","label":"Edit this page on GitHub"},{"zoneId":"t-114","kind":"text","label":"This page: 7.9 KB of JavaScript (Luxel's shared runtime), 0 KB from your app."},{"zoneId":"t-115","kind":"text","label":"Measured when the site is built: the runtime files this page loads, compressed as they are sent."},{"zoneId":"l-116","kind":"text","label":"GitHub"},{"zoneId":"l-117","kind":"text","label":"Discussions"},{"zoneId":"l-118","kind":"text","label":"Apache-2.0"},{"zoneId":"l-119","kind":"text","label":"Ties and losses"},{"zoneId":"t-120","kind":"text","label":"Made by IntiOps. The Luxel 0.1.0 betas are on npm (0.1.0-beta.1, 0.1.0-beta.2), with an alpha of 0.2 (0.2.0-alpha.1): no external security review yet."}],"events":[],"messages":{"network":"Could not reach the server. Check your connection and try again.","unexpected":"Something went wrong. Reload the page."},"extensions":{"render.dom@1":{"root":{"el":"div","class":"site site--en page--doc","children":[{"el":"header","class":"topbar","children":[{"zone":"l-1","el":"span","class":"brand"},{"el":"div","class":"nav","children":[{"zone":"l-2","el":"span","class":"nav-link"},{"zone":"l-3","el":"span","class":"nav-link"},{"zone":"l-4","el":"span","class":"nav-link"},{"zone":"l-5","el":"span","class":"nav-link"},{"zone":"l-6","el":"span","class":"nav-link"},{"zone":"l-7","el":"span","class":"nav-link"},{"zone":"l-8","el":"span","class":"nav-link"}]},{"zone":"l-9","el":"span","class":"lang"}]},{"el":"main","class":"main main--doc","children":[{"el":"div","class":"sidebar","children":[{"zone":"t-10","el":"p","class":"sidebar-version"},{"zone":"l-11","el":"span","class":"side-link side-link--version"},{"zone":"l-12","el":"span","class":"side-link side-link--search"},{"zone":"t-13","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-14","el":"span","class":"side-link"},{"zone":"l-15","el":"span","class":"side-link"},{"zone":"l-16","el":"span","class":"side-link"},{"zone":"l-17","el":"span","class":"side-link"}]},{"zone":"t-18","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-19","el":"span","class":"side-link"},{"zone":"l-20","el":"span","class":"side-link"},{"zone":"l-21","el":"span","class":"side-link"},{"zone":"l-22","el":"span","class":"side-link"},{"zone":"l-23","el":"span","class":"side-link"},{"zone":"l-24","el":"span","class":"side-link"},{"zone":"l-25","el":"span","class":"side-link"},{"zone":"l-26","el":"span","class":"side-link"},{"zone":"l-27","el":"span","class":"side-link"},{"zone":"l-28","el":"span","class":"side-link side-link--current"},{"zone":"l-29","el":"span","class":"side-link"},{"zone":"l-30","el":"span","class":"side-link"},{"zone":"l-31","el":"span","class":"side-link"},{"zone":"l-32","el":"span","class":"side-link"}]},{"zone":"t-33","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-34","el":"span","class":"side-link"},{"zone":"l-35","el":"span","class":"side-link"},{"zone":"l-36","el":"span","class":"side-link"},{"zone":"l-37","el":"span","class":"side-link"}]},{"zone":"t-38","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-39","el":"span","class":"side-link"},{"zone":"l-40","el":"span","class":"side-link"},{"zone":"l-41","el":"span","class":"side-link"}]},{"zone":"t-42","el":"p","class":"sidebar-group"},{"el":"div","class":"sidebar-links","children":[{"zone":"l-43","el":"span","class":"side-link"},{"zone":"l-44","el":"span","class":"side-link"},{"zone":"l-45","el":"span","class":"side-link"}]},{"zone":"l-46","el":"span","class":"side-link side-link--index"}]},{"el":"section","class":"article","children":[{"zone":"t-47","el":"p","class":"doc-meta"},{"zone":"t-48","el":"h1","class":"page-title"},{"el":"div","class":"block","children":[{"zone":"t-49","el":"h2","class":"section-title"},{"el":"div","class":"table-wrap","children":[{"el":"table","class":"table","children":[{"el":"thead","children":[{"el":"tr","children":[{"zone":"t-50","el":"th"},{"zone":"t-51","el":"th"},{"zone":"t-52","el":"th"}]}]},{"el":"tbody","children":[{"el":"tr","children":[{"zone":"t-53","el":"td"},{"el":"td","children":[{"zone":"t-54","el":"span"},{"zone":"t-55","el":"span"}]},{"zone":"t-56","el":"td"}]},{"el":"tr","children":[{"zone":"t-57","el":"td"},{"zone":"t-58","el":"td"},{"zone":"t-59","el":"td"}]},{"el":"tr","children":[{"zone":"t-60","el":"td"},{"zone":"t-61","el":"td"},{"zone":"t-62","el":"td"}]},{"el":"tr","children":[{"zone":"t-63","el":"td"},{"zone":"t-64","el":"td"},{"zone":"t-65","el":"td"}]},{"el":"tr","children":[{"zone":"t-66","el":"td"},{"zone":"t-67","el":"td"},{"zone":"t-68","el":"td"}]}]}]}]},{"zone":"t-69","el":"p","class":"para"},{"zone":"t-70","el":"p","class":"para"},{"el":"p","class":"code","children":[{"zone":"t-71","el":"span"},{"zone":"t-72","el":"span"}]},{"el":"p","class":"para","children":[{"zone":"t-73","el":"span"},{"zone":"t-74","el":"span"},{"zone":"t-75","el":"span"}]},{"el":"div","class":"list-wrap","children":[{"el":"ul","class":"list","children":[{"zone":"t-76","el":"li"},{"zone":"t-77","el":"li"},{"el":"li","children":[{"zone":"t-78","el":"span"},{"zone":"t-79","el":"span"}]},{"zone":"t-80","el":"li"},{"zone":"t-81","el":"li"}]}]},{"el":"p","class":"para","children":[{"zone":"t-82","el":"span"},{"zone":"t-83","el":"span"}]},{"el":"p","class":"para","children":[{"zone":"t-84","el":"span"},{"zone":"t-85","el":"span"},{"zone":"t-86","el":"span"},{"zone":"t-87","el":"span"}]},{"zone":"t-88","el":"h2","class":"section-title"},{"el":"p","class":"para","children":[{"zone":"t-89","el":"span"},{"zone":"t-90","el":"span"},{"zone":"t-91","el":"span"}]},{"zone":"t-92","el":"p","class":"code"},{"zone":"t-93","el":"p","class":"para"},{"zone":"t-94","el":"h2","class":"section-title"},{"zone":"t-95","el":"p","class":"para"},{"el":"div","class":"list-wrap","children":[{"el":"ul","class":"list","children":[{"zone":"t-96","el":"li"},{"zone":"t-97","el":"li"},{"zone":"t-98","el":"li"}]}]},{"zone":"t-99","el":"p","class":"para"},{"el":"p","class":"code","children":[{"zone":"t-100","el":"span"},{"zone":"t-101","el":"span"},{"zone":"t-102","el":"span"}]},{"el":"p","class":"para","children":[{"zone":"t-103","el":"span"},{"zone":"l-104","el":"span"},{"zone":"t-105","el":"span"}]},{"zone":"t-106","el":"h2","class":"minor"},{"el":"p","class":"para","children":[{"zone":"t-107","el":"span"},{"zone":"t-108","el":"span"},{"zone":"t-109","el":"span"}]}]},{"el":"div","class":"pager","children":[{"zone":"l-110","el":"span","class":"pager-link"},{"zone":"l-111","el":"span","class":"pager-link"},{"zone":"l-112","el":"span","class":"pager-link pager-link--next"}]},{"zone":"l-113","el":"span","class":"edit-link"}]}]},{"el":"footer","class":"footer","children":[{"zone":"t-114","el":"p","class":"jsline"},{"zone":"t-115","el":"p","class":"jsnote"},{"el":"div","class":"footer-links","children":[{"zone":"l-116","el":"span","class":"footer-link"},{"zone":"l-117","el":"span","class":"footer-link"},{"zone":"l-118","el":"span","class":"footer-link"},{"zone":"l-119","el":"span","class":"footer-link"}]},{"zone":"t-120","el":"p","class":"made"}]}]}},"projection.slots@1":{"template":"/_luxel/a/docs-v0-2-sessions-2.52360202a0d3.html","map":"/_luxel/a/docs-v0-2-sessions-2.slots.62f87bca1830.json"}}}