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/W41-REPORT.md

6.0 KB

  1. # W41 report — gitoria#41 repo owners can connect an app (branch w41-apps-connect, worktree W41/wt, base 06d622d)
  2. ## Built
  3. One commit `9af07ec` "gitoria#41: connect an app to a repo …" (not pushed, not deployed, no ticket written).
  4. - `lib/apps.hl`: table `apps.db` keyed by the repo's id (`repo`), rows {repo, name, hookUrl, keyHash (sha256 of gak_+40 hex), secret (64 hex, server only), createdBy, created, lastDelivery, lastStatus}; one row per (repo, name, case-insensitive), re-connect keeps the app id and replaces key + secret; `appOfKey(key)`; `removeApp` (row gone = key dead); `rotateSecret`; `addApp` (manual way B); `makeCode`/`exchangeCode` (table `appcodes.db`, only sha256 of the 48-hex code, deleted on first use, 5 minutes, only on the address of its own repo). Max 20 apps per repo.
  5. - `lib/apps-helpers.hl`: URL allow-list, `GITORIA_APP_HOSTS` config (default empty), key shape, `apiOf(slug)`, form parsing.
  6. - `lib/api.hl` (thin wrappers) + `lib/api-helpers.hl` `apiError` (contract §6 shape) + `project.hl` routes: `GET /settings/apps/connect` (and `/:orepo/…`), `POST /settings/apps/confirm`, `POST /api/apps/exchange`, `/api/:orepo/apps/exchange`, `/:orepo/api/apps/exchange`.
  7. - `components/settings.hl`: "Apps" section (owner: list with name, receiver host, added, last delivery status; Rotate secret; Remove; Add form; key/secret shown once in the page state of that click; the confirm card "Connect X to repo?" with Yes/No). Styles nested, one declaration per line, id rules.
  8. - Hook point: `pingAfterConnect(app, repo)` in `lib/apps.hl`, called after an exchange and after a manual Add; sends nothing (for gitoria#43).
  9. - README: env var `GITORIA_APP_HOSTS`, section "Apps". `tests/apps.mjs` (95 checks) added to GATES in deploy.sh.
  10. ## Connect flow as built
  11. App sends browser → `/settings/apps/connect?app&hook&return&state`: hook/return checked (400 `invalid_url`), name/state checked (422 `invalid`), request parked in the session with a nonce (a session is minted if none) → redirect to the repo's `/settings` → signed out: "Sign in with the selector at the top"; the login callback keeps the same session so the card appears after sign-in; non-owner: "Only the owner…"; owner: Yes/No as a plain HTML form POST with the nonce (no hand-written JS) → `return?code&state` (No: `return?error=denied&state`). The owner check (`ownsRepo`) and the nonce are repeated at the POST; a wrong try does not use up the parked request. Exchange answers the §1 step 3 JSON.
  12. Allow-list: https + host `worldapi.org`/subdomain (no port, no user info, no IP, plain ASCII, ≤500 chars, lower-case `https` only), or url == base or starts with base + "/" from `GITORIA_APP_HOSTS` (plain http included, per Apollo's correction and contract v1.1). Tested: `http://100.77.141.84:8100.evil`, `:81000`, other ports, `worldapi.org.evil.com`, `evilworldapi.org`, `x.worldapi.org\@evil.com`, spaces, ftp, javascript:, empty all refused for both hook and return.
  13. ## Tests (LC_ALL=C, ports 8730–8739, all free before and after)
  14. - `node tests/apps.mjs` 95 passed, 0 failed (new gate; flow, allow-list incl. 38 refusal checks, owner-only, re-connect, add/rotate/remove, org repo `acme/rev` with both exchange spellings, no key/secret/code in any page or the server log).
  15. - `node theme/check-theme.mjs .` 0 problems (58 files).
  16. - `node tests/browser.mjs` 265 passed, 0 failed (rerun with Chrome ports 8733-8738; the first run crashed with "no bindable port in 8735-8738" because I gave it only 4 Chrome ports, not a test failure).
  17. - signin-return 3/0, security 82/0, private 158/0, ident-access-gitoria 30/0 (these four are deploy.sh GATES).
  18. - Logs: W41/gates.log, W41/apps1.log.
  19. ## Contract points
  20. Covered: §0 key/secret/api-base shapes; §1 flow A steps 1–3 and manual B, re-connect replaces, remove, rotate, allowed URLs (v1.1), §6 error shape for the routes I added.
  21. Not covered (by scope): step 4 ping (hook point only), tokens gat_ (#42), events/deliveries (#43), rate limits/413 (#47). `lastDelivery`/`lastStatus` stay empty ("no delivery yet").
  22. Deviations/choices to confirm: (1) an unknown, used, expired or wrong-repo code is `404 not_found` (the contract has no `invalid_code`). (2) The org exchange route: contract says `{repo address}/api/apps/exchange` (= `<org>/<repo>/api/apps/exchange`) but the API base for org is `<org>/api/<repo>`; I serve both. (3) The confirm card lives on `/settings` (not a separate page), because the login `next` keeps only the path. (4) Uppercase `HTTPS://` is refused (strict).
  23. ## DOCS/GAP
  24. - GAP-1: `JSON.parse` of broken JSON ends the request with 500 (located error), no safe parse, no `req.json()`. Repro: `curl -XPOST -d '{broken' http://host/api/apps/exchange` → 500. Only a body not shaped like `{…}` gets the contract's 400 `invalid_json`; `{broken}` still 500. No workaround added.
  25. - GAP-2: a page component cannot read the query string and `route.path` has no query, so `?next=` of the login loses it; solved by parking in the session (fine, but a framework way would be shorter).
  26. - DOCS: a View `if` refuses `x != ''` ("declare it at the root"): needed `hasShownKey`.
  27. ## Open risks / not done
  28. - NOT proven in his Chrome on lisbeth :9223 (WORKER-RULES "proof in his Chrome", multi-resolution screenshots). Only the headless gate (real HTTP, plus browser.mjs for existing pages) ran; no screenshot of the new Apps section was taken or looked at. The Add/Rotate/Remove face handlers are tested through the face endpoint, not by clicks in a browser. A follow-up must click Add/Rotate/Remove and the Yes form at 390 px and 1280 px.
  29. - The expiry of the 5-minute code is coded (`codeLifeMs`) but not tested (no clock control).
  30. - `appOfKey` has no caller yet (#42).
  31. - `secret` is stored plain in `apps.db` (server must sign); the face of Add/Rotate sends it to the owner's page once, by design.
  32. - The worktree's `bin` is a symlink to the main checkout's bin (not committed; `git status` clean).
  33. - Stopped: nothing left running (gates stop their own servers; `ss` shows no 873x listener, no Chrome with a W41 cwd). I started no background processes.
  34. - Requests used: about 40.

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