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:
@@ -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