ident
All repositories: gitoria
13.2 KB
// project.hl — ident.worldapi.org: THE MAP. Config, routes and wiring; the logic lives in lib/. Concept: CONCEPT.md// (the creator's).//// WHERE THINGS ARE (one line per feature; README.md "Files" has the full list):// the login: email → code, limits per address / IP, the code page lib/login.hl (codes, IP buckets: lib/login-helpers.hl)// the account, its sessions, sign out everywhere, time zone lib/accounts.hl// identities, the short id, avatar lib/identities.hl (checks, label: lib/identities-helpers.hl)// apps, connections, the login button + exchange, an invite's login lib/apps.hl (checks, return URL: lib/apps-helpers.hl)// the identity selector (pick ids, the choice) lib/selector.hl (browser half: selector.js)// invites (ident#22) lib/invites.hl (checks: lib/invites-helpers.hl)// notifications: kinds, sending, inbox, per-app switches lib/notify.hl (checks, orders: lib/notify-helpers.hl)// mail (codes, invitations; IDENT_MAIL_SINK) lib/mail.hl// delivery: the daily mail at 17:00 in the user's zone, urgent at once lib/delivery.hl (texts, clock: lib/delivery-helpers.hl)// the function routes (/login, /api/*, /invite/:token, /code) lib/api.hl (plumbing: lib/api-helpers.hl, lib/jsoncheck.hl)// shared small helpers (storage dir, env, lists, text checks) lib/util.hl// an identity's page, "Used in" (ident#26) lib/usedin.hl (texts: lib/usedin-helpers.hl; page: components/identity.hl)// identity access, one key per identity (ident#27) lib/access.hl (page: components/access.hl; the app's check: POST /api/introspect)// pages: shell, sign-in + identities, start, apps, inbox, per-app components/*.hl; CSS components/styles.hl// /docs, what ident is (ident#45): the text is docs/IDENT.md lib/docs.hl (page: components/docs.hl)//// THE FLOWS (README "How apps use ident", "How apps send notifications", "Invites"):// GET /login?key=<api key>&return=<url> → error page, or → /signin/<rid> (sign in, choose the identity,// → <return url>?ident_code=<one-time code>)// POST /api/exchange { key, secret, code, fields? } → { identity, + the asked fields }, POST /api/profile (ident#11)// GET /selector.js, GET /api/selector/identities?key=, POST /api/selector/choose?key= {identity} → { code }// POST /api/code { email } → { email } | 400/429 { error } (a function route: the per-IP limit needs the request)// GET /code, /signin/<rid>/code the code form for this session's pending address, or → / resp. /signin/<rid>// Deploy (Byrodin): HL_HOST=127.0.0.1 binds loopback only (hl:web reads HL_HOST, hybriel#24),// IDENT_PORT the port.import WebFramework from 'hl:web'import { exit } from 'hl:proc'import { envString } from './lib/util.hl'import Styles from './components/styles.hl'import { dark, darker } from './shared/tokens.hl'import { appLogin, apiExchange, apiProfile, apiMigrateIds, apiCode, apiSelectorIdentities, apiSelectorChoose, apiInvites, apiInvitesList, apiInvitesGet, apiInvitesRevoke, inviteLink, apiKinds, apiNotify, apiIntrospect, apiOnline, notFoundApi, notFoundRoute, codeRoute, signinCodeRoute, embedSigninRoute, embedGo, welcomeRoute, pageServer } from './lib/api.hl'import Mail from './lib/mail.hl'import Delivery from './lib/delivery.hl'import { sessionHooks, dropSessionUser, signedOutAudience } from './lib/accounts.hl'import { shortIdsBackfilled } from './lib/identities.hl'import { gitoriaWildcardAdded } from './lib/apps.hl'// ident#23: statics run on first use — touching it here gives every older identity its short id at bootconsole.log('ident: ' + shortIdsBackfilled + ' identities got their short id')console.log('ident: ' + gitoriaWildcardAdded + ' app got the wildcard origin of its repo addresses')import Home from './components/home.hl'import Start from './components/start.hl'import Apps from './components/apps.hl'import Access from './components/access.hl'import Inbox from './components/inbox.hl'import Identity from './components/identity.hl'import AppSettings from './components/appsettings.hl'import NotFound from './components/notfound.hl'import Embed from './components/embed.hl'import ErrorPage from './components/error.hl'import Docs from './components/docs.hl'static siteName = "ident"appTitle = siteName// THE PAGES' POLICY, as <meta> (hl:web has no setting for response headers of a page: reports/SI-sec.md). No <base>, no plugin// objects, forms only to ident itself, no frames in, connections only to ident itself; the pages need their inline module// (hl:web's boot script) so scripts keep 'unsafe-inline'. `frame-ancestors` and X-Frame-Options cannot be set from a meta.meta = [{ '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'" }{ name = 'referrer' content = 'same-origin' }]styles = Styles// ---- THE INSTALLABLE APP (mission 046, as calendar#3): hl:web generates the web app manifest// (/__hl/manifest.webmanifest, linked in every head with the apple-touch-icon and theme-color)// from these, and the service worker (/__hl/sw.js) from `offline`. No JavaScript of ours.// Icons: icons/ (icon.svg is the source, README "PWA"). Theme colour = the header's colour (token// `darker`), background `dark` — the same in every app (mission 046); the icon carries the accent.appThemeColor = darker.valueappBackgroundColor = dark.valueappFavicon = '/favicon.ico'appTouchIcon = '/icons/apple-touch-icon.png'appIcons = [{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'any' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'any' }{ src = '/icons/icon-192.png' sizes = '192x192' purpose = 'maskable' }{ src = '/icons/icon-512.png' sizes = '512x512' purpose = 'maskable' }]// OFFLINE, WITHOUT PERSONAL DATA: the worker keeps only `/start` (components/start.hl, a page// with no data — never `/`, whose copy would hold the signed-in address and identities) and the// shell's assets. The installed app starts at `/start` (appManifest); online the shell's reachability event// (main.hl) sends it on to `/`, offline the header says it is offline. Every other page offline// is the worker's "Unavailable offline" (README "PWA").offline = [ Start ]appManifest = { start_url = '/start' }// ---- THE ROUTES: files, the function routes (lib/api.hl), the pages (components/) ----------------routes = [{ pattern = "/favicon.ico" file = "./icons/favicon.ico" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }{ pattern = "/icons/icon-192.png" file = "./icons/icon-192.png" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }{ pattern = "/icons/icon-512.png" file = "./icons/icon-512.png" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }{ pattern = "/icons/apple-touch-icon.png" file = "./icons/apple-touch-icon.png" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }{ pattern = "/icons/icon.svg" file = "./icons/icon.svg" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }{ pattern = "/login" function = appLogin }// the login error page (ident#41) is rendered by lib/api-helpers.hl errorPage; this entry (behind the function route, which wins) only registers its component and its Style{ pattern = "/login" component = ErrorPage }{ pattern = "/api/exchange" function = apiExchange }{ pattern = "/api/profile" function = apiProfile }{ pattern = "/api/migrate-ids" function = apiMigrateIds }{ pattern = "/api/code" function = apiCode }{ pattern = "/api/selector/identities" function = apiSelectorIdentities }{ pattern = "/api/selector/choose" function = apiSelectorChoose }{ pattern = "/api/invites" function = apiInvites }{ pattern = "/api/invites/list" function = apiInvitesList }{ pattern = "/api/invites/get" function = apiInvitesGet }{ pattern = "/api/invites/revoke" function = apiInvitesRevoke }{ pattern = "/invite/:token" function = inviteLink }{ pattern = "/api/introspect" function = apiIntrospect }{ pattern = "/api/kinds" function = apiKinds }{ pattern = "/api/notify" function = apiNotify }{ pattern = "/selector.js" file = "./selector.js" headers = { 'Cache-Control' = 'private, no-cache' 'X-Content-Type-Options' = 'nosniff' } }// health route (no longer called by the shell): 204{ pattern = "/api/online" function = apiOnline }{ pattern = "/api/*" function = notFoundApi }// THE CODE PAGE (ident#20): renders Home through the framework's page render — it needs the server, BY REFERENCE{ pattern = "/code" function = codeRoute }{ pattern = "/signin/:rid/code" function = signinCodeRoute }{ pattern = "/signin/:rid/welcome" function = welcomeRoute }{ pattern = "/embed/signin" function = embedSigninRoute }{ pattern = "/embed/go" function = embedGo }// the frame's page is rendered by embedSignin (above, it wins); this entry only registers the component and its shell with the client{ pattern = "/embed/signin" component = Embed }{ pattern = "/" component = Home }{ pattern = "/start" component = Start }{ pattern = "/signin/:rid" component = Home }{ pattern = "/apps" component = Apps }{ pattern = "/identity/:iid" component = Identity }{ pattern = "/access" component = Access }{ pattern = "/inbox" component = Inbox }{ pattern = "/inbox/:cid" component = AppSettings }// what ident is and how it works (ident#45): docs/IDENT.md, public{ pattern = "/docs" component = Docs }// anything else: the 404 page, in the shell (last: every route above wins){ pattern = "/*" function = notFoundRoute }]// the mailer's result handlers live on an INSTANCE of lib/mail.hlmail = new Mail()// THE DAILY MAIL's clock (one round a minute) lives on an INSTANCE of lib/delivery.hldelivery = new Delivery()sessionDir = envString('IDENT_SESSIONS', null, true)port = toNumber(envString('IDENT_PORT', '8351', true))// THE LISTENER's interface: hl:web reads HL_HOST (or HOST) itself (hybriel#24): 127.0.0.1 on// Byrodin behind nginx; unset = 0.0.0.0 (dev on Loreana).// IDENT_WATCH=0 turns the dev watcher off (the container: a deploy is an rsync + restart,// half-copied .hl files must not be re-analysed); unset = on, as before.watching = envString('IDENT_WATCH', null, true) != '0'// WHO A PUSHED EVENT IS FOR: "signed out everywhere" reaches every open connection whose// session is the account's (checked before dropUserSessions clears the sessions).audience = {signedOutAll = signedOutAudience}// ident's OWN COOKIE NAME. Cookies are per host, not per port: with the default `hlsid` an app// on the same host (tickets on :8350) and ident would overwrite each other's session cookie// → hl:web's `sessionCookie` setting (hybriel#10/#17).// SECURITY (mission SI): behind https (IDENT_PUBLIC_URL starts with https://, as on Byrodin) the cookie is `Secure` and carries// the `__Host-` prefix — a browser then refuses to let any sibling host (another *.worldapi.org app) plant or overwrite it// with a Domain cookie (session fixation: hl:web keeps the session id across the sign-in, hybriel gap in reports/SI-sec.md).// Dev and the gates run on http: the old name, no flag.publicUrl = envString('IDENT_PUBLIC_URL', null, true)behindHttps = publicUrl != null && publicUrl.startsWith('https://')sessionCookie = behindHttps ? '__Host-identsid' : 'identsid'// ident takes no file in any emit (the avatar travels as a small data URL string): /__hl/upload is open to a session nobody// signed in (it mints one), so its default of 1 GiB per upload was an anonymous memory sink. Nothing may be uploaded here.uploadMax = 0// hl:web now adds X-Frame-Options: SAMEORIGIN to every answer that names none. ident's embed page names its framing apps by// `frame-ancestors` (lib/api-helpers.hl framedBy), which cannot be said in X-Frame-Options, so the default is switched off;// every other answer keeps the framework's CSP `frame-ancestors 'self'` and ident's own DENY headers.pageHeaders = { 'X-Frame-Options' = null }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)// SIGN OUT EVERYWHERE deletes every session of the account (ticket #19, lib/accounts.hl dropUserSessions): the// session store is this server'spageServer.server = serversessionHooks.server = serversessionHooks.dropUser = dropSessionUser// A fault while the program starts is fatal (hybriel#65): exit 1 at once, so the container's start fails visibly instead of// serving a half-started app. A fault in the event loop (a request, a delivery) is only logged; the server keeps serving.on Error(e) {if (e.phase == 'startup') {console.log('ident: startup error: ' + e.message)exit(1)}console.log('ident: error: ' + e.message)}
Branches
Latest commits
- 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
- e36f4516Merge branch 'f14-online' into mainIdent
- 2c5eac91|||PR ident#38 online state without probe timermre
- bf1980f2Merge branch 'v56-day56' into mainIdent
- 62ae0adf|||PR ident: vendor Hybriel day56mre
- 0d18abc4Merge branch 'f13-avatar' into mainIdent
- 2a99730a|||PR ident#37 avatar in hlmre
- fa4ed25bMerge branch 'f11-upsert' into mainIdent
- 8f3d9bc9|||PR ident#42 keyed upsert and removemre
- 675493b1ident#42: editing an identity upserts the one edited row (face editIdentity answers { identity, row }); a create or delete keeps the whole list because the rows' position-dependent parts (default, Delete, Identity n) changemre
- 45e55303ident#42: an app write patches one row: upsert on create, edit and new secret, one-argument remove on delete; the faces answer the changed app (or the deleted id), not the whole listmre
- 991641d4Merge branch 'f10-access' into mainIdent
- e56d8273|||PR ident#34 part 4: access and inbox fixed classesmre
- df7696dbident#34: tests: access ticks selector quoting fixmre
- 7215903eident#34: access: the unstyled classes all, app, tick, apptick, plus are dropped; the gate finds the app ticks by input[name=app]mre
- 69b0a0ceident#34: access: the pick buttons use Style.pickCard instead of class pickmre
- dc702419Merge branch 'f9-choose' into mainIdent
- 8caec771|||PR ident#34 restore .choose hookmre
- 0dbff960Merge branch 'f8-shared' into mainIdent
- d69665f6|||PR ident#34 part 3: shared look classes (wide, avatar, chip/used, conn, choose, who, inboxlink) moved to statics or droppedmre