fix: address performance and security findings
- Add PostgreSQL-backed backend and frontend tests to CI - Harden Android API logging and disable app backups - Update the performance report with resolved findings
This commit is contained in:
1 parent
a84a36349b
commit
937f51b4fb
35 files changed
+2566
-332
No files matched your search
+12
-7
@@ -6,7 +6,7 @@
|
||||
- **Commit:** 6aec03f on main
|
||||
- **Working tree:** clean (no uncommitted changes, no untracked files)
|
||||
- **Stack:** Go 1.26 (net/http, pgx v5) API server; PostgreSQL; SvelteKit 2 / Svelte 5 static SPA (Vite 8, TanStack Query) embedded in the Go binary; Android client (Kotlin, Room, Retrofit) with offline sync; Docker multi-stage image on `scratch`; GitHub Actions.
|
||||
- **Updated:** 2026-10-19 — Critical and High findings handled in the working tree (not committed).
|
||||
- **Updated:** 2026-10-19 — Critical, High and Medium findings handled in the working tree (not committed). A second Medium pass re-checked P-004, which stays open for a pagination contract decision.
|
||||
- **Scope:** Read all first-party backend code (`backend/*.go`, including tests), `docker/Dockerfile`, `.dockerignore`, `.github/workflows/*`, the frontend data layer, list components, routes and Vite config, the Android API client, preferences and sync repository, and the shared auth, postgres and authclient code that CollabTable calls. Excluded: `node_modules`, `frontend/.svelte-kit`, the Gradle wrapper, lock files (read for versions only), build output, and the rest of `shared/` (node, python and java packages, which CollabTable does not use). Tracked SQLite files were inspected read-only from a copy (schema and row counts only). No tests, builds or linters were run; the analysis is static.
|
||||
|
||||
## Summary
|
||||
@@ -15,7 +15,7 @@
|
||||
|---|---:|---:|---:|---:|
|
||||
| Critical | 0 | 0 | 0 | 0 |
|
||||
| High | 2 | 1 | 0 | 1 |
|
||||
| Medium | 5 | 0 | 0 | 5 |
|
||||
| Medium | 5 | 4 | 0 | 1 |
|
||||
| Low | 3 | 0 | 0 | 3 |
|
||||
| Info | 1 | 0 | 0 | 1 |
|
||||
|
||||
@@ -37,35 +37,40 @@ Two structural costs dominate: the dashboard re-downloads the full database ever
|
||||
- **Recommendation:** Batch the writes, using `pgx.Batch` or multi-row `INSERT ... SELECT FROM unnest(...)` upserts per table. Load the field-to-list map once per request instead of once per value. Insert notifications as one multi-row statement per request. Cap rows per request, return `413` above the cap, and have clients chunk their pushes.
|
||||
- **Status:** Open 2026-10-19 — partly addressed: `backend/sync.go` now resolves each request's fields and items in two statements (`valueReferences`) instead of up to two lookups per value, which removes the per-value reads. Still needed: the list, field, item and value upserts and their notification inserts still run one statement at a time inside one transaction, so this needs `pgx.Batch` or `unnest` bulk upserts; the per-request row cap with `413` is a client-facing change and needs CollabTableAndroid to chunk pushes first. Not measured against PostgreSQL, since none is available in this environment.
|
||||
|
||||
### P-003 · No index on `updatedat`, so every delta query scans the table · **Medium**
|
||||
### P-003 · No index on `updatedat`, so every delta query scans the table · **Medium** · Fixed
|
||||
- **Location:** `backend/db.go:40-189` (indexes exist only on `fields.listid`, `items.listid`, `item_values.itemid`, `item_values.fieldid`, and notifications `createdat` and `listid`, at `:83-86` and `:97-98`). Queries filtering on `updatedat`: `backend/data.go:75`, `:108`, `:145`, `:178`; sync calls at `backend/sync.go:220-235`.
|
||||
- **Description:** Sync and `/web/data` filter with `updatedat >= $1`, but `lists`, `fields`, `items` and `item_values` have no index on `updatedat`. Rows are soft-deleted and never physically removed, so the tables only grow.
|
||||
- **Impact:** Every sync from every device performs four full table scans, and the cost grows with history rather than with recent change volume.
|
||||
- **Recommendation:** Add `CREATE INDEX IF NOT EXISTS` on `updatedat` for `lists`, `items`, `fields` and `item_values` in `initSchema`. Consider `(isdeleted, updatedat)` if soft-delete filtering is common in the same queries.
|
||||
- **Status:** Fixed 2026-10-19 — `initSchema` creates indexes on `updatedat` for lists, fields, items and item values, so delta queries stop scanning whole tables. The index builds run at startup and briefly block writes on large tables. Files: backend/db.go.
|
||||
|
||||
### P-004 · No pagination on list endpoints or the sync response; the first sync returns everything · **Medium**
|
||||
### P-004 · No pagination on list endpoints or the sync response; the first sync returns everything · **Medium** · Open
|
||||
- **Location:** `backend/data.go:68-204` (`queryLists`, `queryFields`, `queryItems`, `queryValues`, none with LIMIT), `backend/data.go:228-235` (`GET /api/lists`), `backend/sync.go:216-248` (`since` is nil when `lastSync == 0`, so the full table is returned).
|
||||
- **Description:** Collection endpoints return unbounded arrays. The first sync from any device (`lastSync == 0`) returns every list, field, item and value in the database in one response.
|
||||
- **Impact:** Response size and server memory grow linearly with total data. Large first syncs risk the 60-second write timeout and slow mobile clients.
|
||||
- **Recommendation:** Add keyset pagination (a `(updatedat, id)` cursor and a `limit` parameter) to the collection endpoints. For sync, return a `hasMore` flag and a cursor, and let the client loop until it is caught up.
|
||||
- **Status:** Open 2026-10-19 — Re-checked, unchanged: the collection queries have no LIMIT and `lastSync == 0` still returns every row. Decision needed: the pagination contract (`hasMore` plus a cursor, or keyset on `(updatedat, id)`), the default page size, and the rollout order. CollabTableAndroid has to loop until caught up before the server may page, or existing clients would silently get a truncated sync.
|
||||
|
||||
### P-005 · Frontend scans full arrays for every row, card and cell on each poll · **Medium**
|
||||
### P-005 · Frontend scans full arrays for every row, card and cell on each poll · **Medium** · Fixed
|
||||
- **Location:** `frontend/src/routes/lists/[id]/+page.svelte:94` (`itemValuesFor(overview.values, item.id)` runs once per visible row and scans every value in the database) and `:98` (`valueFor` per cell); `frontend/src/lib/components/lists/ListCard.svelte:7-8` (each card filters all fields and all items); `frontend/src/lib/features/lists/listHelpers.js:1-15` (linear `filter` and `find` with no index).
|
||||
- **Description:** The helpers are linear scans over the complete data set, and they run for every visible row and card. Because each 5-second poll replaces the arrays, every derived value is recomputed on every poll.
|
||||
- **Impact:** Cost per render is roughly visible rows times total values. With a large data set this appears as delayed input and scroll jank.
|
||||
- **Recommendation:** Build lookup maps once per data change in a `$derived` (a `Map` keyed by `listId`, by `itemId`, and by `itemId + fieldId`). Pass pre-grouped slices into the card and row components. Rely on TanStack's structural sharing so unchanged data keeps its references.
|
||||
- **Status:** Fixed 2026-10-19 — Fields, items and item values are grouped once per data change with `groupByKey`, and each grid card, table row and detail row reads only its own slice. `itemValuesFor` is removed because it had no other callers. Files: frontend/src/lib/features/lists/listHelpers.js, frontend/src/routes/+page.svelte, frontend/src/routes/lists/[id]/+page.svelte, frontend/src/lib/components/lists/ListsGrid.svelte, frontend/src/lib/components/lists/ListsTable.svelte.
|
||||
|
||||
### P-006 · No HTTP compression and no cache headers on JSON or static assets · **Medium**
|
||||
### P-006 · No HTTP compression and no cache headers on JSON or static assets · **Medium** · Fixed
|
||||
- **Location:** `backend/server.go:118-125` (plain `http.Server`, no compression middleware), `backend/server.go:292-316` (`spaFileServer` sets no `Cache-Control`), `backend/web.go:74-76` (`no-store` on `/web/data`).
|
||||
- **Description:** JSON responses (`/web/data`, `/api/sync`, `/api/lists`) are sent uncompressed. Static build output, including content-hashed Vite assets, is served with no cache-control, and the embedded filesystem provides no modification times for conditional requests.
|
||||
- **Impact:** Large JSON bodies transfer several times more bytes than necessary, and browsers refetch the whole app bundle on each visit.
|
||||
- **Recommendation:** Add gzip or brotli middleware, or enable it at the reverse proxy. Set `Cache-Control: public, max-age=31536000, immutable` for `_app/immutable/*` and `no-cache` for `index.html`. Add ETags for `/web/data` (see P-001).
|
||||
- **Status:** Fixed 2026-10-19 — Responses are gzip-compressed for clients that accept it, `_app/immutable/` assets are cached for a year as immutable, and `index.html` and other static files are sent with `no-cache`. Files: backend/server.go, backend/server_test.go.
|
||||
|
||||
### P-007 · Request bodies up to 50 MB are decoded into memory with no per-route limit · **Medium**
|
||||
### P-007 · Request bodies up to 50 MB are decoded into memory with no per-route limit · **Medium** · Fixed
|
||||
- **Location:** `backend/server.go:253-259` (`decodeJSON` uses `io.LimitReader(r.Body, 50*1024*1024)`), used by `backend/sync.go:46` and by the write handlers in `backend/data.go`.
|
||||
- **Description:** Every write endpoint accepts up to 50 MB of JSON and decodes it fully into Go structs. `io.LimitReader` truncates silently, so an oversized body fails with a confusing decode error instead of `413`. These handlers have no concurrency cap, so each concurrent request can allocate its full decode buffer.
|
||||
- **Impact:** A few concurrent large requests can exhaust memory. It is also an easy denial-of-service vector (see the rate-limiting note in the Security report).
|
||||
- **Recommendation:** Use `http.MaxBytesReader` with per-route limits (for example 1 to 5 MB for single-entity writes, and a higher bound for sync), returning `413` when exceeded. Bound concurrent sync transactions with a semaphore sized below `DATABASE_MAX_CONNS`.
|
||||
- **Status:** Fixed 2026-10-19 — Request bodies are limited with `http.MaxBytesReader` (2 MB for single-entity writes, 50 MB for sync), oversized bodies get 413, and at most four syncs run at once. Single-entity writes above 2 MB now fail with 413; the shared auth proxy already caps bodies at 128 KB. Files: backend/server.go, backend/sync.go, backend/data.go.
|
||||
|
||||
### P-008 · One notification row per changed row, on every write path · **Low**
|
||||
- **Location:** `backend/sync.go:79`, `:126`, `:164`, `:206`; `backend/data.go:256`, `:302`, `:364`, `:418`, `:507`, `:561`, `:605`, `:621`; retention in `backend/db.go:212-230`; polling in `backend/web.go:92-141` (`LIMIT 500` at `:109`).
|
||||
|
||||
Reference in new issue
Block a user