gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit00efc06f00efc06fP50 reportmre00efc06f/lib/transport-helpers.hl

2.1 KB

  1. // lib/transport-helpers.hl — what lib/transport.hl looks up: the Basic password of a request, the plain-text answers,
  2. // the protocol version a client asks for, git's pkt-line. Statics only.
  3. import { Response } from 'hl:http1'
  4. import { run } from 'hl:proc'
  5. import { NL, isBase64 } from './util.hl'
  6. // the password of a Basic `Authorization` header ('user:password' → 'password'); null without one.
  7. // Hybriel has no base64 decoder (hybriel ticket candidate), so `base64 -d` decodes it — the text goes in as an
  8. // argument, after a check that it only holds base64 characters.
  9. static passwordOf = (header) => {
  10. if (header == null || hlTypeName(header) != 'String') { return null }
  11. h = header.trim()
  12. if (h.length < 7 || h.slice(0, 6).toLowerCase() != 'basic ') { return null }
  13. b = h.slice(6).trim()
  14. if (!isBase64(b, 600)) { return null }
  15. r = run(['sh', '-c', 'printf %s "$1" | base64 -d 2>/dev/null', 'sh', b], { timeout = 10 })
  16. if (r == null || r.exit != 0 || r.lines.length == 0) { return null }
  17. text = r.lines[0]
  18. colon = text.indexOf(':')
  19. return colon < 0 ? null : text.slice(colon + 1)
  20. }
  21. static plain = (status, text, extra) => {
  22. let headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'Cache-Control' = 'no-store' 'X-Content-Type-Options' = 'nosniff' }
  23. if (extra != null) { for (k of extra.keys()) { headers[k] = extra[k] } }
  24. return new Response(text + NL, { status = status headers = headers })
  25. }
  26. // git speaks protocol v2 when the client says so: `Git-Protocol: version=2` (only that shape is passed on)
  27. static protocolEnv = (req) => {
  28. v = req.headers['git-protocol']
  29. if (v == null || hlTypeName(v) != 'String' || v.length > 40) { return {} }
  30. let ok = v.length > 0
  31. let i = 0
  32. while (i < v.length) {
  33. c = v.charCodeAt(i)
  34. if (!((c >= 48 && c <= 57) || (c >= 97 && c <= 122) || c == 61 || c == 58)) { ok = false }
  35. i = i + 1
  36. }
  37. return ok ? { GIT_PROTOCOL = v } : {}
  38. }
  39. // pkt-line: 4 hex digits of the length (itself included), then the text
  40. static pktLine = (text) => {
  41. let n = text.length + 4
  42. hex = '0123456789abcdef'
  43. let out = ''
  44. let i = 0
  45. while (i < 4) {
  46. d = n % 16
  47. out = hex[d] + out
  48. n = (n - d) / 16
  49. i = i + 1
  50. }
  51. return out + text
  52. }

Branches

Latest commits

  • 00efc06fP50 reportmre
  • eefa2dbcRepo setting: refuse direct pushes to the main branch (pre-receive over HTTPS and ssh)mre
  • 25309981log: STOP and paused workers 2026-11-08mre
  • 5286803alog: worker briefs and reports of 2026-11-08mre
  • 85c86605log: 2026-11-08 Arachne on list shapemre
  • cb634512log: 2026-11-08 keyed lists livemre
  • 07c98d4aLists: keyed rows with @id, remove(id) and one whole-list assignment instead of hand-rebuilt loopsmre
  • 0db0d81elog: 2026-11-08 day52 live, W30 startedmre
  • b05f6d92tests/status: the gate's 3 s app token expired during the restart; it lives 60 s like status-keyedmre
  • 1e8f4f0avendor: Hybriel set-day52 (fault-path leak fix #335, keyed rows #331)mre
  • f5f0fb7blog: 2026-11-08 day50/#29 live, H25 correction, V52 startedmre
  • dc77fb95main: offline note from __hlOnline, tick removed (#29)mre
  • 37a86d93tests/reviews: seeded fake hook's DNS failures are not server errors (flaky gate)mre
  • 07ab845bvendor: Hybriel set-day50 (run() leak fix #335)mre
  • 71b2fa4blog: hybriel#335mre
  • bd94cc7elog: #25 cause found (run() leak)mre
  • 565cb508log: H25 round 1mre
  • 90a0af84log: H25 startedmre
  • 87bd53b8mission H25mre
  • 71a746cflog: day48 livemre