ident
All repositories: gitoria
2.7 KB
// lib/login-helpers.hl — what lib/login.hl looks up: making a six-digit code and its hash, and the client's IP// BUCKET of the per-IP limit. No table access. Statics only.import { randomBytes, sha256 } from 'hl:crypto'// ---- codes --------------------------------------------------------------------------// six digits from the kernel CSPRNG (randomBytes answers hex)static newOtp = () => {hex = randomBytes(8)let n = 0let i = 0while (i < 12) {n = (n * 16 + '0123456789abcdef'.indexOf(hex[i])) % 1000000i = i + 1}let s = '' + nwhile (s.length < 6) { s = '0' + s }return s}static otpHash = (email, code) => { return sha256(email + ':' + code) }// ---- the client's IP bucket (mission 006 (old 010)) -------------------------------------------// `ip` is the X-Client-IP header nginx sets on Byrodin (CF-Connecting-IP when the request// really came through Cloudflare, else the TCP peer; nginx OVERWRITES what a client sent),// or null when there is none (dev without nginx: hl:web's req.remoteAddress would be nginx's; hl:http1 did not expose the// connection's peer address). The bucket:// no header / empty → 'direct' ONE SHARED BUCKET for every header-less request// IPv4 (also ::ffff:a.b.c.d) → the address// IPv6 → its /64 prefix ('2a01:4f9:3080:1126::/64'): one client// usually owns a whole /64, so per-address would not limit it// anything else → the text itself (lowercased, cut to 64 chars)static hexDigits = '0123456789abcdef'static stripZeros = (g) => {let t = gwhile (t.length > 1 && t[0] == '0') { t = t.slice(1, t.length) }return t}static ipBucket = (ip) => {if (ip == null || hlTypeName(ip) != 'String') { return 'direct' }let t = ip.trim().toLowerCase()if (t == '') { return 'direct' }if (t.length > 64) { t = t.slice(0, 64) }if (!t.includes(':')) { return t }// an IPv4-mapped IPv6 address counts as its IPv4 addressif (t.includes('.')) { return t.slice(t.lastIndexOf(':') + 1, t.length) }let head = tlet tail = ''gap = t.indexOf('::')if (gap >= 0) {head = t.slice(0, gap)tail = t.slice(gap + 2, t.length)}groups = head == '' ? [] : head.split(':')rest = tail == '' ? [] : tail.split(':')if (gap >= 0) {let fill = 8 - groups.length - rest.lengthwhile (fill > 0) {groups.push('0')fill = fill - 1}}for (g of rest) { groups.push(g) }if (groups.length != 8) { return t }out = []let i = 0while (i < 4) {let g = groups[i]if (g == '' || g.length > 4) { return t }let j = 0while (j < g.length) {if (!hexDigits.includes(g[j])) { return t }j = j + 1}out.push(stripZeros(g))i = i + 1}return out.join(':') + '::/64'}
Branches
Latest commits
- d6da2d02tests: delivery and migration gate ports from env (DELIVERY_GATE_PORT, DELIVERY_GATE_CHROME, MIGRATION_GATE_CHROME) — hard-coded 8700-8719 collided with a worker during deploymre
- 7276a008ident mission 013: re-vendor Hybriel master f9614007 (#200, #202 mpackdb copy fix); gates and e2e rerunmre
- e13e30c3ident mission 013: report, mission, repro, LOGmre
- eff734f3ident mission 013: in-place sign-out also closes the code step (no leftover code form); checksmre
- b7a61546ident mission 013: e2e — in-place main-menu mark kept as a known gapmre
- 59b43d81ident mission 013: sign out everywhere keeps this browser's own (signed-out) session so the page goes on in placemre
- 716e14ffident mission 013: browser gate — Bob signs out everywhere (no second code request)mre
- 5885f1c9ident mission 013 step 2: stopgap reload removed (in-place sign-in/out reach the shell via emit, notices back, route-marked main menu), gates updatedmre
- 734ac0a9ident mission 013 step 1: re-vendor Hybriel ce6f2e0a (plugins whole; bin/ is git-ignored)mre
- b37875ccident mission 012 part 3: real-Chrome fixes (brand 44 px, identity form width), e2e walk, report, logmre
- f989c2ebident mission 012: stopgap reload after in-place sign-in/sign-out (until hybriel#193), gates wait for cold start, welcome end reloadsmre
- 443291d4ident mission 012: /start on its own shell (no account), browser gate 152/0, reportmre
- 021dd0fcident mission 012: browser gate waits cold start (IDENT_COLD_MS), header selectors, e2e checks; shell events from a page do not reach it (probe), current not marked, account-bar link 44 pxmre
- 97f77b07ident mission 012 (WIP): onto the layouts theme dbe3de7, shell on AppHeader/MainMenu/UserMenu/Sidebar + ContentFirst, styles cut, check-theme gatemre
- 8e4f435bpaths: projects moved into /media/STORAGE/projects/WorldAPI/mre
- fa288f63ident mission 011: report wording (Intl zone names)mre
- 961fae01ident mission 011: report, LOG, STATUSmre
- 65348039ident#7: delivery gate — console check split at the gate's own server restart (49 checks)mre
- dfa7b783ident#7: README (Delivery, env, gate, files, data), deploy.sh runs tests/delivery.mjsmre
- ab6331f4ident#7: tests/delivery.mjs — fake clock gate: Vienna/New York/Tokyo/UTC 17:00, urgent, mail off, restart, DST days, zone changemre