gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit436206fc436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre436206fc/project.hl

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

Branches

Latest commits

  • 436206fcident#47: deploy.sh runs the sign-in gate on the deploy's own port slot, like the sessionwrites and docs gates (the default 8700 can be taken by another process)mre
  • a4887ea3ident#47: the selector's sign-in frame no longer has a Continue button; the identity row itself is the link (gate tests/signin.mjs fails on the old code)mre
  • d8ec703dident#45: /docs shows docs/IDENT.md (hl:markdown, vendored from ac1ed9da), one Docs entry in the main menu, README for developers only, gates tests/docs.mjs and tests/sessionwrites.mjs in deploy.shmre
  • ec6aad35Merge branch 'a28g-amp-callsites' into d45-docsmre
  • 6bfbd3f2ident#45: docs/IDENT.md, what ident is and how it works; CONCEPT.md marks one id per app as droppedmre
  • c0edca26ident#28 A28G: write & at every call that hands a session to an &-parameter; gate tests/sessionwrites.mjs pins that sign-in, pending address, embed sign-in and selector land in the session filesmre
  • 80965c08ident#28: README says the deploy goes through the standbymre
  • 2f41670cident#28: ident-standby service on port 45012 (no background round in the standby) and deploy.sh hands over through standby-swap.shmre
  • a544b261ident#28: README names the new vendored Hybrielmre
  • 716860b0ident#28: gates follow Hybriel ac1ed9da (lazy sessions, meta attribute order, JSON key order, default X-Frame-Options switched off for the embed page)mre
  • 889e00fbident#28: Hybriel master ac1ed9da (sessions reload a newer file, a replayed reconnect carries the server session); a startup fault exits 1 (on Error)mre
  • f5a55f8aident#11: apps can ask for nickname, firstname and lastname (fields list on /api/exchange, new POST /api/profile); empty fields come back null; gate checks, READMEmre
  • d8be66ebident: report and log line for the widget cache and frame height changemre
  • 2068f61aident#31: browsers revalidate the widget scripts on every load; the sign-in frame is exactly as tall as the current step (the frame page reports its height, selector.js accepts it from ident only)mre
  • a22d2daaident#31: the sign-in frame is no taller than the tallest step needs (plain CSS height per width), gate check for itmre
  • 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