gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit7b8a4f747b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk7b8a4f74/lib/security.hl

1.9 KB

  1. // lib/security.hl — THE SMALL DEFENCES the routes and faces share (mission SK, the security audit): a request budget (rate limit),
  2. // the caller's address as the proxy gives it, the headers every non-page answer carries.
  3. // hl:web answers the PAGES with no header hook (CSP / nosniff / frame-ancestors / referrer-policy there are hl:web's to add,
  4. // reports/SK-sec.md); the function routes and the files this app answers itself carry the headers below (imageHeaders; the text answers carry nosniff).
  5. import { now } from 'hl:time'
  6. // request budgets: `allowHit('login', ip, 20, 60000)` = at most 20 hits per key per window; true = go ahead. In memory, one
  7. // process per storage. The map is dropped when it holds too many keys (an address flood must not grow it forever).
  8. static budget = { counts = {} keys = 0 }
  9. static allowHit = (&cls, &key, &max, &windowMs) => {
  10. t = now()
  11. slot = cls + '|' + ((t - t % windowMs) / windowMs) + '|' + key
  12. if (budget.keys > 20000) {
  13. budget.counts = {}
  14. budget.keys = 0
  15. }
  16. let c = budget.counts[slot]
  17. if (c == null) {
  18. c = 0
  19. budget.keys = budget.keys + 1
  20. }
  21. if (c >= max) { return false }
  22. budget.counts[slot] = c + 1
  23. return true
  24. }
  25. // the caller's address behind nginx (X-Client-IP, hybriel#25); 'direct' when there is none. Cut to 64 characters.
  26. static clientKey = (&req) => {
  27. h = req != null ? req.headers : null
  28. if (h == null) { return 'direct' }
  29. let v = h['x-client-ip']
  30. if (v == null) { v = h['X-Client-IP'] }
  31. if (v == null || hlTypeName(v) != 'String' || v == '') { return 'direct' }
  32. return v.slice(0, 64)
  33. }
  34. // an image file's headers: its type, its caching, nosniff, and a policy that lets a browser show it and nothing else — a stored .svg
  35. // opened as a page can run no script, load nothing and is sandboxed
  36. static imageHeaders = (&contentType, &cache) => {
  37. return { 'Content-Type' = contentType 'Cache-Control' = cache 'X-Content-Type-Options' = 'nosniff' 'Content-Security-Policy' = "default-src 'none'; style-src 'unsafe-inline'; img-src data:; sandbox" }
  38. }

Branches

Latest commits

  • 7b8a4f74security audit SK: nosniff + image sandbox headers, face id checks, adult follow, login budget + new session at login, guest-link budget, tests/security.mjssk
  • f0f26c5areports: T18 section (gates, boot-gate, 3x3 table, search + short-id compare)mre
  • 2a8682a1deploy.sh GATES: tests/warmstart.mjsmre
  • 3761338breports/T17-boot.md: handoff (phase table, fix, numbers so far, open proof)mre
  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-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
  • c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
  • d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
  • 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
  • 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
  • 4625aa22re-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
  • a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
  • 33ad4bd5Merge commit 'f57f64f'mre
  • 7d38cec4docker-compose: nofile 65536 (default soft 1024 refused boot: errno 24 in fs.listDir, Hybriel 528bc89f)mre
  • f57f64f0mission 046: report, LOGmre
  • 5965963adeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • efe1b485mission 046: re-vendor Hybriel master 60b2817b (integration 8, #203): plugins mpackdb + web (bin/ git-ignored: hybriel, libhlrt.a, hlc.o, hlrt/ from native/zig-out)mre