Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix: address deep-link review regressions

Josué53021919b9bf
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.json
index 6b07b5ac8..7767ee58d 100644
--- a/desktop-app/package-lock.json
+++ b/desktop-app/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "evenfire",
- "version": "0.1.330",
+ "version": "0.1.331",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "evenfire",
- "version": "0.1.330",
+ "version": "0.1.331",
"license": "MPL-2.0",
"dependencies": {
"@clerum/desktop-app-links": "file:../packages/desktop-app-links",
diff --git a/desktop-app/package.json b/desktop-app/package.json
index 7441c979c..ffb63dc71 100644
--- a/desktop-app/package.json
+++ b/desktop-app/package.json
@@ -1,7 +1,7 @@
{
"name": "evenfire",
"productName": "Evenfire",
- "version": "0.1.330",
+ "version": "0.1.331",
"private": true,
"license": "MPL-2.0",
"description": "Evenfire desktop client for secure agent and workflow access",
diff --git a/desktop-app/src/__tests__/mainWindowReadiness.test.ts b/desktop-app/src/__tests__/mainWindowReadiness.test.ts
new file mode 100644
index 000000000..821d9a0b3
--- /dev/null
+++ b/desktop-app/src/__tests__/mainWindowReadiness.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from 'vitest'
+import { shouldResetRendererReadinessForNavigation } from '../mainWindowReadiness.js'
+
+describe('main window renderer readiness', () => {
+ it('resets only for main-frame cross-document navigations', () => {
+ expect(
+ shouldResetRendererReadinessForNavigation({
+ isMainFrame: true,
+ isSameDocument: false,
+ })
+ ).toBe(true)
+ expect(
+ shouldResetRendererReadinessForNavigation({
+ isMainFrame: false,
+ isSameDocument: false,
+ })
+ ).toBe(false)
+ expect(
+ shouldResetRendererReadinessForNavigation({
+ isMainFrame: true,
+ isSameDocument: true,
+ })
+ ).toBe(false)
+ })
+})
diff --git a/desktop-app/src/__tests__/protocolLaunchArgs.test.ts b/desktop-app/src/__tests__/protocolLaunchArgs.test.ts
index 830b447b6..3a06fa667 100644
--- a/desktop-app/src/__tests__/protocolLaunchArgs.test.ts
+++ b/desktop-app/src/__tests__/protocolLaunchArgs.test.ts
@@ -29,4 +29,16 @@ describe('collectInitialProtocolUrls', () => {
],
})
})
+
+ it('matches protocol schemes case-insensitively', () => {
+ expect(
+ collectInitialProtocolUrls([
+ 'EVENFIRE://app/sandbox-recipes/task-board?path=%2Ftasks',
+ 'CLERUM://oauth-completed?clientId=github&provider=github',
+ ])
+ ).toEqual({
+ evenfireUrls: ['EVENFIRE://app/sandbox-recipes/task-board?path=%2Ftasks'],
+ clerumUrls: ['CLERUM://oauth-completed?clientId=github&provider=github'],
+ })
+ })
})
diff --git a/desktop-app/src/__tests__/sandboxUiDriver.test.ts b/desktop-app/src/__tests__/sandboxUiDriver.test.ts
index 0523ddc56..be0887764 100644
--- a/desktop-app/src/__tests__/sandboxUiDriver.test.ts
+++ b/desktop-app/src/__tests__/sandboxUiDriver.test.ts
@@ -101,6 +101,39 @@ describe('sandbox UI route normalization', () => {
).toThrow('Cannot read the current app route')
})
+ it('falls back to the default route when the app view has not committed a URL yet', () => {
+ expect(
+ resolveSandboxUiSharePath({
+ currentUrl: '',
+ rpcProxyOrigin: 'https://rpc.example',
+ recipeNs: 'ns',
+ recipeName: 'app',
+ defaultPath: '/tasks',
+ })
+ ).toBeUndefined()
+ })
+
+ it('omits default routes that include query or hash state when sharing', () => {
+ expect(
+ resolveSandboxUiSharePath({
+ currentUrl: 'https://rpc.example/api/v1/sandbox-ui/ns/app/view/#/dashboard',
+ rpcProxyOrigin: 'https://rpc.example',
+ recipeNs: 'ns',
+ recipeName: 'app',
+ defaultPath: '/#/dashboard',
+ })
+ ).toBeUndefined()
+ expect(
+ resolveSandboxUiSharePath({
+ currentUrl: 'https://rpc.example/api/v1/sandbox-ui/ns/app/view/index.php?view=board',
+ rpcProxyOrigin: 'https://rpc.example',
+ recipeNs: 'ns',
+ recipeName: 'app',
+ defaultPath: '/index.php?view=board',
+ })
+ ).toBeUndefined()
+ })
+
it('treats the bare view endpoint and nested routes as the same boundary', () => {
const prefix = 'https://rpc.example/api/v1/sandbox-ui/ns/app/view'
expect(isSandboxUiNavigationWithinPrefix(prefix, prefix)).toBe(true)
@@ -111,6 +144,9 @@ describe('sandbox UI route normalization', () => {
it('uses valid defaults and warns before falling back from an invalid default', () => {
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
expect(resolveSandboxUiDefaultPath('/accounts')).toBe('/accounts')
+ expect(resolveSandboxUiDefaultPath('/#/dashboard')).toBe('/#/dashboard')
+ expect(resolveSandboxUiDefaultPath('/index.php?view=board')).toBe('/index.php?view=board')
+ expect(resolveSandboxUiDefaultPath('/app#/inbox')).toBe('/app#/inbox')
expect(resolveSandboxUiDefaultPath(undefined)).toBe('/')
expect(resolveSandboxUiDefaultPath('/safe/../admin')).toBe('/')
expect(warn).toHaveBeenCalledOnce()
diff --git a/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts b/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts
index 3144309b5..67461da60 100644
--- a/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts
+++ b/desktop-app/src/__tests__/sandboxUiPartitionPolicies.test.ts
@@ -47,6 +47,19 @@ describe('classifyEmbedNavigation', () => {
})
})
+ it('does not allow sibling paths that only share a string prefix', () => {
+ const prefixWithoutSlash = allowed.replace(/\/$/, '')
+ const sibling = `${prefixWithoutSlash}-other/x`
+ expect(classifyEmbedNavigation(sibling, prefixWithoutSlash)).toEqual({
+ kind: 'external',
+ url: sibling,
+ })
+ expect(classifyEmbedNavigation(`${prefixWithoutSlash}x/secret`, prefixWithoutSlash)).toEqual({
+ kind: 'external',
+ url: `${prefixWithoutSlash}x/secret`,
+ })
+ })
+
it('routes a different recipe under the same proxy origin to the OS browser (not allow)', () => {
// Different recipe — the proxy would 401 it anyway via the JWT
// claim binding, but the embed should never even attempt to load
diff --git a/desktop-app/src/main.ts b/desktop-app/src/main.ts
index 4fc77f26b..6165852b9 100644
--- a/desktop-app/src/main.ts
+++ b/desktop-app/src/main.ts
@@ -4,6 +4,7 @@ import { AppService } from './appService.js'
import { config } from './config.js'
import { assertTrustedSender, registerIpcHandlers } from './ipc.js'
import { createMainWindowCoordinator, createRetryableInitializer } from './mainWindowCoordinator.js'
+import { shouldResetRendererReadinessForNavigation } from './mainWindowReadiness.js'
import { collectInitialProtocolUrls } from './protocolLaunchArgs.js'
import { SandboxUiDeepLinkQueue } from './sandboxUiDeepLinkQueue.js'
import {
@@ -35,6 +36,7 @@ let mainWindowRendererReady = false
const appServiceInitializer = createRetryableInitializer(() => appService.initialize())
function enqueuePendingEvenfireUrl(rawUrl: string): void {
+ if (pendingEvenfireUrls.includes(rawUrl)) return
pendingEvenfireUrls.push(rawUrl)
if (pendingEvenfireUrls.length > MAX_PENDING_EVENFIRE_URLS) {
pendingEvenfireUrls.shift()
@@ -298,9 +300,10 @@ if (!gotSingleInstanceLock) {
app.on('open-url', (event, rawUrl) => {
event.preventDefault()
- if (rawUrl.startsWith(`${DESKTOP_SETUP_PROTOCOL}:`)) {
+ const lowerUrl = rawUrl.toLowerCase()
+ if (lowerUrl.startsWith(`${DESKTOP_SETUP_PROTOCOL}:`)) {
handleEvenfireUrl(rawUrl)
- } else if (rawUrl.startsWith(`${CLERUM_PROTOCOL}:`)) {
+ } else if (lowerUrl.startsWith(`${CLERUM_PROTOCOL}:`)) {
handleClerumUrl(rawUrl)
}
})
@@ -340,8 +343,15 @@ async function createWindow(): Promise<void> {
mainWindowRendererReady = false
}
})
- window.webContents.on('did-start-loading', () => {
- if (mainWindow === window) mainWindowRendererReady = false
+ window.webContents.on('did-start-navigation', details => {
+ if (mainWindow === window && shouldResetRendererReadinessForNavigation(details)) {
+ mainWindowRendererReady = false
+ }
+ })
+ window.webContents.on('render-process-gone', () => {
+ if (mainWindow === window) {
+ mainWindowRendererReady = false
+ }
})
wireWindowVisibility(window)
diff --git a/desktop-app/src/mainWindowReadiness.ts b/desktop-app/src/mainWindowReadiness.ts
new file mode 100644
index 000000000..bd8deefe5
--- /dev/null
+++ b/desktop-app/src/mainWindowReadiness.ts
@@ -0,0 +1,10 @@
+export type RendererNavigationReadinessEvent = {
+ isMainFrame: boolean
+ isSameDocument: boolean
+}
+
+export function shouldResetRendererReadinessForNavigation(
+ details: RendererNavigationReadinessEvent
+): boolean {
+ return details.isMainFrame && !details.isSameDocument
+}
diff --git a/desktop-app/src/protocolLaunchArgs.ts b/desktop-app/src/protocolLaunchArgs.ts
index 8f9e6da5b..a9ae8dc1f 100644
--- a/desktop-app/src/protocolLaunchArgs.ts
+++ b/desktop-app/src/protocolLaunchArgs.ts
@@ -6,10 +6,12 @@ export type InitialProtocolUrls = {
}
export function collectInitialProtocolUrls(argv: string[]): InitialProtocolUrls {
+ const hasProtocol = (argument: string, protocol: string) =>
+ argument.slice(0, protocol.length).toLowerCase() === protocol
return {
evenfireUrls: [
- ...new Set(argv.filter(argument => argument.startsWith(SANDBOX_UI_DEEP_LINK_PROTOCOL))),
+ ...new Set(argv.filter(argument => hasProtocol(argument, SANDBOX_UI_DEEP_LINK_PROTOCOL))),
],
- clerumUrls: [...new Set(argv.filter(argument => argument.startsWith(CLERUM_OAUTH_PROTOCOL)))],
+ clerumUrls: [...new Set(argv.filter(argument => hasProtocol(argument, CLERUM_OAUTH_PROTOCOL)))],
}
}
diff --git a/desktop-app/src/sandboxUiDriver.ts b/desktop-app/src/sandboxUiDriver.ts
index 41ace47b6..471ec23fa 100644
--- a/desktop-app/src/sandboxUiDriver.ts
+++ b/desktop-app/src/sandboxUiDriver.ts
@@ -6,6 +6,7 @@ import { touchSandboxUiPartition } from './sandboxUiPartitionGc.js'
import {
applySandboxUiNavigationPolicies,
applySandboxUiPartitionPolicies,
+ isSandboxUiNavigationWithinPrefix as isNavigationWithinPrefix,
} from './sandboxUiPartitionPolicies.js'
/**
@@ -98,10 +99,13 @@ type ActiveView = {
partition: string
parentWindow: BrowserWindow
rpcProxyOrigin: string
+ cleanupClientRouteHandoff?: () => void
}
let active: ActiveView | null = null
+export const isSandboxUiNavigationWithinPrefix = isNavigationWithinPrefix
+
export function getActiveSandboxUi(): {
recipeNs: string
recipeName: string
@@ -145,9 +149,10 @@ export function resolveSandboxUiSharePath(input: {
recipeName: string
defaultPath: string
}): string | undefined {
+ if (!input.currentUrl.trim()) return undefined
const currentPath = extractSandboxUiViewRoute(input)
if (currentPath === null) throw new Error('Cannot read the current app route')
- return currentPath === input.defaultPath ? undefined : currentPath
+ return currentPath === sharedPathForDefaultPath(input.defaultPath) ? undefined : currentPath
}
export function partitionFor(envKey: string, recipeNs: string, recipeName: string): string {
@@ -256,6 +261,7 @@ async function teardownActive(reason: 'replaced' | 'closed' | 'parent_closed'):
const current = active
active = null
try {
+ current.cleanupClientRouteHandoff?.()
// contentView.removeChildView is the documented teardown step; it both
// detaches the view from layout AND severs the parent's ownership ref.
if (!current.parentWindow.isDestroyed()) {
@@ -456,6 +462,9 @@ export async function mountSandboxUiView(args: MountSandboxUiArgs): Promise<void
console.warn('[SandboxUI] client route handoff timed out before the app became ready')
cleanupClientRouteHandoff()
}, CLIENT_ROUTE_HANDOFF_TIMEOUT_MS)
+ if (active && active.view === view) {
+ active.cleanupClientRouteHandoff = cleanupClientRouteHandoff
+ }
}
// Drop the HTTP cache on every open so a stale entry from a prior
// broken pod can't keep painting after the recipe is healthy. The
@@ -497,27 +506,47 @@ export async function applySandboxUiClientRoute(
export function resolveSandboxUiDefaultPath(defaultPath?: string): string {
const rawDefaultPath = String(defaultPath || '').trim()
if (!rawDefaultPath) return '/'
- const normalized = normalizeSandboxUiRoute(rawDefaultPath)
+ const normalized = normalizeSandboxUiDefaultPath(rawDefaultPath)
if (normalized) return normalized
console.warn('[SandboxUI] Invalid recipe defaultPath; falling back to "/":', rawDefaultPath)
return '/'
}
-export function isSandboxUiNavigationWithinPrefix(
- navigationUrl: string,
- allowedNavigationPrefix: string
-): boolean {
- try {
- const navigation = new URL(navigationUrl)
- const allowed = new URL(allowedNavigationPrefix)
- return (
- navigation.origin === allowed.origin &&
- (navigation.pathname === allowed.pathname ||
- navigation.pathname.startsWith(`${allowed.pathname}/`))
- )
- } catch {
- return false
+const DOT_SEGMENT_PATTERN = /^(?:\.|%2e){1,2}$/i
+
+function pathHasDotSegment(pathname: string): boolean {
+ return pathname.split('/').some(segment => DOT_SEGMENT_PATTERN.test(segment))
+}
+
+function sharedPathForDefaultPath(defaultPath: string): string {
+ const firstQueryIndex = defaultPath.indexOf('?')
+ const firstHashIndex = defaultPath.indexOf('#')
+ const firstMetaIndex = [firstQueryIndex, firstHashIndex]
+ .filter(index => index !== -1)
+ .sort((a, b) => a - b)[0]
+ return firstMetaIndex === undefined ? defaultPath : defaultPath.slice(0, firstMetaIndex) || '/'
+}
+
+function normalizeSandboxUiDefaultPath(rawPath: string): string | null {
+ const routePath = String(rawPath || '').trim()
+ if (!routePath) return '/'
+ if (
+ routePath.length > 4096 ||
+ !routePath.startsWith('/') ||
+ routePath.startsWith('//') ||
+ routePath.includes('\\') ||
+ /[\u0000-\u001f\u007f\s]/.test(routePath)
+ ) {
+ return null
+ }
+ const firstHashIndex = routePath.indexOf('#')
+ const serverPath = sharedPathForDefaultPath(routePath)
+ if (pathHasDotSegment(serverPath)) return null
+ if (firstHashIndex !== -1) {
+ const hashRoute = routePath.slice(firstHashIndex + 1).split('?')[0] || ''
+ if (hashRoute.startsWith('/') && pathHasDotSegment(hashRoute)) return null
}
+ return routePath
}
export function canApplySandboxUiClientRoute(input: {
diff --git a/desktop-app/src/sandboxUiPartitionPolicies.ts b/desktop-app/src/sandboxUiPartitionPolicies.ts
index 50ae200b0..fced04788 100644
--- a/desktop-app/src/sandboxUiPartitionPolicies.ts
+++ b/desktop-app/src/sandboxUiPartitionPolicies.ts
@@ -36,6 +36,28 @@ export type EmbedNavigationOutcome =
/** non-http(s) scheme or empty URL — drop silently. */
| { kind: 'drop' }
+function pathWithoutTrailingSlash(pathname: string): string {
+ return pathname.replace(/\/+$/, '') || '/'
+}
+
+export function isSandboxUiNavigationWithinPrefix(
+ navigationUrl: string,
+ allowedNavigationPrefix: string
+): boolean {
+ try {
+ const navigation = new URL(navigationUrl)
+ const allowed = new URL(allowedNavigationPrefix)
+ const allowedPath = pathWithoutTrailingSlash(allowed.pathname)
+ const navigationPath = pathWithoutTrailingSlash(navigation.pathname)
+ return (
+ navigation.origin === allowed.origin &&
+ (navigationPath === allowedPath || navigation.pathname.startsWith(`${allowedPath}/`))
+ )
+ } catch {
+ return false
+ }
+}
+
/**
* Classify a candidate navigation URL against the recipe's allowed
* `view/*` prefix. Pure function — no Electron coupling, easy to test.
@@ -45,11 +67,15 @@ export function classifyEmbedNavigation(
allowedPrefix: string
): EmbedNavigationOutcome {
if (!rawUrl) return { kind: 'drop' }
- if (rawUrl.startsWith(allowedPrefix)) return { kind: 'allow' }
+ if (isSandboxUiNavigationWithinPrefix(rawUrl, allowedPrefix)) return { kind: 'allow' }
if (rawUrl.startsWith('clerum:')) {
const parsed = parseClerumOauthAuthorize(rawUrl)
return parsed
- ? { kind: 'oauth_authorize', oauthClientId: parsed.oauthClientId, background: parsed.background }
+ ? {
+ kind: 'oauth_authorize',
+ oauthClientId: parsed.oauthClientId,
+ background: parsed.background,
+ }
: { kind: 'drop' }
}
if (rawUrl.startsWith('https://') || rawUrl.startsWith('http://')) {
diff --git a/desktop-app/ui/src/lib/__tests__/sandboxUiAppSelection.test.ts b/desktop-app/ui/src/lib/__tests__/sandboxUiAppSelection.test.ts
index 25851970f..93575586f 100644
--- a/desktop-app/ui/src/lib/__tests__/sandboxUiAppSelection.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/sandboxUiAppSelection.test.ts
@@ -12,6 +12,7 @@ const apps = [
defaultPath: '/',
ready: true,
phase: 'Ready',
+ updatedAt: null,
},
{
appRef: 'sandbox-recipes/provisioning-app',
@@ -19,6 +20,7 @@ const apps = [
defaultPath: '/',
ready: false,
phase: 'Installing',
+ updatedAt: null,
},
]