Fixed findings from the audit reports (SECURITY, QUALITY, PERFORMANCE): - P-001 · Unbounded per-session timing maps and no connection cap in the sync hub - S-001 · Anonymous `PUT /access` switches off login for every guarded route - S-002 · Malformed cookies crash the Node middleware and fail requests in Java - S-004 · Anonymous `PUT /sync` writes unvalidated JSON into shared session state Also includes the pre-existing uncommitted changes in web-ui, README, shared-styles and the .changeset files, as the owner asked. Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
15 KiB
15 KiB
Performance Report — shared
- Project: shared
- Path: /workspace/Personal/Web/shared
- Analyzed: 2026-10-16
- Commit:
5216031on main - Working tree: 9 uncommitted change(s):
.changeset/user-management-roles.mdandpackages/web-ui/src/lib/components/UserManagement.sveltedeleted;.changeset/remove-user-management.mduntracked;README.md,MediaPlayerControls.svelte,packages/web-ui/src/lib/index.ts,packages/web-ui/src/lib/styles.css,packages/web-ui/src/lib/types.ts,shared-styles.cssmodified. Findings reflect the working tree. - Stack: Go 1.25 (
backend/, modulerepos.gfranz.ch/Gabriel20xx/shared/backend, pgx, chi, coder/websocket, goose); Node.js ESM withpg(packages/node-backend); Python 3.10+ with asyncpg, bcrypt and optional FastAPI (packages/python-backend); Java 8 target with Jackson (packages/java-backend); Svelte 5 and TypeScript (packages/web-ui); PostgreSQL; PowerShell and Node scripts; Gitea and GitHub Actions. No Dockerfile, compose file or.dockerignoreexists in the repo. - Scope: This is a shared library consumed by other projects (vendored snapshot), not an application. Read: all first-party Go packages except
backend/auth/*andbackend/config(reviewed in a separate pass), the Node, Python and Java AuthGuard clients and stores, the web-ui components that perform I/O or timers, root manifests,.githuband.giteaworkflows, andscripts/. Excluded:node_modules,packages/web-ui/distand.svelte-kit(gitignored, not tracked),package-lock.jsonandgo.sum(versions only), and test bodies (used only for coverage notes). Paths below are relative to the repo root. Backend findings come from read-only static review passes; the highest-severity citations were re-checked in the code. Nothing was built, run or profiled. - Updated: 2026-10-19 — Critical and High findings handled in the working tree (not committed).
Summary
| Severity | Count | Fixed | Not reproduced | Open |
|---|---|---|---|---|
| Critical | 0 | 0 | 0 | 0 |
| High | 1 | 1 | 0 | 0 |
| Medium | 4 | 0 | 0 | 4 |
| Low | 4 | 0 | 0 | 4 |
| Info | 1 | 0 | 0 | 1 |
The auth code has no obvious SQL N+1 outside the playlist reorder path, and most outbound calls have timeouts. The main performance risks are unbounded in-memory state in the sync websocket hub, a per-request AuthGuard round trip with no caching, blocking CPU work (password hashing) on event loops, and a media lookup that defeats its index.
Issues
P-001 · Unbounded per-session timing maps and no connection cap in the sync hub · High · Fixed
- Location:
backend/syncsocket/syncsocket.go:443(sync:update handler),backend/syncsocket/syncsocket.go:446-455(writes toplayAt,playAtLocalMs,capturedAtMskeyed by session ID),backend/syncsocket/syncsocket.go:457-463(eviction covers onlystates),backend/syncsocket/syncsocket.go:293(ServeWebSocketaccepts unlimited connections) - Description: The three timing maps are written per session ID and are cleared only in narrow branches. The 1000-session cap on
statesdoes not touch them, so the maps grow for every new session ID ever seen.ServeWebSockethas no peer or connection limit, and each connection holds a goroutine and buffers. - Impact: Memory grows without bound in a long-running process, and one client sending
sync:updatewith fresh session IDs can drive that growth. Exposure depends on whether consumers gate/wswith authentication (see Security S-003; needs verification in consumers). - Recommendation: Remove timing entries when a session is evicted or loses its last peer. Apply the same cap to all per-session maps. Add a maximum connection count and per-IP and per-peer message-rate limits.
- Status: Fixed 2026-10-19 — the
playAt,playAtLocalMsandcapturedAtMsmaps are trimmed tomaxSyncSessions(1000) after eachsync:updatewrite, andServeWebSocketrefuses connections pastmaxSyncConnections(1000) by closing with 1013 Try Again Later. Over the cap, entries are dropped arbitrarily, asstatesalready is, instead of being removed on last-peer exit; per-IP and per-peer message-rate limits are not added. Behaviour change: an 1001st concurrent websocket is closed at once. Files:backend/syncsocket/syncsocket.go,backend/syncsocket/syncsocket_test.go.
P-002 · Sync fan-out runs on the HTTP request path and writes to peers one at a time · Medium
- Location:
backend/syncsocket/syncsocket.go:234(Broadcast),backend/syncsocket/syncsocket.go:247-261(serial per-peer writes, 2 s timeout each; JSON marshalled once per peer),backend/mediacore/mediacore.go:150(PUT /synccallsBroadcastinline),backend/syncsocket/syncsocket.go:486(eachsync:updatefans out to the whole session) - Description:
Broadcastmarshals the payload once per peer and writes to peers sequentially, each with up to a 2 s deadline. The HTTP handler forPUT /synccalls it on the request goroutine, so one slow peer can hold the HTTP response for up to 2 s per peer. Peers may sendsync:updateat any rate, and each message is fanned out to the entire session. - Impact: Slow or hostile peers add latency to unrelated HTTP responses, and one client can multiply its traffic across every peer in its session.
- Recommendation: Marshal once per broadcast, send through per-peer buffered queues written concurrently, and drop peers whose queue is full. Move HTTP-triggered broadcasts off the request goroutine. Add per-peer message-rate limits.
P-003 · Media lookup defeats the media_key index, and playlist reorder issues one UPDATE per id · Medium
- Location:
backend/mediacore/mediacore.go:735(findMedia:WHERE media_key=$1 OR CAST(id AS TEXT)=$1),backend/mediacore/mediacore.go:210(thumbnail join with the same OR pattern),backend/mediacore/mediacore.go:711-713(reorder loop, one UPDATE per id, errors discarded, no transaction) - Description: An OR with a cast on
idmakes the planner unlikely to use themedia_keyindex alone. Stream and thumbnail requests call this path on every request (mediacore.go:181,194-224). The reorder handler issues one statement per submitted id without a transaction and ignores errors; the 512 KB body cap allows tens of thousands of ids. - Impact: Each media request can cost a sequential scan on a large
mediatable, and a single reorder call can issue tens of thousands of statements and report success after a partial failure. Plan impact was not measured (no database access). - Recommendation: Look up by
media_keyonly, and try the numeric id only when the input is all digits. Replace the loop with oneUPDATE ... FROM unnest(...)inside a transaction, check errors, and cap the id count. Confirm withEXPLAINon a populated table.
P-004 · Password hashing blocks the event loop · Medium
- Location:
packages/node-backend/src/auth.js:61and:69(crypto.pbkdf2SyncinhashPasswordandverifyPassword),packages/python-backend/src/shared_backend/auth.py:126and:131(bcrypt.hashpwandbcrypt.checkpwcalled synchronously inside an otherwise async module) - Description: Both runtimes perform deliberately expensive hashing synchronously on the thread that serves requests. Node uses 100,000 PBKDF2 iterations; Python uses bcrypt defaults. Each call takes tens to hundreds of milliseconds of CPU.
- Impact: A burst of login or signup attempts stalls every other request in the process, which makes this a cheap denial-of-service lever as well as a latency problem.
- Recommendation: In Node, use the async
crypto.pbkdf2orscrypt. In Python, wrap the bcrypt calls inasyncio.to_threador expose async variants and use them from async handlers.
P-005 · Every authenticated request costs a fresh AuthGuard round trip, and the login-required flag is re-read per request · Medium
- Location:
backend/auth/proxy.go:504(CurrentUsercalls AuthGuard/api/meon each request),backend/auth/proxy.go:512,:566,:598,:651,:733,:773,:848(each re-reads the login-required setting from the store),packages/node-backend/src/authclient.js:167(validateper request),packages/python-backend/src/shared_backend/authclient.py:254(same),backend/authclient/client.go:265-285(middleware validates per request) - Description: No client caches validated sessions, and the Go proxy re-reads the login-required flag from Postgres in each middleware and handler. A request carrying an invalid token still triggers an outbound call. The clients are otherwise correct about timeouts and context propagation.
- Impact: Every request pays an AuthGuard round trip and at least one database read, so latency and load on AuthGuard and Postgres scale directly with traffic. Invalid tokens can be used to drive outbound calls.
- Recommendation: Cache the login-required flag in memory with a short TTL, passing the resolved value down the request. Add a short-TTL session cache keyed by a SHA-256 of the token, storing both positive and negative results and bounded in size. Keep connections pooled in every client.
P-006 · Outbound AuthGuard calls use blocking urllib on the default thread pool · Low
- Location:
packages/python-backend/src/shared_backend/authclient.py:265(asyncio.to_thread),:276(urllib.request.urlopen),packages/node-backend/src/authclient.js:177(abort timer) - Description: The Python client performs blocking
urllibcalls throughasyncio.to_thread, which uses the event loop's default executor shared with otherto_threadusers, and opens a new connection per call. In Node the abort timer is set at line 177; the review pass reports it is cleared once headers arrive, which would leave the body read without a deadline (needs verification atauthclient.js:186-188). - Impact: A slow AuthGuard can exhaust executor threads needed elsewhere in the process, and a stalled response body can hang a request.
- Recommendation: Use a pooled async HTTP client (httpx or aiohttp in Python; undici or a reused agent in Node), and keep the timeout active until the body is fully read, or apply an overall deadline.
P-007 · Admin user operations over-fetch and make sequential calls; the Go store lists all users · Low
- Location:
packages/python-backend/src/shared_backend/authproxy.py:644-652(updating one user lists all users to find it),packages/python-backend/src/shared_backend/authproxy.py:406-416(/statusmakes two sequential AuthGuard calls),backend/auth/store.go:294(ListUsersreturns every row with no limit) - Description: After a user update the Python handler fetches the entire user list to locate one row. The status endpoint makes two independent AuthGuard calls one after the other. The Go store's
ListUsershas noLIMIT, and the client list calls have no pagination. - Impact: Latency and memory grow with the number of accounts.
- Recommendation: Add a get-by-id method (or return the updated record from the update call), run independent calls concurrently, and add pagination to the list endpoints.
P-008 · CarrierNode client has no transport timeout; the media proxy depends on caller deadlines · Low
- Location:
backend/carriernodeclient/carriernodeclient.go:28-30(package-levelhttp.Clientwith noTimeout; the comment says callers set context deadlines),backend/carriernodeclient/carriernodeclient.go:171-213(Proxyuses the incoming request context),backend/carriernodeclient/carriernodeclient.go:510-522(thumbnail HEAD probe on the same client) - Description: The shared client is deliberately timeout-free so that large media streams are not cut off. Control calls and the proxy paths rely on each caller to attach a deadline. Where a caller does not, a hung CarrierNode holds the request open indefinitely.
- Impact: Goroutines and client connections can be tied up by a slow upstream. The severity depends on consumers' server-level timeouts (needs verification).
- Recommendation: Set a
ResponseHeaderTimeouton the transport so that stalled upstreams fail quickly while streams still work. Attach deadlines to control calls, and document the requirement for callers that use the proxy paths.
P-009 · Status widget polls two endpoints every 15 seconds regardless of tab visibility · Low
- Location:
packages/web-ui/src/lib/components/StatusWidget.svelte:76-79(onMountstarts a 15 s interval that issues/healthzand/readyrequests) - Description: Each mounted
StatusWidgetpolls both probes on a fixed interval, with no check fordocument.hidden. Consumers may mount the widget on several pages or in several open tabs. The cleanup on unmount is correct. - Impact: Background tabs and multiple widgets add steady load to every backend that exposes these probes.
- Recommendation: Pause polling while
document.hiddenis true and refresh onvisibilitychange. Consider a longer interval for/ready, which may query the database.
P-010 · Info: the root prepare script builds on install, and CI runs the build twice · Info
- Location:
package.json(preparerunsnpm run buildandbuild-root-styles;testrunsnpm run buildbeforetest:node-backend),.github/workflows/tests.yml(npm cifollowed bynpm test) - Description:
npm ciruns the rootpreparescript, which builds the web-ui package, and thennpm testbuilds it again. - Impact: Extra CI time on every run. No runtime impact.
- Recommendation: Either skip the duplicate build in
test, or move the build out ofprepareinto an explicit CI step.
Notes
- Docker: No Dockerfile, compose file or
.dockerignoreexists in this repository, so image size, multi-stage builds and base-image checks do not apply here. Consumer projects that build images from the vendored snapshot should be reviewed separately. - Frontend checks: No whole-library imports were found;
@lucide/svelteis imported by name in every component. No{@html}, unbounded caches or leaked intervals were found in the web-ui, and the timers and listeners inMediaPlayer,MediaPlayerControls,StatusWidget,AppShellandnotifications.svelte.tsare cleaned up.shared-styles.css(1134 lines, about 21 KB) is loaded in full by consumers. As a component library it has no route-level code-splitting, which is expected rather than a defect. Four of seven{#each}blocks in the components are keyed; the remaining ones are listed under quality findings. - HTTP caching and compression: Not applicable to the library code; the backends are API services and the static styles are shipped to consumers' own build pipelines.
- Not verified: No query plans (no database access), no benchmarks or profiling, no build or test runs. Counts and ordering are based on code reading only.
- Excluded from analysis:
packages/web-ui/distand.svelte-kit(gitignored, not tracked),package-lock.jsonandgo.sum(used for versions only).