Skip to content

The agent that grows with you

fix(desktop): profiles with a supported home mode (0755/0750/0701) attach again

Teknium10acccd78de1
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index b22baf4712c..11c39627d59 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -299,6 +299,42 @@ test.skipIf(process.platform === 'win32')('a group-accessible control socket is
}
})
+// R7: the profile home keeps the operator's mode (Python `home_mode_unsafe`: HERMES_HOME_MODE
+// 0750/0701, a 0755 home); only write by another user can swap the socket. The socket stays 0600.
+test.skipIf(process.platform === 'win32')('a supported home mode mints its ticket; a home others can write is refused', async () => {
+ const fs = await import('node:fs/promises')
+ const os = await import('node:os')
+ const path = await import('node:path')
+ const net = await import('node:net')
+ const { mintLocalGatewayTicket } = await import('./local-gateway')
+ const home = await fs.realpath(await fs.mkdtemp(path.join(os.tmpdir(), 'desktop-home-mode-')))
+ const socketPath = path.join(home, 'gateway.sock')
+ const endpoint = { profile_id: home, instance_id: 'owner', authority_epoch: 1, runtime_protocol: 1, api_origin: 'http://127.0.0.1:1234', capabilities: ['session-authority-v1'], supervisor: 'none' }
+
+ const server = net.createServer(socket => socket.once('data', () => {
+ socket.end(JSON.stringify({ protocol: 1, id: 1, ok: true, result: { profile_id: home, instance_id: 'owner', ticket: 'grant' } }) + '\n')
+ }))
+
+ await new Promise<void>(resolve => server.listen(socketPath, resolve))
+ await fs.chmod(socketPath, 0o600)
+
+ try {
+ for (const mode of [0o700, 0o755, 0o750, 0o701]) {
+ await fs.chmod(home, mode)
+ expect(await mintLocalGatewayTicket(endpoint)).toBe('grant')
+ }
+
+ for (const mode of [0o757, 0o703]) {
+ await fs.chmod(home, mode)
+ await expect(mintLocalGatewayTicket(endpoint)).rejects.toThrow('Unsafe gateway control path')
+ }
+ } finally {
+ await fs.chmod(home, 0o700)
+ await new Promise<void>(resolve => server.close(() => resolve()))
+ await fs.rm(home, { recursive: true, force: true })
+ }
+})
+
test('a ?profile= request on the shared host descriptor mints for the sibling profile home', () => {
const endpoint = { profile_id: '/h/.hermes', instance_id: 'i', authority_epoch: 1, runtime_protocol: 1, api_origin: 'http://127.0.0.1:1', capabilities: [], supervisor: 'none', control_home: null }
expect(routedGatewayEndpoint(endpoint, 'http://127.0.0.1:1/api/sessions?profile=p2', '/h/.hermes')).toMatchObject({ profile_id: '/h/.hermes/profiles/p2', control_home: '/h/.hermes' })
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index db698570f5c..4fc657956cb 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -241,11 +241,16 @@ export function createLocalGatewayDials() {
}
}
-async function privateNode(file: string, kind: 'directory' | 'socket' | 'file') {
+// A profile home keeps the operator's mode (Python `home_mode_unsafe`: HERMES_HOME_MODE 0750/0701,
+// a 0755 home): read/search bits grant nothing against the 0600 socket; only write by another user
+// could swap it. Python admits group-write solely for a proven-private group without an ACL, which
+// Node cannot establish (no xattrs/NSS), so it is refused here, as Python treats the unprovable.
+// The socket, pointer and fallback directory stay owner-only.
+async function privateNode(file: string, kind: 'directory' | 'socket' | 'file' | 'home') {
const node = await fs.lstat(file)
- const valid = { directory: node.isDirectory(), socket: node.isSocket(), file: node.isFile() }[kind]
+ const valid = { directory: node.isDirectory(), home: node.isDirectory(), socket: node.isSocket(), file: node.isFile() }[kind]
- if (!valid || node.uid !== process.getuid?.() || (node.mode & 0o077)) {throw new Error('Unsafe gateway control path')}
+ if (!valid || node.uid !== process.getuid?.() || (node.mode & (kind === 'home' ? 0o022 : 0o077))) {throw new Error('Unsafe gateway control path')}
}
/** The endpoint a `?profile=<name>` request is scoped to on a shared host descriptor: the same
@@ -322,7 +327,7 @@ export async function mintLocalGatewayTicket(endpoint: GatewayEndpoint, purpose:
for (const dir of new Set([home, controlHome])) {
if (await fs.realpath(dir) !== dir) {throw new Error('Noncanonical gateway profile')}
- await privateNode(dir, 'directory')
+ await privateNode(dir, 'home')
}
let socketPath: string