API type-roles access bug
A read, update, or delete of an existing row is decided by the roles on that row's own resource (user-allowed-resource in be-rec, be-id, be-update, be-delete). :type-roles exist to answer who may create a row, because a row that does not exist yet has no resource to check. The REST handlers contradict this: GET /api/item, /api/list, /api/id, /api/value, /api/column, and the /api/update and /api/delete handlers call require-auth with get-type-roles before the backend runs, so a user who holds none of the type's roles gets a 401 and the row's roles are never examined. be-list then checks read on the type resource a second time (valid-user-permissions). A public grant on one row of an admin-only type is unreachable.
Fix: drop the get-type-roles argument from those handlers so authentication still runs and the row check decides. Create stays gated on the type resource (be-insert). See docs/roles.md.
Plan: api-type-roles-access-bug-plan-kimi.org.
Implemented per the plan, one deviation. lisp/backend.lisp: be-list's authorization dispatch is category-gated — a let* binds the compiled :phase-a-shape once (measure-p) and reuses it for both authorization and execution dispatch; rollups (:measure), built-ins (built-in-p, base and non-base system types alike), and a future :page projection shape keep valid-user-permissions read on the type resource, while an ordinary author-defined resource-backed type now needs only valid-existing-user — base-be-list's user-read-type-ids filtering decides visibility, so a caller with no readable rows gets a successful empty list. lisp/rest.lisp: the get-type-roles membership preflight is dropped from the ten existing-row handlers — list, item, id, value-id, value, column, update, delete, actions (require-auth no-arg) and file (require-auth-with-query-token no-arg); authentication itself is untouched (missing/invalid token still 401), insert/upload/validate-field/validate-form keep their preflights, and the delete handler's admin usage-metadata prefetch stays. Deviation: rest-value now parses its form parameter (= (if form (parse-form form) :update-form)=, the rest-item shape) before calling be-val — the plan's mandated /api/value acceptance is unsatisfiable without it, since every string form (the "udpate-form" typo default included) died in form-field-keys /=u:tree-get='s etypecase as a 500; the typo default itself is untouched (an omitted form now 400s "Form not found" instead of 500ing — both errors). Tests: fixture models/test/api-type-roles-access-test.lisp (guest-allowed + api-roles + :row-writer :new-roles, admin-only :notes with the :test-sync button, :users redeclared admin-only as the built-in control) and tests/api-type-roles-access-tests.lisp — a transport-stub direct-handler harness modeled on action-log-tests (token extraction/validation, parse-posted-json, abort-request, record-usage stubbed; require-auth, get-type-roles, RBAC, and the backend run real) plus 17 tests / 100 checks: the guest read matrix across every existing-row endpoint (non-UUID identity lookups; private row never disclosed), writer update/delete/action, /api/file 401/403/404/serve, preserved boundaries (insert/upload/validate preflights; :users and :usage type gates now surfacing as the backend's 400; the rollup gate intact under measure-rollup-test; tab visibility; envelope-vs-record capability split), and wire-level JSON (boolean flags, empty readable set as success — those users need a:remove-user-role "public", every fresh user holds it — no private leaks); registered in data-ui.asd, run-api-type-roles-access-tests in tests/helpers.lisp and run-tests. Baseline recorded pre-fix (11 failing: the type gate and the 401 preflights exactly). Docs: docs/roles.md REST section rewritten as the split; docs/rest.md gains an Authorization paragraph, corrected /api/id and /api/value-id sections (the two were swapped; value-id takes type/field/value and returns an ID — no column param) plus /api/value, /api/delete, /api/file authorization notes; docs/model-reference.md Type-roles, Guest-login, API-roles, and list-ordering prose updated. Full suite scripts/data-ui tests: 2946/2946 across 51 groups.
- Slot
- 4800
- Status
- 60 Done
- Tags
- mvp, backend, bug
- Contributors
- Donnie, Kimi
- Plans
- API Type-Roles Access Bug — Implementation Plan