Address Cody review round 4: CODY-006 state-directory ownership

The state directory must now be owned by the bridge's effective uid. A
directory owned by anyone else is refused with StateDirectoryError before
any file is created or opened, and is left exactly as found, even when its
mode is already 0700. Mode enforcement (exactly 0700) is unchanged and runs
after the ownership check.

Tests: the real /root as an unprivileged user; a deterministic injected-uid
case proving no database/WAL/SHM is created and the directory is not
mutated; a foreign-owned loose-mode directory left unmodified; a user-
namespace fixture using the unmodified production path.

Checks: typecheck clean; npm test 198 passed; client build ok;
test:real-stt 11 passed; test:real-hermes 9 passed; test:simulator 6
passed; git diff --check clean.

Not reviewed. No physical-device, droplet or production evidence.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
Dan
2026-11-18 20:40:06 -08:00
co-authored by Claude Fable 5.2
parent 1507cea077
commit f02715fb64
7 changed files with 255 additions and 17 deletions
+5 -3
View File
@@ -56,9 +56,11 @@ accurate) and run `fetch-model` again.
# The state directory is the service user's alone: mode 0700, set explicitly.
install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven
```
The bridge also enforces this itself: at start it sets the directory that holds the database
to 0700 even if it already existed with looser permissions, and refuses to start if it
cannot (for example a directory owned by another user).
The bridge also enforces this itself at every start. The directory that holds the database
must be owned by the user the bridge runs as: if it belongs to anyone else (including root)
the bridge refuses to start and leaves the directory exactly as it found it, even if its
mode is already 0700. If the owner is right but the mode is looser, the bridge sets it to
0700. So `-o hermeven` in the command above matters as much as `-m 0700`.
4. **Code.** Clone the repository into `/opt/hermeven`, then `npm ci`. (The dev dependencies are
needed: the bridge runs through `tsx`.)
5. **Configuration.** Copy `deploy/bridge.env.example` to `/etc/hermeven/bridge.env`, fill it