Files
Hello/docs/OPEN-TOPICS.AI.md
Thomas KarnerandClaude Opus 5 6907d9a014 Add a front door, a user guide in two languages, and an honest list of what is broken
Four documents and two fixes to the deploy directory that the documents
exposed while being written.

The repo had no root README. Cloning it landed you on a 40 KB spec and a 24 KB
plan with nothing to orient you, which mattered more once main stopped being
an empty branch. The new one links rather than duplicates, and its status table
says plainly what has never run on hardware and that there are no backups.

docs/README.USER.md and its German twin are written for someone who will use
this, not build it: what radar buys over a PIR sensor, why there is no sign-up
page, what "pre-trigger" means, what to do when the six-digit code is refused.
Every POORBIRD_* setting is described in plain language, including the two that
cost an hour each the first time they bite. The German version is a
translation, not a mechanical flip of the English.

docs/OPEN-TOPICS.AI.md is the list nobody writes: unfixed security issues,
traps, and test debt, each labelled ACCEPTED, OPEN or TRAP, because the
difference between "known trade-off" and "not done yet" is the only thing that
makes such a list usable. It ends with a section of things that are NOT
problems -- the SHA-256/Argon2id split, the frozen 0001 migration, the finite
pool_timeout -- so they stop being rediscovered and "fixed".

Two real defects surfaced while documenting the install:

Nothing served the WebUI in production. The Caddyfile's human-facing block
only reverse-proxied to FastAPI, and FastAPI mounts no static files, so a
by-the-book install produced a working API and no gallery. It now has a
file_server with a try_files fallback, because the router does client-side
routing and without it only the entry page survives a reload.

INSTALL.md never created an account. With no sign-up endpoint, following it
end to end left you at a login form with no credentials that work -- the exact
wall hit on the dev machine today, and worse on a headless host. It also never
built or copied the UI, so a git pull on the server silently kept the old
bundle; that is now its own step, with --delete spelled out because Vite emits
content-hashed filenames.

Verified: caddy validate via the official caddy:2 image reports "Valid
configuration" (with the cloudflare-DNS block stripped, since that plugin is
not in the stock image and the block is unchanged); npm run build is clean at
192 modules; all 31 relative links across every .md resolve; the committed
line endings are LF, so caddy fmt's complaint was my working tree only.

Not verified: none of the install has run on a real host. The doc says so.

One claim was wrong before it shipped: both guides said signing out ends every
session everywhere. logout calls revoke_session for the current token only --
revoke_all_for_user exists but is not called there -- so it ends that browser's
session alone, and `user passwd` is what clears them all. Corrected in both
languages.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 23:01:20 +02:00

19 KiB

Open topics and unfixed security issues

Scope: the whole repository, develop. Written against: f9d0b09 plus the deploy changes committed alongside this file. Date: 2026-09-21. Audience: an AI or a maintainer picking this up cold.


How to read this

This is a list of what is not done, deliberately or otherwise. It is not a review of the code that exists — for that, see reviews/, which holds branch-scoped snapshots.

Three labels are used, and the difference between them is the point of the document:

Label Means
ACCEPTED A known trade-off, decided on purpose, with the reasoning recorded. Do not "fix" one of these without reopening the decision — several exist specifically to prevent a well-meant change that breaks something worse.
OPEN A real gap. Not yet paid for. Fixing it is straightforward and wanted.
TRAP Works as written, but will mislead someone. Usually a default, a missing step, or a silent failure mode.

Every claim below was verified against the code at the commit named above. Where a line number is given, it was read, not remembered. If you are reading this later and a reference does not match, trust the code.


1. Security — accepted trade-offs

SPEC C2. The camera speaks unencrypted HTTP on :8080 (server/deploy/Caddyfile, the :8080 block). TLS on an ESP32-S3 means a CA baked into the firmware image and a camera that silently stops uploading when that chain rotates — while mounted outdoors, where it cannot be reflashed.

What this actually exposes: the device bearer token crosses the LAN in cleartext on every request. Anyone already on the network can capture it and then impersonate that camera indefinitely — post fabricated captures, drain its command queue, read its config. Passive capture of the images themselves is the lesser problem.

What would fix it without TLS: HMAC request signing with a per-device key, which is cheap on an ESP32 and needs no certificate chain. It requires a coordinated firmware change, so it is a firmware/API.md contract revision, not a server-side patch.

Why it stays: the threat model is a home LAN behind Tailscale. Worth revisiting the moment this is reachable from anywhere else.

1.2 ACCEPTED — one enrollment secret, shared, compiled into firmware

