gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita77d1b22a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemrea77d1b22/project.hl

11.6 KB

  1. // project.hl — ident.worldapi.org: THE MAP. Config, routes and wiring; the logic lives in lib/. Concept: CONCEPT.md
  2. // (the creator's).
  3. //
  4. // WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):
  5. // the login: email → code, limits per address / IP, the code page lib/login.hl (codes, IP buckets: lib/login-helpers.hl)
  6. // the account, its sessions, sign out everywhere, time zone lib/accounts.hl
  7. // identities, the short id, avatar lib/identities.hl (checks, label: lib/identities-helpers.hl)
  8. // apps, connections, the login button + exchange, an invite's login lib/apps.hl (checks, return URL: lib/apps-helpers.hl)
  9. // the identity selector (pick ids, the choice) lib/selector.hl (browser half: selector.js)
  10. // invites (ident#22) lib/invites.hl (checks: lib/invites-helpers.hl)
  11. // notifications: kinds, sending, inbox, per-app switches lib/notify.hl (checks, orders: lib/notify-helpers.hl)
  12. // mail (codes, invitations; IDENT_MAIL_SINK) lib/mail.hl
  13. // delivery: the daily mail at 17:00 in the user's zone, urgent at once lib/delivery.hl (texts, clock: lib/delivery-helpers.hl)
  14. // the function routes (/login, /api/*, /invite/:token, /code) lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)
  15. // shared small helpers (storage dir, env, lists, text checks) lib/util.hl
  16. // an identity's page, "Used in" (ident#26) lib/usedin.hl (texts: lib/usedin-helpers.hl; page: components/identity.hl)
  17. // pages: shell, sign-in + identities, start, apps, inbox, per-app components/*.hl; CSS components/styles.hl
  18. //
  19. // THE FLOWS (README "How apps use ident", "How apps send notifications", "Invites"):
  20. // GET /login?key=<api key>&return=<url> → error page, or → /signin/<rid> (sign in, choose the identity,
  21. // → <return url>?ident_code=<one-time code>)
  22. // POST /api/exchange { key, secret, code } → { identity } (the identity's short id only)
  23. // GET /selector.js, GET /api/selector/identities?key=, POST /api/selector/choose?key= {identity} → { code }
  24. // POST /api/code { email } → { email } | 400/429 { error } (a function route: the per-IP limit needs the request)
  25. // GET /code, /signin/<rid>/code the code form for this session's pending address, or → / resp. /signin/<rid>
  26. // Deploy (Byrodin): HL_HOST=127.0.0.1 binds loopback only (hl:web reads HL_HOST, hybriel#24),
  27. // IDENT_PORT the port.
  28. import WebFramework from 'hl:web'
  29. import { env } from 'hl:proc'
  30. import Styles from './components/styles.hl'
  31. import { dark, darker } from './shared/tokens.hl'
  32. import { appLogin, apiExchange, apiMigrateIds, apiCode, apiSelectorIdentities, apiSelectorChoose, apiInvites, apiInvitesList, apiInvitesGet, apiInvitesRevoke, inviteLink, apiKinds, apiNotify, apiOnline, notFoundApi, notFoundPage, codePage, embedSignin, embedGo, welcomePage } from './lib/api.hl'
  33. import Mail from './lib/mail.hl'
  34. import Delivery from './lib/delivery.hl'
  35. import { sessionHooks, dropUserSessions } from './lib/accounts.hl'
  36. import { shortIdsBackfilled } from './lib/identities.hl'
  37. // ident#23: statics run on first use — touching it here gives every older identity its short id at boot
  38. console.log('ident: ' + shortIdsBackfilled + ' identities got their short id')
  39. import Home from './components/home.hl'
  40. import Start from './components/start.hl'
  41. import Apps from './components/apps.hl'
  42. import Inbox from './components/inbox.hl'
  43. import Identity from './components/identity.hl'
  44. import AppSettings from './components/appsettings.hl'
  45. import NotFound from './components/notfound.hl'
  46. import Embed from './components/embed.hl'
  47. static siteName = "ident"
  48. appTitle = siteName
  49. // THE PAGES' POLICY, as <meta> (hl:web has no setting for response headers of a page: reports/SI-sec.md). No <base>, no plugin
  50. // objects, forms only to ident itself, no frames in, connections only to ident itself; the pages need their inline module
  51. // (hl:web's boot script) so scripts keep 'unsafe-inline'. `frame-ancestors` and X-Frame-Options cannot be set from a meta.
  52. meta = [
  53. { 'http-equiv' = 'Content-Security-Policy' content = "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob: http: https:; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-src 'none'; worker-src 'self'; manifest-src 'self'" }
  54. { name = 'referrer' content = 'same-origin' }
  55. ]
  56. styles = Styles
  57. // ---- THE INSTALLABLE APP (mission 046, as calendar#3): hl:web generates the web app manifest
  58. // (/__hl/manifest.webmanifest, linked in every head with the apple-touch-icon and theme-color)
  59. // from these, and the service worker (/__hl/sw.js) from `offline`. No JavaScript of ours.
  60. // Icons: icons/ (icon.svg is the source, README "PWA"). Theme colour = the header's colour (token
  61. // `darker`), background `dark` — the same in every app (mission 046); the icon carries the accent.
  62. appThemeColor = darker.value
  63. appBackgroundColor = dark.value
  64. appFavicon = '/favicon.ico'
  65. appTouchIcon = '/icons/apple-touch-icon.png'
  66. appIcons = [
  67. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }
  68. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }
  69. { src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }
  70. { src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }
  71. ]
  72. // OFFLINE, WITHOUT PERSONAL DATA: the worker keeps only `/start` (components/start.hl, a page
  73. // with no data — never `/`, whose copy would hold the signed-in address and identities) and the
  74. // shell's assets. The installed app starts at `/start` (appManifest); online the shell's probe
  75. // (main.hl) sends it on to `/`, offline the header says it is offline. Every other page offline
  76. // is the worker's "Unavailable offline" (README "PWA").
  77. offline = [ Start ]
  78. appManifest = { start_url = '/start' }
  79. // ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------
  80. routes = [
  81. { pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  82. { pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  83. { pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  84. { pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  85. { pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  86. { pattern = "/login" function = appLogin }
  87. { pattern = "/api/exchange" function = apiExchange }
  88. { pattern = "/api/migrate-ids" function = apiMigrateIds }
  89. { pattern = "/api/code" function = apiCode }
  90. { pattern = "/api/selector/identities" function = apiSelectorIdentities }
  91. { pattern = "/api/selector/choose" function = apiSelectorChoose }
  92. { pattern = "/api/invites" function = apiInvites }
  93. { pattern = "/api/invites/list" function = apiInvitesList }
  94. { pattern = "/api/invites/get" function = apiInvitesGet }
  95. { pattern = "/api/invites/revoke" function = apiInvitesRevoke }
  96. { pattern = "/invite/:token" function = inviteLink }
  97. { pattern = "/api/kinds" function = apiKinds }
  98. { pattern = "/api/notify" function = apiNotify }
  99. { pattern = "/selector.js" file = "./selector.js" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  100. { pattern = "/avatar.js" file = "./avatar.js" headers = { 'Cache-Control' = 'no-cache' 'X-Content-Type-Options' = 'nosniff' } }
  101. // the offline probe of the shell (components/main.hl): 204
  102. { pattern = "/api/online" function = apiOnline }
  103. { pattern = "/api/*" function = notFoundApi }
  104. // THE CODE PAGE (ident#20): renders Home through the framework's page render — it needs the server, BY REFERENCE
  105. { pattern = "/code" function = (route, req) => { return codePage(route, req, &server, Home) } }
  106. { pattern = "/signin/:rid/code" function = (route, req) => { return codePage(route, req, &server, Home) } }
  107. { pattern = "/signin/:rid/welcome" function = (route, req) => { return welcomePage(route, req, &server, Home) } }
  108. { pattern = "/embed/signin" function = (route, req) => { return embedSignin(route, req, &server, Embed) } }
  109. { pattern = "/embed/go" function = embedGo }
  110. // the frame's page is rendered by embedSignin (above, it wins); this entry only registers the component and its shell with the client
  111. { pattern = "/embed/signin" component = Embed }
  112. { pattern = "/" component = Home }
  113. { pattern = "/start" component = Start }
  114. { pattern = "/signin/:rid" component = Home }
  115. { pattern = "/apps" component = Apps }
  116. { pattern = "/identity/:iid" component = Identity }
  117. { pattern = "/inbox" component = Inbox }
  118. { pattern = "/inbox/:cid" component = AppSettings }
  119. // anything else: the 404 page, in the shell (last: every route above wins)
  120. { pattern = "/*" function = (route, req) => { return notFoundPage(route, req, &server, NotFound) } }
  121. ]
  122. // the mailer's result handlers live on an INSTANCE of lib/mail.hl
  123. mail = new Mail()
  124. // THE DAILY MAIL's clock (one round a minute) lives on an INSTANCE of lib/delivery.hl
  125. delivery = new Delivery()
  126. sessionDir = env('IDENT_SESSIONS') != null ? env('IDENT_SESSIONS') : null
  127. port = env('IDENT_PORT') != null ? toNumber(env('IDENT_PORT')) : 8351
  128. // THE LISTENER's interface: hl:web reads HL_HOST (or HOST) itself (hybriel#24): 127.0.0.1 on
  129. // Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).
  130. // IDENT_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,
  131. // half-copied .hl files must not be re-analysed); unset = on, as before.
  132. watching = env('IDENT_WATCH') != '0'
  133. // WHO A PUSHED EVENT IS FOR: "signed out everywhere" reaches every open connection whose
  134. // session is the account's (checked before dropUserSessions clears the sessions).
  135. audience = {
  136. signedOutAll = (accountId, session) => { return session != null && session.user != null && session.user.id == accountId }
  137. }
  138. // ident's OWN COOKIE NAME. Cookies are per host, not per port: with the default `hlsid` an app
  139. // on the same host (tickets on :8350) and ident would overwrite each other's session cookie
  140. // → hl:web's `sessionCookie` setting (hybriel#10/#17).
  141. // SECURITY (mission SI): behind https (IDENT_PUBLIC_URL starts with https://, as on Byrodin) the cookie is `Secure` and carries
  142. // the `__Host-` prefix — a browser then refuses to let any sibling host (another *.worldapi.org app) plant or overwrite it
  143. // with a Domain cookie (session fixation: hl:web keeps the session id across the sign-in, hybriel gap in reports/SI-sec.md).
  144. // Dev and the gates run on http: the old name, no flag.
  145. publicUrl = env('IDENT_PUBLIC_URL')
  146. behindHttps = publicUrl != null && publicUrl.startsWith('https://')
  147. sessionCookie = behindHttps ? '__Host-identsid' : 'identsid'
  148. // ident takes no file in any emit (the avatar travels as a small data URL string): /__hl/upload is open to a session nobody
  149. // signed in (it mints one), so its default of 1 GiB per upload was an anonymous memory sink. Nothing may be uploaded here.
  150. uploadMax = 0
  151. server = new WebFramework(routes = routes, styles = styles, audience = audience, minify = true, port = port, watchMode = watching, sessionCookie = sessionCookie, sessionSecure = behindHttps, uploadMax = uploadMax, sessionMaxAge = 3122064000)
  152. // SIGN OUT EVERYWHERE deletes every session of the account (ticket #19, lib/accounts.hl dropUserSessions): the
  153. // session store is this server's
  154. sessionHooks.dropUser = (userId) => { return dropUserSessions(&server, userId) }

Branches

Latest commits

  • a77d1b22ident#31: the welcome form keeps editId a plain value (browser gate), README, wider rows in the framemre
  • 5c481bfdident#31: sign in to ident inside the selector's panel (email, code, identity in an iframe; a new address goes to ident in the same tab and comes back)mre
  • 061abfe2ident: the apps gate waits until the test app's login button stops moving before it clicks (the page grows after load and the click missed about every second run)mre
  • 45f7e4daident: the user menu's Sign out waits for the server before it reloads (the apps gate failed because the session could still be signed in)mre
  • f07658c7ident: home page shows the account once (account bar removed, the user menu carries email, Sign out, Sign out everywhere); wildcard origins https://*.domain for apps on many subdomains; gates follow (WIP: gates not re-run after the last edits)mre
  • f2c43bbbtheme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 6d4f996esessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 029eb5e5deploy: security gate (tests/security.mjs)mre
  • d3c065a8security audit (SI): uploadMax 0, Secure __Host- cookie behind https, headers on function routes/files, page CSP+referrer meta, app/identity caps, tests/security.mjs, reportmre
  • 5561a0cbreport I4-mobilemre
  • 4ca2ed20404 page in the shell (viewport, status 404, way home); phone: account actions live in the user menu so the open menu covers nothing; mobile gate; signoutall waits for a cold startmre
  • 9baad745tests: browser gate waits for the reloaded document (offline reload race under CPU throttle); HL_CPU_THROTTLE knobmre
  • b96796bdtests: wait for hydration before real clicks after a navigation (H2)mre
  • 9722964fre-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c9b196c9tests/iplimit: wait for the welcome form itself after B's first login (identities list renders before it); mission 017 reportmre
  • 72e0f587ident#26: identity page with "Used in" (app, since, last use, Notif. chip, empty state); lastLogin recorded at exchange; gates + lisbeth E2E; mission 016 reportmre
  • 94576fbcident#26 WIP: identity page /identity/:iid with "Used in" (app, since, last use, Notif. chip), lastLogin recorded at exchange, "Used in…" link on the identities list; apps gate 4b, e2e-usedin.mjsmre
  • 349cb502tests/invites: wait for hydration on the code page before entering the code (native GET submit raced the welcome form); mission 015 reportmre
  • d1bf4720tests: no hard-coded ports — every gate's ports and fixture origins come from <GATE>_PORT / _CHROME env (defaults unchanged; Bob/fixture origins follow, selector cookie name too)mre
  • 6280c92fre-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre