Address Cody review round 2: all ten findings (CODY-001 to CODY-010)

CODY-001 Bridge URL must be HTTPS (HTTP only to loopback), in the client and
         in manifest generation.
CODY-002 Even host calls stay serialised until the SDK call really settles;
         a microphone start that completes after its timeout is followed by
         a stop.
CODY-003 Request id is stored before the first submit and cleared only on a
         definitive answer; lost replies are treated as ambiguous and
         reconciled under the same id; HUD no longer claims "not sent".
CODY-004 Revoking a device cancels its in-flight turns, aborts
         transcription and asks Hermes to stop, from HTTP and CLI paths.
CODY-005 Speech model pinned to a commit with per-file SHA-256; fetched and
         verified ahead of time; verified on every load; never downloaded
         at run time; no unpinned configuration.
CODY-006 State directory 0700, database/WAL/SHM 0600 regardless of umask.
CODY-007 credential_expired handled like unauthorized on every path.
CODY-008 Approval wait start and paused agent deadline persisted and
         restored across restarts (schema v2).
CODY-009 Exactly one conversation create per epoch, sent in sequence, with
         stale results dropped before persistence.
CODY-010 Wrong pairing guesses no longer consume the outstanding code;
         failures are indistinguishable.

Checks: typecheck clean; npm test 182 passed; client build ok;
test:real-stt 11 passed (including with no network); 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 19:49:14 -08:00
co-authored by Claude Fable 5.2
parent 3d5691dfa3
commit e1c02d5266
43 changed files with 2104 additions and 227 deletions
+63
View File
@@ -1,3 +1,8 @@
import { execFileSync } from 'node:child_process';
import { mkdtempSync, rmSync, statSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { describe, expect, it } from 'vitest';
import { ConfigError, loadConfig } from '../src/config.ts';
import { openDb } from '../src/db.ts';
@@ -46,6 +51,64 @@ describe('configuration', () => {
});
});
describe('state files are owner-only whatever the umask (CODY-006)', () => {
const mode = (path: string) => statSync(path).mode & 0o777;
it('under umask 0022 the directory is 0700 and the database, WAL and SHM are 0600', () => {
const root = mkdtempSync(join(tmpdir(), 'hermeven-perm-'));
const dbPath = join(root, 'state', 'hermeven.sqlite');
// A separate process, so the permissive umask is real and does not leak into this one.
const script = `
process.umask(0o022);
const { openDb } = await import(${JSON.stringify(fileURLToPath(new URL('../src/db.ts', import.meta.url)))});
const fs = await import('node:fs');
const { syncBuiltinESMExports } = await import('node:module');
// Record the loosest mode each state file ever has, from the instant SQLite or the
// bridge touches permissions, so a file that is briefly world-readable is caught too.
const loosest = {};
const seen = (p) => { try { const mode = fs.statSync(p).mode & 0o777; loosest[p] = Math.max(loosest[p] ?? 0, mode & 0o077); } catch {} };
const realChmod = fs.chmodSync;
fs.default.chmodSync = (p, mode) => { seen(${JSON.stringify(dbPath)}); seen(${JSON.stringify(dbPath + '-wal')}); seen(${JSON.stringify(dbPath + '-shm')}); return realChmod(p, mode); };
syncBuiltinESMExports();
const db = openDb(${JSON.stringify(dbPath)});
db.prepare("INSERT INTO pairing_codes (code_hash, created_at, expires_at) VALUES ('x', 1, 2)").run();
const { statSync } = fs;
const m = (p) => (statSync(p).mode & 0o777).toString(8);
const everLoose = Object.values(loosest).some((bits) => bits !== 0);
// Read while the database is open, so the WAL and SHM files exist.
console.log(JSON.stringify({ everLoose, umask: process.umask().toString(8), dir: m(${JSON.stringify(join(root, 'state'))}), db: m(${JSON.stringify(dbPath)}), wal: m(${JSON.stringify(dbPath + '-wal')}), shm: m(${JSON.stringify(dbPath + '-shm')}) }));
db.close();
`;
try {
const out = execFileSync(process.execPath, ['--import', 'tsx', '--input-type=module', '-e', script], {
encoding: 'utf8',
cwd: fileURLToPath(new URL('..', import.meta.url)),
});
expect(JSON.parse(out.trim().split('\n').at(-1)!)).toEqual({ everLoose: false, umask: '22', dir: '700', db: '600', wal: '600', shm: '600' });
expect(mode(dbPath)).toBe(0o600);
} finally {
rmSync(root, { recursive: true, force: true });
}
});
it('an existing database with loose permissions is tightened when opened', async () => {
const { chmodSync } = await import('node:fs');
const root = mkdtempSync(join(tmpdir(), 'hermeven-perm-'));
const dbPath = join(root, 'hermeven.sqlite');
try {
openDb(dbPath).close();
chmodSync(dbPath, 0o644);
const db = openDb(dbPath);
db.prepare("INSERT INTO pairing_codes (code_hash, created_at, expires_at) VALUES ('x', 1, 2)").run();
expect(mode(dbPath)).toBe(0o600);
expect(mode(`${dbPath}-wal`)).toBe(0o600);
db.close();
} finally {
rmSync(root, { recursive: true, force: true });
}
});
});
describe('device credentials', () => {
const setup = (env: Record<string, string> = {}) => {
let now = 1_000_000;