Skip to content

The agent that grows with you

fix(desktop): route profile SOUL tickets

KoNit-K5ccc64c67bc6
diff --git a/apps/desktop/electron/local-gateway.test.ts b/apps/desktop/electron/local-gateway.test.ts
index 78377681967..722d8ef3526 100644
--- a/apps/desktop/electron/local-gateway.test.ts
+++ b/apps/desktop/electron/local-gateway.test.ts
@@ -446,6 +446,15 @@ test('a ?profile= request on the shared host descriptor mints for the sibling pr
expect(() => routedGatewayEndpoint(endpoint, 'http://127.0.0.1:1/x?profile=../evil', path.resolve('hermes-home'))).toThrow('Invalid profile route')
})
+test('a profile SOUL route mints for the profile named in its path', () => {
+ const endpoint = { profile_id: path.resolve('hermes-home'), 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/profiles/p2/soul', path.resolve('hermes-home'))).toMatchObject({
+ profile_id: path.resolve('hermes-home', 'profiles', 'p2'),
+ control_home: path.resolve('hermes-home')
+ })
+})
+
// The batched sidebar names its owner in `recents_profile`; a grant for the window's own profile
// is refused there (profile_scope_mismatch) and the sidebar drops that profile's sessions.
test('a sidebar read mints for the profile its recents_profile names', () => {
diff --git a/apps/desktop/electron/local-gateway.ts b/apps/desktop/electron/local-gateway.ts
index cf3eb963e1a..cc4787be856 100644
--- a/apps/desktop/electron/local-gateway.ts
+++ b/apps/desktop/electron/local-gateway.ts
@@ -347,10 +347,35 @@ function shellQuote(file: string): string {
return `'${file.replace(/'/g, `'\\''`)}'`
}
-/** The batched sidebar names its owner in `recents_profile` (the gateway checks that selector);
- * every other profile-scoped route uses `profile`. */
+// These are collection routes beneath /api/profiles, not profile names. Keep this in step with
+// dashboard_auth.native_http._check_profile_scope: every other first path segment names the
+// profile whose native ticket must be minted.
+const PROFILE_COLLECTION_ROUTES = new Set([
+ 'active', 'import', 'projects', 'sessions'
+])
+
+/** The batched sidebar names its owner in `recents_profile`. A named profile route carries its
+ * owner in the first path segment; all other profile-scoped routes use `profile`. */
function scopedProfileOf(url: URL): null | string {
- return url.searchParams.get(url.pathname.replace(/\/+$/, '') === '/api/profiles/sessions/sidebar' ? 'recents_profile' : 'profile')
+ const pathname = url.pathname.replace(/\/+$/, '')
+
+ if (pathname === '/api/profiles/sessions/sidebar') {
+ return url.searchParams.get('recents_profile')
+ }
+
+ const prefix = '/api/profiles/'
+ const suffix = pathname.startsWith(prefix) ? pathname.slice(prefix.length) : ''
+ const segment = suffix.split('/', 1)[0]
+
+ if (segment && !PROFILE_COLLECTION_ROUTES.has(segment)) {
+ try {
+ return decodeURIComponent(segment)
+ } catch {
+ return null
+ }
+ }
+
+ return url.searchParams.get('profile')
}
/** The endpoint a `?profile=<name>` request is scoped to on a shared host descriptor: the same