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:
@@ -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
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# Handoff for Cody, Round 5
|
||||
|
||||
From: Claude (implementation). Date: 2026-11-18.
|
||||
|
||||
**Not reviewed.** Cody's Round 4 verdict applies to `1507cea` only.
|
||||
|
||||
| Item | Value |
|
||||
|---|---|
|
||||
| Repository | `git@git.xylo.gg:Xylo-Digital/hermeven.git` |
|
||||
| Branch | `cody/slice-1-review` |
|
||||
| Reviewed in Round 4 | `1507cea077838852bfa3658a0d6ef5f419fd8437` |
|
||||
| `main` | `0c9dcd864f16782097471e5bbf57cbd701c26616` (unchanged; nothing merged) |
|
||||
| New head for Round 5 | the tip of `cody/slice-1-review` after this push; exact SHA in the push report |
|
||||
|
||||
## CODY-006: foreign-owned state directory
|
||||
|
||||
| Required correction | What was done |
|
||||
|---|---|
|
||||
| 1. Final owner equals the bridge's effective uid, or a configured trusted-owner model | The owner must equal `process.geteuid()`. No trusted-owner option was added. |
|
||||
| 2. Reject foreign ownership with `StateDirectoryError` before SQLite creates or opens any file | The ownership check is the first check after "is a directory", inside `secureStateDir()`, which `openDb()` calls before it creates the file or constructs the database. |
|
||||
| 3. Preserve exact 0700 enforcement | Unchanged; runs after the ownership check, and ownership is checked once more after any `chmod`. |
|
||||
| 4. Preserve the deployment command | `install -d -m 0700 -o hermeven -g hermeven /var/lib/hermeven` is unchanged in `docs/deploy-droplet.md`; the paragraph after it now states that ownership is enforced and why `-o` matters. |
|
||||
| 5. Actionable error, refused directory not mutated | The message names the directory, its owner uid, the bridge's uid, the required mode and the `install` command. A refused directory is not `chmod`-ed, even when its mode is loose. |
|
||||
|
||||
Changed files: `services/bridge/src/db.ts`, `services/bridge/test/units.test.ts`,
|
||||
`docs/deploy-droplet.md`, `docs/security.md`, `docs/test-evidence.md`, this file.
|
||||
|
||||
`openDb()` gained an optional `{ effectiveUid }` argument so the refusal can be tested
|
||||
deterministically on any machine. Production code never passes it. The same refusal is also tested
|
||||
without it, against the real `/root` and inside a user namespace.
|
||||
|
||||
## Checks
|
||||
|
||||
| Check | Result |
|
||||
|---|---|
|
||||
| `npm run typecheck` | exit 0 |
|
||||
| `npm test` | 198 passed, 0 failed (was 194) |
|
||||
| `npm run client:build` | built |
|
||||
| `npm run test:real-stt` | 11 passed, 0 failed |
|
||||
| `npm run test:real-hermes` | 9 passed, 0 failed |
|
||||
| `npm run test:simulator` | 6 passed, 0 failed |
|
||||
| `git diff --check` | clean |
|
||||
|
||||
No check was omitted. CODY-003's tests (`tests/integration/durableRequestId.test.ts`) and the
|
||||
other resolved findings' tests are unchanged and passing.
|
||||
|
||||
## Things the author is unsure about
|
||||
|
||||
- A bridge run as root against a directory owned by a service user is also refused, since the
|
||||
owner is not the process's own uid. That is the strict reading of the finding; it means the
|
||||
operator CLI must be run as the service user (as the deployment guide already does for `pair`).
|
||||
- On a platform without POSIX uids the ownership check is skipped. The bridge is only documented
|
||||
for Linux.
|
||||
- The check and the later file creation are separate steps; a directory replaced in between by
|
||||
someone with write access to its parent would not be noticed.
|
||||
|
||||
## Not claimed
|
||||
|
||||
No physical device, no droplet, no deployment, no production change. Nothing merged to `main`.
|
||||
+1
-1
@@ -36,7 +36,7 @@ devices. Not reviewed by anyone but its author yet; see `docs/handoff/`.
|
||||
| Cross-origin browser abuse | CORS allows only exact configured origins and sends no credentials mode. CORS is not treated as authentication: every route still needs the bearer credential. | yes |
|
||||
| Secrets or content in logs | Logs carry ids, states, codes and timings. Request logging is off, a redaction list backs it up, and Hermes's own diagnostic text is never relayed or logged. | yes |
|
||||
| Substituted speech-model files | The model is pinned to a commit id with a SHA-256 for every file. Files are fetched ahead of time and verified; the bridge re-verifies on every load, never downloads at run time, and reads from a directory that can be read-only. There is no unpinned mode. | yes, including with no network at all |
|
||||
| State files readable by other users | The directory holding the database is set to 0700 at every start, whether it was just created or already existed, and the bridge refuses to start if it cannot be. The database is created owner-only before SQLite opens it (so its WAL and SHM files inherit that); the systemd unit sets `UMask=0077`. | yes, under umask 0022, for new and pre-existing directories |
|
||||
| State files readable by other users | At every start the directory holding the database must be owned by the bridge's own user (a directory owned by anyone else is refused untouched, whatever its mode) and is set to 0700, whether it was just created or already existed; the bridge refuses to start otherwise. The database is created owner-only before SQLite opens it (so its WAL and SHM files inherit that); the systemd unit sets `UMask=0077`. | yes, under umask 0022, for new and pre-existing directories |
|
||||
| A running turn forgotten by the app | The request id is stored on the phone before anything is sent, and the request is not sent until the phone has confirmed the write. A write that times out or is refused holds the request back, unsent, for a retry under the same id. | yes, with the production Even adapter and a stalled host write |
|
||||
| Recordings retained | Audio exists only in memory for the length of one transcription call and is never written to disk by the bridge. | by construction; not independently audited |
|
||||
| Agent approves its own privileged action | The bridge never calls Hermes's approval endpoint. | yes |
|
||||
|
||||
@@ -373,3 +373,47 @@ write is stuck, HUD updates queued behind it are not drawn until it completes.
|
||||
|
||||
Eight ways of removing these two fixes were tried against the default suite; all eight were
|
||||
caught (between 1 and 6 failing tests each).
|
||||
|
||||
## Round 5: after Cody's Round 4 review (2026-11-18)
|
||||
|
||||
Cody reviewed `1507cea`: CODY-003 resolved; CODY-006 still open because `secureStateDir()`
|
||||
accepted a directory already at 0700 that belonged to another user (reviewer proof:
|
||||
`secureStateDir('/root')` returned successfully for uid 1000).
|
||||
|
||||
```
|
||||
$ npm run typecheck exit 0
|
||||
$ npm test Test Files 11 passed (11) Tests 198 passed (198) (3 consecutive runs)
|
||||
$ npm run client:build built
|
||||
$ npm run test:real-stt Tests 11 passed (11)
|
||||
$ npm run test:real-hermes Tests 9 passed (9)
|
||||
$ npm run test:simulator Tests 6 passed (6)
|
||||
$ git diff --check clean
|
||||
```
|
||||
|
||||
No check was omitted, and none of the new tests printed "NOT RUN" on this machine.
|
||||
|
||||
Cody's reproduction, re-run on the corrected code as uid 1000:
|
||||
|
||||
```
|
||||
secureStateDir('/root')
|
||||
StateDirectoryError: The state directory /root is owned by uid 0, not by the bridge, and has
|
||||
been left untouched. The bridge keeps device credentials there and needs a directory of its own,
|
||||
owned by uid 1000, the user it runs as, with mode 0700. ...
|
||||
```
|
||||
|
||||
New tests in `services/bridge/test/units.test.ts`:
|
||||
|
||||
| Scenario | Result |
|
||||
|---|---|
|
||||
| The real `/root` (uid 0, mode 0700) as uid 1000: `StateDirectoryError` from both `secureStateDir` and `openDb`; mode, owner, mtime and ctime of `/root` unchanged | pass |
|
||||
| Deterministic, any machine: a 0700 directory whose owner differs from the bridge's uid (the uid is injected, the directory is real): `StateDirectoryError`; the directory stays empty (no database, WAL or SHM); mode, owner and timestamps unchanged. With an existing empty database file present: not opened, still 0 bytes | pass |
|
||||
| Foreign-owned directory at 0755: refused, and still 0755 afterwards (not "fixed" for someone else) | pass |
|
||||
| Isolated user fixture: in a user namespace (`unshare -r`), with the unmodified production code path and the process's real uid, a foreign-owned 0700 directory is refused and unchanged | pass |
|
||||
|
||||
Retained and passing: new directory under umask 0022; pre-existing 0755 directory tightened to
|
||||
0700 with database, WAL and SHM at 0600; the loose-mode matrix (0750, 0777, 0711, 0701); the
|
||||
transient-permission check; the cannot-secure refusal with its operator message; the
|
||||
parent-is-a-file refusal.
|
||||
|
||||
Three ways of removing the ownership check were tried against the suite; all three were caught
|
||||
(2 to 4 failing tests each).
|
||||
|
||||
Reference in New Issue
Block a user