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:
@@ -15,11 +15,15 @@ export interface DeviceRow {
|
||||
}
|
||||
|
||||
export type AuthFailure = 'unauthorized' | 'credential_expired';
|
||||
export type PairingFailure = 'pairing_invalid' | 'pairing_locked';
|
||||
export type PairingFailure = 'pairing_invalid';
|
||||
|
||||
// No 0/O, 1/I/L: read aloud or typed on a phone without ambiguity. 31 symbols.
|
||||
const CODE_ALPHABET = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
|
||||
const CODE_LENGTH = 10; // ~49.5 bits; with 5 total failures before lockout, guessing is not viable.
|
||||
// ~49.5 bits. Brute force is bounded by this entropy, the code's few-minute lifetime and the
|
||||
// per-client attempt limit in the HTTP layer; see docs/security.md for the arithmetic. Wrong
|
||||
// guesses are deliberately NOT counted against the outstanding code: if they were, anyone
|
||||
// who can reach the endpoint could void the owner's real code with a handful of junk guesses.
|
||||
const CODE_LENGTH = 10;
|
||||
|
||||
export function sha256(value: string): string {
|
||||
return createHash('sha256').update(value).digest('hex');
|
||||
@@ -55,8 +59,8 @@ export class Devices {
|
||||
}
|
||||
|
||||
/**
|
||||
* Exchange a pairing code for a device credential. A wrong guess counts against every
|
||||
* outstanding code, so the code is burned after a few failures regardless of who guessed.
|
||||
* Exchange a pairing code for a device credential. A wrong, expired or already-used code
|
||||
* all fail the same way and change nothing: only the correct code consumes the code.
|
||||
*/
|
||||
claimPairingCode(
|
||||
rawCode: string,
|
||||
@@ -66,22 +70,10 @@ export class Devices {
|
||||
const hash = sha256(normalizeCode(rawCode));
|
||||
return this.db.transaction(() => {
|
||||
const live = this.db
|
||||
.prepare('SELECT id, code_hash, failed_attempts FROM pairing_codes WHERE used_at IS NULL AND expires_at > ?')
|
||||
.all(now) as Array<{ id: number; code_hash: string; failed_attempts: number }>;
|
||||
.prepare('SELECT id, code_hash FROM pairing_codes WHERE used_at IS NULL AND expires_at > ?')
|
||||
.all(now) as Array<{ id: number; code_hash: string }>;
|
||||
const match = live.find((row) => safeEqualHex(row.code_hash, hash));
|
||||
if (!match) {
|
||||
let locked = false;
|
||||
for (const row of live) {
|
||||
const failures = row.failed_attempts + 1;
|
||||
if (failures >= this.config.credentials.pairingCodeMaxFailures) {
|
||||
this.db.prepare('UPDATE pairing_codes SET failed_attempts = ?, used_at = ? WHERE id = ?').run(failures, now, row.id);
|
||||
locked = true;
|
||||
} else {
|
||||
this.db.prepare('UPDATE pairing_codes SET failed_attempts = ? WHERE id = ?').run(failures, row.id);
|
||||
}
|
||||
}
|
||||
return { ok: false as const, reason: locked ? ('pairing_locked' as const) : ('pairing_invalid' as const) };
|
||||
}
|
||||
if (!match) return { ok: false as const, reason: 'pairing_invalid' as const };
|
||||
this.db.prepare('UPDATE pairing_codes SET used_at = ? WHERE id = ?').run(now, match.id);
|
||||
const token = newToken();
|
||||
const device: DeviceRow = {
|
||||
@@ -130,11 +122,21 @@ export class Devices {
|
||||
return { device: this.get(deviceId)!, token };
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke a device. One transaction ends its access, closes its conversation and flags every
|
||||
* turn it still has in flight for cancellation, so nothing the device started keeps running
|
||||
* on its behalf. The flag is in the database, so it also reaches a bridge process that did
|
||||
* not perform the revocation (the operator CLI is a separate process): the turn engine acts
|
||||
* on it by aborting transcription and asking Hermes to stop.
|
||||
*/
|
||||
revoke(deviceId: string): boolean {
|
||||
const now = this.now();
|
||||
return this.db.transaction(() => {
|
||||
const res = this.db.prepare('UPDATE devices SET revoked_at = ? WHERE id = ? AND revoked_at IS NULL').run(now, deviceId);
|
||||
this.db.prepare('UPDATE conversations SET closed_at = ? WHERE device_id = ? AND closed_at IS NULL').run(now, deviceId);
|
||||
this.db
|
||||
.prepare("UPDATE turns SET cancel_requested = 1, updated_at = ? WHERE device_id = ? AND state != 'done' AND cancel_requested = 0")
|
||||
.run(now, deviceId);
|
||||
return res.changes > 0;
|
||||
})();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user