gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Branchf2-api-bugs26117255|||PR apps API: review comments on files with spaces in their namemref2-api-bugs/reports/W42-REPORT.md

5.4 KB

  1. # W42 report — gitoria#42: an app's short-lived token, git read over HTTPS
  2. Branch `w42-app-token` (worktree `/media/STORAGE/claude-scratch/gitoria/W42/wt`), one commit `b5d696f` on top of main fdb9ed2. Not pushed, not deployed, no tickets touched.
  3. `docs/apps-api.md` is untracked in main, so I copied it into the worktree to read it and did NOT commit it.
  4. ## Built
  5. - `lib/app-tokens.hl` (new): table `apptokens.db` { hash (sha256 only), app, repo, created, expires }. `issueToken`, `rowOfToken`, `dropTokensOfApp`, `sweepExpired`.
  6. Token = `gat_` + 40 hex, life 1 h. Expired rows are swept on every issue (no timer) and deleted when found expired at use.
  7. `GITORIA_APP_TOKEN_LIFE_MS` shortens the life, for the gate only.
  8. - `lib/app-auth.hl` (new): `appOfRequest(route, req)` → `{ app, repo }` or `{ error }` (a ready §6 Response).
  9. 401 `unauthorized` for a missing, unknown or expired token, or an app that was removed. 404 `not_found` when the token's repo is not the repo the address names. Also `bearerOf`, `unauthorized()`, `notFound()`, `appOfToken`.
  10. - `lib/apps.hl`: `removeApp` and a re-connect (a new key) call `dropTokensOfApp`, so the tokens die at once.
  11. - `lib/api.hl`: `appToken` route, `POST {api}/apps/token` with `Bearer gak_…` → `200 {"token","expires"}`.
  12. `expires` is UTC ISO with milliseconds (`timestamp()`), e.g. `2026-11-02T07:00:00.000Z`; the contract's example has no ms.
  13. GET → 405 `invalid`. No, unknown or wrongly shaped key → 401. A key used on another repo's address → 404.
  14. - `lib/transport.hl`: a `gat_` password = READ of its own repo, including a private one, on the repo address and the org address.
  15. Push (`info/refs?service=git-receive-pack` and the POST) → 403. Another repo: no access, i.e. a private repo gives 404 "no such repository", a public repo is plain anonymous read as before. An expired or removed token also counts as no credential.
  16. - apiError already gave exactly the §6 shape, so it is reused unchanged.
  17. ## API base, both spellings (point 4)
  18. `apiPatterns(path)` in `lib/api-helpers.hl` returns `['/api'+path, '/api/:orepo'+path, '/:orepo/api'+path]`. project.hl lists a route once:
  19. `for (p of apiPatterns('/apps/token')) { { pattern = p function = appToken } }`. The exchange route now uses the same helper.
  20. #43/#44 add routes the same way, with `:n` and the like inside `path`. Inside the handler, `repoOfRequest(route, req)` reads `route.params.orepo`.
  21. ## Tests
  22. - `tests/app-token.mjs` (added to GATES in deploy.sh), 42 checks, 0 failed. It covers:
  23. - issue and token shape;
  24. - a 3 s life, with the first token still working beside a newer one, then dead after the life;
  25. - the key as password and the missing / unknown key cases;
  26. - wrong repo 404 and no-repo 404;
  27. - the org address in both spellings;
  28. - git ls-remote, clone and v2 shallow fetch with the token on a private repo, with any user name;
  29. - push refused 403;
  30. - the token on another private repo → 404 and on a public repo → anonymous read;
  31. - re-connect and remove kill the old tokens;
  32. - the key and every token never appear in the server log, even when the key is used as a git URL password or a query value;
  33. - a restart.
  34. - `tests/app-auth-unit.hl` (run by the gate): calls `appOfRequest` directly, because no API route uses it yet.
  35. - Full gates, `LC_ALL=C`, ports inside 8730–8739: signin-return 3/0, check-theme 61 files 0 problems, browser 265/0, security 82/0, private 158/0, ident-access-gitoria 30/0, apps 95/0, app-token 42/0. 0 failed, no flake.
  36. - Not run: his Chrome on lisbeth, since there is no UI change. The old-code failure of the new checks is trivially true (no route, no table).
  37. ## Contract points
  38. - Covered: §0 key and token, §2 token route, Bearer and Basic with `gat_`, read-only, own repo only, §3 fetch with the token (clone, ls-remote, shallow v2 fetch; `refs/pull/*` is served by the same upload-pack once they exist), §6 401 and 404 codes.
  39. - Not covered: the API routes that use `appOfRequest` (#44). `appOfRequest` is tested only directly. §6 429 and 413 are #47.
  40. ## Bugs found on the way (mine, fixed)
  41. A hybrid literal `{ app = a.id repo = a.repo }` rebinds `app` inside the literal, so a parameter named `app` read as a String. I renamed the parameter. This may be worth a DOCS note: inside a hybrid literal a named entry shadows a same-named outer variable for the later entries.
  42. ## DOCS / GAP
  43. DOCS used: HL-PRIMER, CODE-ORDER, hl:time README (`timestamp`). No framework gap hit. No UI, so the COMPONENTS sections were not needed. Open question for docs: the route list in project.hl takes `for (p of …) { { … } }` splices. It works (gate proves it), but I found it only by trying; it is not shown in the docs I read.
  44. ## Open risks
  45. - `expires` carries milliseconds; a strict client parsing `…:00Z` literally would need an ISO parser. Easy to cut if Kunibert wants it.
  46. - Sweep cost is one pass over the token table per issue; fine for ≤20 apps per repo at one token per hour.
  47. - A token for a private repo is not tied to the app's later settings (e.g. the repo turning private→public); it simply reads the same repo.
  48. - With the same app and key, an exchange (reconnect) invalidates its tokens at once; an app that holds a token across a reconnect gets 401 and must fetch a new one, which is the contract's "get a new token" path.
  49. - Requests used: ~35.
  50. ## Stopped / left
  51. Two server processes of my own aborted gate run (pids 3511390 and 3511171) were killed. At the end nothing of mine runs or listens (`ss` on 873x is empty, no Chrome in my scratch). Test stores are under `wt/.scratch/` (git-ignored).

Branches

Latest commits

  • 26117255|||PR apps API: review comments on files with spaces in their namemre
  • b8796cecMerge branch 'f1-broken-json' into mainGitoria
  • 2f2959c5|||PR apps API: broken JSON body gives 400 invalid_json, not 500mre
  • f7c6ca07Merge branch 'ident-chooser-selector' into mainGitoria
  • 691abb8e|||PR tests: find ident identity choice without the removed .choose classmre
  • 16a3530fMerge branch 'heap-revert' into mainGitoria
  • 220a80e0|||PR Remove temporary /__heap route and heap helper; logmre
  • 13f0c342Merge branch 'hl25-records' into mainGitoria
  • a002ecb7|||PR records: HL25 report, heap helper, logmre
  • 2492a55cTemporary keyed /__heap route for the live memory snapshotmre
  • fefaedd2log: tracker PR-only, HL25 startedmre
  • 21aa57calog: parkmre
  • e9f950a8reports: G25c soakmre
  • a7783686log: deploy 9f41ffcmre
  • 9f41ffc1log: W30b mergedmre
  • bef635c1Merge branch 'w30b'mre
  • 15b996a5Org list: keyed rows by @id, newest first, concat instead of hand loopmre
  • c4f6d9e3reports: G25c growth huntmre
  • b88e39f1log: privacy cleanup donemre
  • bfd7826ddocs: neutral example organisation namemre