POORBIRD_ENROLL_SECRET is one value for all cameras (server/src/poorbird/config.py:84) and is compiled into the firmware image as the last-resort recovery path for a camera that cannot be reached over USB (firmware/API.md).

Consequences, both real: extracting the flash of one camera yields the enrollment credential for the whole fleet; and rotating it on the server without shipping new firmware removes the only way back into a mounted camera. Both are documented at the point of use, including in config.py and deploy/poorbird.env.example.

Per-device pre-shared keys would fix the first and worsen the second.

1.3 ACCEPTED — failed logins are limited by address, never by username

api/ratelimit.py:201 — LOGIN = Limit.per_hour(30, burst=8), keyed by_address.

Keying on username would let anyone lock a known account out of its own service by guessing at it, which converts a nuisance into a denial of service against a specific person. The cost of the choice is the mirror image: an attacker spread across many source addresses gets proportionally more attempts, and a legitimate user sharing a NAT with an attacker gets throttled.

There is deliberately no account lockout for the same reason.

1.4 ACCEPTED — SameSite=Lax, not Strict

api/sessions.py. Strict means following a link from anywhere outside the app presents as signed out, which trains people to distrust the login. Lax permits the cookie on top-level cross-site GET only; every mutation is POST/PUT/PATCH/DELETE and goes through the CSRF middleware, so the residual exposure is limited to read-only navigations.

1.5 ACCEPTED — device endpoints have no CSRF check

api/userauth.py, csrf_middleware. It returns early unless the method is unsafe and the request carries the session cookie. Device requests are bearer-authenticated and carry no cookies, so they are never in scope — which is correct, because CSRF is an attack on ambient browser credentials and a camera has no browser.

Do not "fix" this by applying CSRF to all unsafe methods. It would break every device endpoint and protect nothing.

1.6 ACCEPTED — images are authorised by the app, served by Caddy

api/delivery.py + the protected_files snippet in deploy/Caddyfile. The app checks the session, then returns an empty 200 carrying X-Accel-Redirect; Caddy reads the file. serve_images_directly=true makes the app send the bytes itself, for development where there is no Caddy.

The flag does not relax authorisation — the same check runs in both paths, and the only difference is how an already-authorised response is finished. This was built as one code path with two endings, specifically to avoid a separate unauthenticated dev route, which is the kind of thing that survives into production because it works.

_safe_absolute() resolves the stored relative path and answers 404 — not 403 — on any escape from the configured root. The traversal test escapes to a canary file that genuinely exists outside the root; it was originally written against /etc/passwd, which does not exist on the Windows dev machine, so it would have passed with the guard removed. Keep the canary.


2. Security — open, not yet paid for

2.1 OPEN — a TOTP code can be replayed for ~90 seconds

totp.py:25 sets VALID_WINDOW = 1, so the previous, current and next 30-second steps are all accepted. Nothing records which codes have been used, because there is no column for it. An observer who sees a code once can use it until its window closes.

Fix: add users.totp_last_counter, reject any counter <= the stored value, and persist on success. One migration, a few lines in api/routes/auth.py around the check at auth.py:135-140.

The limitation is documented in the verify() docstring rather than left implicit. On a Tailscale-only LAN the observer has already had to get onto the network; that stops being reassuring the day this is public.

2.2 OPEN — TOTP cannot be added, removed or repaired after account creation

cli.py exposes only user add, user list and user passwd. There is no user delete and no way to change the second factor later.

Three consequences, all reachable today:

  • An account created with --no-totp (cli.py:133-134, which warns) stays without a second factor permanently.
  • Losing the otpauth:// URI — printed exactly once — bricks that account. There is no recovery path short of editing the database.
  • A wrong --role or a typo'd username cannot be undone.

The dev admin me on this machine was created with --no-totp, so it is an instance of the first case.

Fix: poorbird user totp --enable|--disable NAME, poorbird user delete NAME, poorbird user role NAME --role X. All small; none exist.

2.3 OPEN — audit_log only records authentication

api/routes/auth.py writes login, login_failed (with a reason) and logout. Nothing else writes to the table. Content mutations — observations, tags, device config, keep/reject decisions — leave no trace, so "who changed this label, and when" is currently unanswerable.

The table and its ON DELETE SET NULL on user_id are already in the schema, so this is purely a matter of adding writes as each endpoint lands. Recorded in TODO.md Phase 3.

2.4 OPEN — no password reset, and no second admin by default

If the only admin's password is lost, recovery is manual SQL. user passwd requires shell access on the server, which is the intended trust model, but it means there is no in-band recovery at all. Worth at least documenting a "create a second admin" step; worth more if this is ever used by someone other than its author.

