gitoria

calendar

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit27d3e29427d3e294theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre27d3e294/lib/login-limit.hl

1.6 KB

  1. // lib/login-limit.hl — THE LOGIN LIMIT (calendar security mission SC): /login/callback asks ident to exchange the code, so an
  2. // unthrottled client could make this server hammer ident. Per client IP (the X-Client-IP header nginx sets and overwrites, null
  3. // = one shared 'direct' bucket): CALENDAR_LOGIN_LIMIT exchanges per CALENDAR_LOGIN_WINDOW seconds (default 20 per 600).
  4. // Table storage/mpackdb/logins.db { ip, at }; rows older than the window are removed on the way. The face calendarLogin (ident
  5. // selector path) gets no request context in hl:web (hybriel#25), so it cannot be limited per client — see reports/SC-sec.md.
  6. import { MPackDB } from 'hl:mpackdb'
  7. import { now } from 'hl:time'
  8. import { envOr, storageDir, countOfList } from './util.hl'
  9. static loginsTable = new MPackDB(file = storageDir + '/logins.db', primaryKey = '@id', indexes = ['ip'])
  10. static loginLimit = toNumber(envOr('CALENDAR_LOGIN_LIMIT', '20'))
  11. static loginWindowMs = toNumber(envOr('CALENDAR_LOGIN_WINDOW', '600')) * 1000
  12. static bucketOf = (ip) => {
  13. if (ip == null || hlTypeName(ip) != 'String') { return 'direct' }
  14. t = ip.trim().toLowerCase()
  15. if (t == '') { return 'direct' }
  16. return t.length > 64 ? t.slice(0, 64) : t
  17. }
  18. // true = this client has used up its exchanges (nothing is recorded then); false = recorded, go on
  19. static tooManyLogins = (ip) => {
  20. bucket = bucketOf(ip)
  21. t0 = now()
  22. rows = loginsTable.find('ip', bucket)
  23. n = countOfList(rows)
  24. let recent = 0
  25. let i = 0
  26. while (i < n) {
  27. if (rows[i].at > t0 - loginWindowMs) { recent = recent + 1 } else { loginsTable.delete(rows[i].id) }
  28. i = i + 1
  29. }
  30. if (recent >= loginLimit) { return true }
  31. loginsTable.put({ ip = bucket at = t0 })
  32. return false
  33. }

Branches

Latest commits

  • 27d3e294theme: sync from layouts 4994037 (list rows stack, td word-keep, heading code, edited tap target)mre
  • 2ac9c1bbdeploy: security gate (tests/security.mjs)mre
  • 6b0a2571merge sc-sec (calendar security) with 99-year sessionsmre
  • 92001e52sessions last 99 years (creator 2026-10-23: logins never expire; only sign out ends them)mre
  • 0f76c99dSecurity audit SC: push endpoint SSRF guard, uploadMax 0, Secure cookie, login session rotation + rate limit, event cap, nosniff, security gatemre
  • 2dd53dccP1: one reminder shows once: arm() one at a time, the page skips reminders the server already pushed; push-twice gatemre
  • 3a29760aC13 report (handoff)mre
  • 33ab66ffCalendar: notification controls move from the month view into Reminder settings (user menu), one consistent state, state read when the dialog opensmre
  • 682a5b43reports: calendar gate countsmre
  • 876d22b2reports/H1-hydrate.mdmre
  • ef0cae45tests/dst.mjs: wait for hydration instead of a fixed 2.5 s sleep before clicking #gomre
  • d9cadecatests/cdp.mjs: HL_CPU_THROTTLE=<rate> optional CPU throttling for gate runsmre
  • efa61227re-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
  • 7808adbecalendar#12: report 011, LOG, STATUS, push-shots-testmre
  • df2e4fa0calendar#12: test push rate limit (1 per 30 s per device), owner-only gate checksmre
  • acb957cfcalendar#12: Send a test notification on a subscribed device (one push in ~10 s, owner's own device), push gate part 4mre
  • 0b222eb8tests: e2e-theme CDP port default from E2E_THEME_CDP_PORT (8756 unchanged)mre
  • 8b8a5abare-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
  • a69b27f9docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 1a97edfdcalendar mission 010: reminder rows at 390 px (the 7-column month grid no longer catches the reminder lists), gate checks, settings-shots, reportmre