gitoria
All repositories: gitoria
5.4 KB
# W42 report — gitoria#42: an app's short-lived token, git read over HTTPSBranch `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.`docs/apps-api.md` is untracked in main, so I copied it into the worktree to read it and did NOT commit it.## Built- `lib/app-tokens.hl` (new): table `apptokens.db` { hash (sha256 only), app, repo, created, expires }. `issueToken`, `rowOfToken`, `dropTokensOfApp`, `sweepExpired`.Token = `gat_` + 40 hex, life 1 h. Expired rows are swept on every issue (no timer) and deleted when found expired at use.`GITORIA_APP_TOKEN_LIFE_MS` shortens the life, for the gate only.- `lib/app-auth.hl` (new): `appOfRequest(route, req)` → `{ app, repo }` or `{ error }` (a ready §6 Response).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`.- `lib/apps.hl`: `removeApp` and a re-connect (a new key) call `dropTokensOfApp`, so the tokens die at once.- `lib/api.hl`: `appToken` route, `POST {api}/apps/token` with `Bearer gak_…` → `200 {"token","expires"}`.`expires` is UTC ISO with milliseconds (`timestamp()`), e.g. `2026-11-02T07:00:00.000Z`; the contract's example has no ms.GET → 405 `invalid`. No, unknown or wrongly shaped key → 401. A key used on another repo's address → 404.- `lib/transport.hl`: a `gat_` password = READ of its own repo, including a private one, on the repo address and the org address.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.- apiError already gave exactly the §6 shape, so it is reused unchanged.## API base, both spellings (point 4)`apiPatterns(path)` in `lib/api-helpers.hl` returns `['/api'+path, '/api/:orepo'+path, '/:orepo/api'+path]`. project.hl lists a route once:`for (p of apiPatterns('/apps/token')) { { pattern = p function = appToken } }`. The exchange route now uses the same helper.#43/#44 add routes the same way, with `:n` and the like inside `path`. Inside the handler, `repoOfRequest(route, req)` reads `route.params.orepo`.## Tests- `tests/app-token.mjs` (added to GATES in deploy.sh), 42 checks, 0 failed. It covers:- issue and token shape;- a 3 s life, with the first token still working beside a newer one, then dead after the life;- the key as password and the missing / unknown key cases;- wrong repo 404 and no-repo 404;- the org address in both spellings;- git ls-remote, clone and v2 shallow fetch with the token on a private repo, with any user name;- push refused 403;- the token on another private repo → 404 and on a public repo → anonymous read;- re-connect and remove kill the old tokens;- 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;- a restart.- `tests/app-auth-unit.hl` (run by the gate): calls `appOfRequest` directly, because no API route uses it yet.- 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.- 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).## Contract points- 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.- Not covered: the API routes that use `appOfRequest` (#44). `appOfRequest` is tested only directly. §6 429 and 413 are #47.## Bugs found on the way (mine, fixed)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.## DOCS / GAPDOCS 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.## Open risks- `expires` carries milliseconds; a strict client parsing `…:00Z` literally would need an ISO parser. Easy to cut if Kunibert wants it.- Sweep cost is one pass over the token table per issue; fine for ≤20 apps per repo at one token per hour.- 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.- 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.- Requests used: ~35.## Stopped / leftTwo 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
- f1-broken-json
- f2-api-bugs
- gp-gate-ports
- heap-revert
- hl25-records
- ident-chooser-selector
- mainmain branch
- p51-public-pr-reads
- records-1112
- s25-no-session-on-login-error
- v59
- w52-person-approval
- w52b-approval-followup
- w52c-header-phone
- w53-pulls-speed-pr
- w54-repo-rename-pr
- w55-rename-org
- w56-owner-members
- w62-pr-close
- w63-force-push
- w64-org-slash
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