2.5 OPEN — rate limits are per-process, and nothing enforces one process

api/ratelimit.py uses in-process token buckets, sized for a single uvicorn process. Running with --workers N silently multiplies every effective limit by N, including the login limit.

Nothing in deploy/poorbird-api.service prevents that being added later by someone reasoning that more workers is faster. SPEC C8 rules out Redis, so the fix is either a Postgres-backed limiter or an assertion at startup that there is exactly one worker. Currently it is a comment in the module docstring.


3. Traps

3.1 TRAP — api_port defaults to 8080, which is the camera's Caddy port

config.py:52 — api_port: int = 8080. Meanwhile deploy/poorbird.env.example:30 sets POORBIRD_API_PORT=8090, and deploy/Caddyfile proxies to 127.0.0.1:8090 and itself binds :8080 for the camera.

So the code default and the deployment disagree, and the default collides with Caddy's own listener. Any host where POORBIRD_API_PORT is unset gets uvicorn on 127.0.0.1:8080 — contending with Caddy's :8080 site and unreachable from the proxy, which is looking at 8090.

Fix: change the default in config.py to 8090 so code and deployment agree. Trivial, and nothing depends on 8080.

A Secure cookie is discarded by the browser over plain HTTP. The login returns 200, the session row is created, and the browser is not signed in. Nothing appears in any log, because from the server's point of view nothing went wrong.

This is documented in three places now (config.py:92-97, poorbird.env.example, web/README.md) and, as of this commit, in deploy/INSTALL.md next to the "for a first test, drop the tls block" suggestion that triggers it. It stays on this list because the failure mode is undetectable from the server side and costs an hour every time it is met fresh.

3.3 TRAP — a git pull on the host never updates the UI

web/ is built on the dev machine and shipped as static files (SPEC §6). There is no Node on the server and no build step in deploy/poorbird-api.service. Pulling and restarting gives a new API with the old bundle, and the mismatch shows up as UI features that appear not to work.

Covered in INSTALL.md step 7 and the Upgrading section as of this commit. Vite emits content-hashed filenames, so the copy must use --delete or stale bundles accumulate indefinitely.

3.4 TRAP — running the test suite deletes seeded captures

tests/test_seed.py:36-49, the no_seed_left_behind autouse fixture, sweeps Device.device_uid.startswith(SEED_UID_PREFIX) and deletes every match plus its captures. A developer's own poorbird seed --captures 500 uses that same 5eed prefix, so pytest destroys it. Observed twice on 2026-09-21.

The fixture cannot delegate to clear(), because clear() is the function under test — a broken clear() would then leave the database dirty and hide that it was broken. So it re-derives the scope, and the derived scope cannot distinguish a test's seed device from a person's.

Fix: have the fixture record the device ids it creates and delete exactly those.

Not at risk: user accounts and real camera devices. Every other teardown in the suite deletes by explicit id — verified across test_auth.py:110, test_captures.py:73,127-128. The garden-feeder device on the dev machine has survived every run.

3.5 TRAP — the test suite shares the development database

tests/conftest.py connects to whatever POORBIRD_DATABASE_URL points at, and test_schema_matches_models.py additionally creates and drops a poorbird_schema_check database on the same server, needing a role that may CREATE DATABASE. Combined with 3.4, running tests against a database that holds anything you care about is a mistake waiting to happen.

Mutation-testing clear() was done against an isolated scratch database for exactly this reason.


4. Deployment — changed in this commit, and unverified

deploy/Caddyfile previously had no file_server for the built UI, and FastAPI mounts no static files, so nothing served the WebUI in production. INSTALL.md also never created an account, so a by-the-book install ended at a login form with no usable credentials.

Both are addressed in this commit. What that is worth:

  • The Caddyfile syntax is validated — caddy validate via the official caddy:2 image, with the cloudflare-DNS tls block stripped because that plugin is not in the stock image and that block is unchanged. Result: Valid configuration.
  • npm run build was run: typecheck clean, 192 modules, 400 kB → 127 kB gzip.
  • Nothing has been run on a real host. The try_files fallback, the X-Accel-Redirect handoff against a real Caddy, the systemd units and the account-creation step under sudo -u poorbird are all unexercised. Treat section 6-8 of INSTALL.md as untested instructions.

The whole install has never been performed end to end. Until it has, the deploy directory is a plausible plan, not a proven procedure.


5. Test and process debt

