gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit2f2725ac2f2725actests/browser.mjs: commit-row check (one row, centred date)MG2f2725ac/lib/api-helpers.hl

3.9 KB

  1. // lib/api-helpers.hl — the plumbing of the function routes (lib/api.hl): JSON / Markdown / plain answers, redirects,
  2. // the guard of the internal ssh routes, the repo of a request's host, where a login may return to. Statics only.
  3. import { Response } from 'hl:http1'
  4. import { NL, scheme, hostPort, slugOfHost } from './util.hl'
  5. import { slugError } from './repos-helpers.hl'
  6. import { repoBySlug } from './repos.hl'
  7. import { sshSecret, sshEnabled } from './sshkeys.hl'
  8. static jsonHeaders = { 'Content-Type' = 'application/json; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' }
  9. static reply = (status, value) => {
  10. return new Response(JSON.stringify(value), { status = status headers = jsonHeaders })
  11. }
  12. static fail = (status, message) => { return reply(status, { error = message }) }
  13. // THE MARKDOWN READ VIEW: `Accept: text/markdown` (for LLM readers)
  14. static wantsMarkdown = (req) => {
  15. a = req.headers['accept']
  16. return a != null && hlTypeName(a) == 'String' && a.includes('text/markdown')
  17. }
  18. static markdownReply = (text) => {
  19. return new Response(text, { status = 200 headers = { 'Content-Type' = 'text/markdown; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } })
  20. }
  21. // a plain-text answer of the internal ssh routes
  22. static textReply = (status, text) => {
  23. return new Response(text, { status = status headers = { 'Content-Type' = 'text/plain; charset=utf-8' 'Cache-Control' = 'no-store' 'X-Content-Type-Options' = 'nosniff' } })
  24. }
  25. static goTo = (where) => {
  26. return new Response('redirect', { status = 302 headers = { 'Location' = where 'Cache-Control' = 'no-store' 'Content-Type' = 'text/plain; charset=utf-8' 'X-Content-Type-Options' = 'nosniff' } })
  27. }
  28. // THE INTERNAL SSH ROUTES' GUARD (docker/sshd asks them): null when the caller may ask, else the refusing answer. Without
  29. // GITORIA_SSH_SECRET they do not exist (404); every call needs `X-Gitoria-Secret` = that secret, and a request that came
  30. // through the public proxy (it carries X-Forwarded-For / X-Real-IP) is refused.
  31. static sshGuard = (req) => {
  32. if (!sshEnabled) { return textReply(404, 'not found' + NL) }
  33. if (req.method != 'GET') { return textReply(405, 'GET only' + NL) }
  34. if (req.headers['x-forwarded-for'] != null || req.headers['x-real-ip'] != null) { return textReply(403, 'internal only' + NL) }
  35. given = req.headers['x-gitoria-secret']
  36. if (given == null || hlTypeName(given) != 'String' || given != sshSecret) { return textReply(403, 'wrong secret' + NL) }
  37. return null
  38. }
  39. // the repo of a request's host (a repo address), or null
  40. static repoOfRequest = (req) => {
  41. h = req.headers['host']
  42. slug = slugOfHost(h == null ? '' : h.split(':')[0])
  43. return slug == '' || slugError(slug) != null ? null : repoBySlug(slug)
  44. }
  45. // BACK TO THE PAGE after a login: /login.js puts `?next=` into the button's return URL at the click. Only a same-origin PATH
  46. // goes (one `/`, URL-safe characters, ≤ 500) — or a full URL of THIS system: <scheme>://<label>.<host>
  47. // with a valid, non-reserved repo label and such a path. Anything else → `/`.
  48. static nextChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~/?&=%+,;@!$()*:'
  49. static nextPath = (want) => {
  50. if (want == null || hlTypeName(want) != 'String' || want == '' || want.length > 500) { return '/' }
  51. if (want.slice(0, 1) != '/' || want.slice(0, 2) == '//' || want.slice(0, 7) == '/login/') { return '/' }
  52. let i = 0
  53. while (i < want.length) {
  54. if (!nextChars.includes(want[i])) { return '/' }
  55. i = i + 1
  56. }
  57. return want
  58. }
  59. static safeNext = (want) => {
  60. if (want == null || hlTypeName(want) != 'String' || want.length > 500) { return '/' }
  61. prefix = scheme + '://'
  62. if (!want.startsWith(prefix)) { return nextPath(want) }
  63. rest = want.slice(prefix.length)
  64. slash = rest.indexOf('/')
  65. hp = slash < 0 ? rest : rest.slice(0, slash)
  66. path = slash < 0 ? '/' : rest.slice(slash)
  67. dot = hp.indexOf('.')
  68. if (dot < 1 || hp.slice(dot + 1) != hostPort || slugError(hp.slice(0, dot)) != null) { return '/' }
  69. p = nextPath(path)
  70. if (p == '/' && path != '/') { return '/' }
  71. return prefix + hp + p
  72. }

Branches

Latest commits

  • 2f2725actests/browser.mjs: commit-row check (one row, centred date)MG
  • 4df1ea01tests/browser.mjs: MG phone checks (list first, no dead strip, one branch heading, tab grid, commit rows, PR title row, ticket columns, wrapping commands)MG
  • c52424e9gitoria mobile: repo list before the forms, 3x2 tab grid, no duplicate branch heading, ordered commit rows, aligned ticket rows, pull title on its own row, wrapping clone commands, no dead strip under formsMG
  • 3a95252dG3: cache parsed README blocks by sha256 of the text (bounded LRU), reportmre
  • 570138cddeploy: security gate (tests/security.mjs)mre
  • da6b20fcgitoria SG: security audit fixes (uploadMax 0, Secure cookie on https, session rotation at login, nosniff on function routes, no identity in page data) + tests/security.mjs gate + reportmre
  • f98c981fgitoria B1: report wordingmre
  • c6364cedgitoria B1: compact Markdown blocks (one kind flag per block/span, empty and false fields omitted); same rendered HTML, page values -67%mre
  • cd99d2feWIP gitoria#22: always render the repo level's slot (missing-repo boot hang), pages render nothing without a repo; hydration diagnosis in reports/G2-hydrate.mdmre
  • e5404b9breport: commit idsmre
  • 63cfa21ereports/G2-repotabs.mdmre
  • 9b0516fdgitoria#22: mark the tab underline functional (check-theme), chain E2E: serve/measure split, bring the lisbeth tab to frontmre
  • 19bc1df8gitoria#22: all repo pages under ONE layout level (components/repo.hl, hl:web D-CHAIN): a tab click replaces only the page in the slot; head and tab nav stay the same DOM nodesmre
  • 40658417tests/browser.mjs: wait for the page to be live (hydrated) before clicking Merge — a click on the server-rendered button before the client mounted was lost (flaky 'Clashing change' under load)mre
  • 48a6154bre-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
  • e972e8d7tests: short-id-switch (GITORIA_SWITCH_IDENT_PORT/_PORT) and ssh tunnel (GITORIA_GATE_TUNNEL_PORT) ports from env, defaults unchangedmre
  • f06f5349re-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
  • c7d3cc87docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • f0e7ff8cdeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • fe5f707cgitoria 010: report, mission, comment on why current = true staysmre