Files
routstrd/tests
8a69816029 fix(security): daemon config written world-readable — enforce 0600/0700, atomic writes (#86)
* pi integration

* feat: wire routstrModelsPubkey through daemon

Add RoutstrdConfig.routstrModelsPubkey and pass it to ModelManager and the HTTP handler deps, forwarding it into routeRequests so the models allowlist pubkey (kind 38423) can be set independently of the audit pubkey (kind 38425).

* chore: link @routstr/sdk as file dep; ignore findings

Switch @routstr/sdk to file:../routstr-sdk for local development, refresh bun.lock, and ignore findings artifacts.

* fix(security): write daemon config with 0600/0700 perms, atomically

The daemon config stores spend-capable credentials (operator nsec and the
NWC connection string), but saveDaemonConfig wrote it with Bun.write() and
no mode, and ensureDirs created the config dir with no mode — yielding a
0755 dir and 0644 file under the standard 022 umask, readable by any local
user. The wallet seed path already gets this right (0700/0600), so this was
an inconsistency, not a trade-off.

- saveDaemonConfig now writes via temp-file + rename with mode 0600
  (mirroring saveConfig in wallet/coco-client.ts), is synchronous so write
  errors propagate instead of being silently dropped, and chmods the target
  so previously over-permissive files are repaired on every save.
- ensureDirs creates CONFIG_DIR/REQUESTS_DIR with mode 0700 and chmods
  existing dirs, correcting older installs on every daemon start.
- loadDaemonConfig/loadDaemonConfigSync chmod the config file 0600 on read,
  so even a never-saved install gets repaired.
- cli.ts routes its raw Bun.write(CONFIG_FILE) calls (init, nsec generation,
  remote/local mode switch, mode set) through saveDaemonConfig and uses
  ensureDirsSync for the initial directory creation.

Also fixes the crash-mid-write hazard: a torn JSON write previously made
loadDaemonConfig silently revert to DEFAULT_CONFIG, dropping nsec/NWC/
provider settings; the atomic rename prevents that.

Adds subprocess-isolated regression tests (tests/daemon/) asserting
0600/0700 on fresh installs, repair of 0644/0755 installs, synchronous
error propagation, and corrupt-JSON fallback.

---------

Co-authored-by: redshift <213178690+1ftredsh@users.noreply.github.com>
2026-08-24 20:58:36 +00:00
..