OPEN No ESLint. tsc --noEmit catches the important class of mistakes; the flat-config setup was skipped during scaffolding and never revisited.
OPEN No test runs the UI. There is no component or end-to-end test in web/ at all — the gallery's behaviour is covered only by the server tests behind it and by looking at it.
OPEN Virtualisation is unmeasured. The grid is built to recycle rows and the data path is verified over 506 captures, but nothing asserts that DOM node count stays bounded as you scroll. That is the property the whole design exists for.
ACCEPTED Two tests once passed for the wrong reason, both now fixed: a pool-size assertion whose expected value equalled SQLAlchemy's own default, and the traversal test described in 1.6. The lesson is recorded here because it generalises — assert against values that differ from the library's defaults, or the test cannot fail.
ACCEPTED Reviews under reviews/ are point-in-time snapshots and are deliberately not updated. Their "12/12 tests" and "what's missing" sections describe the commit in their header. Several reference implementations in them are wrong; where that mattered, the code that replaced them says so.

6. Functional gaps, by phase

Phase 3, still open:

  • taxa is not seeded, so there is no species list. Taxon and tag filters are therefore absent from both GET /api/v1/captures and the UI — deliberately, rather than shipped as controls with nothing behind them.
  • No observation editor. The gallery reads and displays observations; nothing writes them. Labelling, the actual point of the project, does not exist yet.
  • users.theme and users.locale are in the schema and returned by /auth/session, but the UI keeps both in localStorage. A second browser starts from the default.
  • The viewer steps only through loaded captures. At the end of a page the arrow disables rather than fetching the next one.

Phase 4:

  • No device listing endpoint, so the Devices page is an honest empty state and the gallery's device filter is built from whatever devices appear in loaded captures.
  • No admin POST /api/v1/firmware, so OTA images cannot be uploaded through the UI.
  • firmware.is_target has no single-row constraint. Two rows marked as the target is a state the schema currently permits and the OTA logic does not expect.
  • CORS is unconfigured. Correct today — Caddy serves UI and API from one origin — but it needs a deliberate answer before anything is ever served from a second origin, rather than a permissive header added under pressure.

Phase 5:

  • No backups of any kind. Blocked on open question 9 (whether the NAS offers SFTP or only SMB/NFS), which decides between restic and a mounted path. The image store and the database are both unprotected. This is the single largest operational gap in the project.
  • No retention or pruning. Captures accumulate without bound; kept exists in the schema but nothing acts on it.

Phase 6:

  • /stream is unimplemented. It is the one part of firmware/API.md with no server side at all.

7. Not problems — do not re-open these

Listed because each one looks like an oversight and is not.

  • Sync SQLAlchemy, not async. Deliberate. The workload is a handful of concurrent requests and a background worker; async buys nothing here and costs a second idiom for every contributor.
  • The job queue is a Postgres table using FOR UPDATE SKIP LOCKED, not Redis or Celery (SPEC C8). One fewer service to run, monitor and back up.
  • Device tokens are SHA-256, user passwords are Argon2id. Not an inconsistency. Device tokens are 256-bit CSPRNG output, so there is nothing to brute-force and a slow hash would only add latency to every ingest; passwords are human-chosen, so slowness is the entire point. Both are explained at api/deps.py.hash_credential and passwords.py.
  • verify_password returns False instead of raising for None, "" or a corrupt hash. Every Phase 1 row has a NULL password_hash, so raising would turn a normal state into a 500.
  • Password rehash on login is already wired (auth.py:147, needs_rehash). If Argon2 parameters change, hashes migrate as people sign in.
  • The login endpoint hashes a password even when the username does not exist, discarding the result. Without it, a missing username returns measurably faster than a wrong password, which is a username oracle.
  • CSRF is compared against the token on the session row, not merely cookie-against-header. Plain double-submit accepts any self-consistent pair, so anyone able to set a cookie on the domain satisfies it while the victim's session cookie rides along.
  • 0001_initial.py is frozen explicit DDL. It used to call Base.metadata.create_all(), which meant a clean database got the current models and then later migrations tried to add columns that already existed. Do not edit it to reflect a model change; add a revision.
  • pool_timeout is finite (30s), on purpose. An infinite timeout turns a pool leak into a permanent hang with no error.
  • received_at is authoritative, not captured_at_device (SPEC C7). The camera has no battery-backed clock; captured_at_device is NULL when it was unsynced and must never be rendered as 1970.
  • Model-sourced observations are badged as predictions. The observations table is also the training data for any future model, so a guess displayed as a human label would poison it.
  • The purge of expired sessions lives in worker/handlers.py, not imported from api/. The worker must not import from the API layer; that layering rule is why images.py sits at the package root.