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
Latest commits
- fe209ffeMerge branch 'w56-owner-members' into mainGitoria
- fa0754c8|||PR repository owner transfer and members API (#55)mre
- 8862e537Merge branch 'w55-rename-org' into mainGitoria
- 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
- 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
- 499f25f2Review fixes for the Settings organization move (#53)mre
- ed3b922b|||PR move a repository into an organization in Settings (#53)mre
- 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
- 9f7ce8d8Preserve rename compatibility and live page titlesmre
- c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
- ce08920dMerge branch 'w52c-header-phone' into mainGitoria
- 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
- e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
- c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
- 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
- 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
- 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
- 155861f6Merge branch 'w52-person-approval' into mainGitoria
- b5435de8|||PR person approvals: second Kunibert round (#52)mre
- 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre