Skip to content

The agent that grows with you

fix(desktop): local-profile REST calls carry the descriptor's configured headers like every other path

Tekniumd912406f63df
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index 4b7b0d9ef6a..0a47115ccf2 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -398,3 +398,18 @@ test('a ?profile= request on the shared host descriptor mints for the sibling pr
expect(routedGatewayEndpoint({ ...endpoint, profile_id: '/h/.hermes/profiles/p2', control_home: '/h/.hermes' }, 'http://127.0.0.1:1/x?profile=default', '/h/.hermes')).toMatchObject({ profile_id: '/h/.hermes' })
expect(() => routedGatewayEndpoint(endpoint, 'http://127.0.0.1:1/x?profile=../evil', '/h/.hermes')).toThrow('Invalid profile route')
})
+
+// A native gateway grant is minted only by main's shared transport (fetchJsonForBackend), which
+// also carries the descriptor's configured headers; a call site that hands fetchJson a
+// gatewayDescriptor itself silently drops them. Source guard over the one module that issues them.
+test('main issues native-gateway REST calls only through the shared descriptor transport', async () => {
+ const fs = await import('node:fs/promises')
+ const source = await fs.readFile(new URL('./main.ts', import.meta.url), 'utf8')
+ const transport = source.indexOf('async function fetchJsonForBackend(')
+ const transportEnd = source.indexOf('\n}\n', transport)
+ const outside = source.slice(0, transport) + source.slice(transportEnd)
+
+ expect(transport).toBeGreaterThan(0)
+ expect(source.slice(transport, transportEnd)).toContain('headers: descriptor.headers')
+ expect(outside.match(/fetchJson\([^)]*\{[^}]*gatewayDescriptor\b/g) ?? []).toEqual([])
+})
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index 057f2e5ae6f..6ed79af602b 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -16458,29 +16458,23 @@ async function handleHermesApiRequest(request) {
const timeoutMs = resolveTimeoutMs(request?.timeoutMs, DEFAULT_FETCH_TIMEOUT_MS)
- if (connection.gatewayEndpoint) {
- response = await redialLocalGateway({
- ensure: () => ensureBackend(routeProfile),
- forget: () => forgetLocalGatewayDescriptor(routeProfile),
- use: current => fetchJson(`${current.baseUrl}${apiRoute.requestPath}`, current.token, {
- method: request?.method,
- body: request?.body,
- upload: request?.upload,
- timeoutMs,
- gatewayDescriptor: current
+ // Main's shared transport for every descriptor: configured headers, a native
+ // gateway grant per attempt, and the OAuth bearer→cookie fallback that
+ // survives refresh failures and login races (requestWithOauthFallback).
+ const send = current => fetchJsonForBackend(current, apiRoute.requestPath, {
+ method: request?.method,
+ body: request?.body,
+ upload: request?.upload,
+ timeoutMs
+ })
+
+ response = connection.gatewayEndpoint
+ ? await redialLocalGateway({
+ ensure: () => ensureBackend(routeProfile),
+ forget: () => forgetLocalGatewayDescriptor(routeProfile),
+ use: send
})
- })
- } else {
- // Remote URL / cloud / SSH: main's shared transport — configured remote
- // headers, and the OAuth bearer→cookie fallback that survives refresh
- // failures and login races (requestWithOauthFallback).
- response = await fetchJsonForBackend(connection, apiRoute.requestPath, {
- method: request?.method,
- body: request?.body,
- upload: request?.upload,
- timeoutMs
- })
- }
+ : await send(connection)
} catch (error) {
// A failed rename PATCH must not strand the app on the temporary primary:
// restore the original active profile and restart its backend.