Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: address remaining desktop deep-link review feedback
Josuéc9fbd44c329c
diff --git a/desktop-app/package-lock.json b/desktop-app/package-lock.jsonindex f344dc192..9597b8544 100644--- a/desktop-app/package-lock.json+++ b/desktop-app/package-lock.json@@ -1,12 +1,12 @@{"name": "evenfire",- "version": "0.1.322",+ "version": "0.1.323","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "evenfire",- "version": "0.1.322",+ "version": "0.1.323","license": "MPL-2.0","dependencies": {"@tanstack/react-query": "5.100.10",diff --git a/desktop-app/package.json b/desktop-app/package.jsonindex 19b999f75..f07aa132d 100644--- a/desktop-app/package.json+++ b/desktop-app/package.json@@ -1,7 +1,7 @@{"name": "evenfire","productName": "Evenfire",- "version": "0.1.322",+ "version": "0.1.323","private": true,"license": "MPL-2.0","description": "Evenfire desktop client for secure agent and workflow access",diff --git a/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts b/desktop-app/src/__tests__/sandboxUiDeepLinks.test.tsindex b87e09a4a..4f854f810 100644--- a/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts+++ b/desktop-app/src/__tests__/sandboxUiDeepLinks.test.ts@@ -4,6 +4,7 @@ import {buildSandboxUiWebLink,extractSandboxUiViewRoute,parseSandboxUiDeepLink,+ sandboxUiDeepLinkTargetsEqual,} from '../sandboxUiDeepLinks.js'describe('sandbox UI deep links', () => {@@ -89,4 +90,23 @@ describe('sandbox UI deep links', () => {})).toBeNull()})++ it('compares parsed targets instead of raw query parameter order', () => {+ const first = parseSandboxUiDeepLink(+ 'evenfire://app/sandbox-recipes/agentic-task-board?path=%2Ftasks&team=team-123'+ )+ const reordered = parseSandboxUiDeepLink(+ 'evenfire://app/sandbox-recipes/agentic-task-board?team=team-123&path=%2Ftasks'+ )++ expect(first).not.toBeNull()+ expect(reordered).not.toBeNull()+ expect(sandboxUiDeepLinkTargetsEqual(first!, reordered!)).toBe(true)+ expect(+ sandboxUiDeepLinkTargetsEqual(first!, {+ ...reordered!,+ path: '/different',+ })+ ).toBe(false)+ })})diff --git a/desktop-app/src/main.ts b/desktop-app/src/main.tsindex 63ae08007..83b534a44 100644--- a/desktop-app/src/main.ts+++ b/desktop-app/src/main.ts@@ -5,7 +5,11 @@ import { config } from './config.js'import { assertTrustedSender, registerIpcHandlers } from './ipc.js'import { createMainWindowCoordinator } from './mainWindowCoordinator.js'import { collectInitialProtocolUrls } from './protocolLaunchArgs.js'-import { type SandboxUiDeepLinkEnvelope, parseSandboxUiDeepLink } from './sandboxUiDeepLinks.js'+import {+ type SandboxUiDeepLinkEnvelope,+ parseSandboxUiDeepLink,+ sandboxUiDeepLinkTargetsEqual,+} from './sandboxUiDeepLinks.js'import { installAdaptiveSystemIcon, resolveSystemIconPath } from './systemIcon.js'const EVENFIRE_APP_NAME = 'Evenfire'@@ -24,7 +28,6 @@ const appService = new AppService()const pendingEvenfireUrls: string[] = []const pendingSandboxUiDeepLinks: SandboxUiDeepLinkEnvelope[] = []let sandboxUiDeepLinkSequence = 0-let lastSandboxUiDeepLink: { rawUrl: string; receivedAt: number } | null = nulllet mainWindowLifecycleReady = falsefunction systemIconAssetsDirectory(): string {@@ -132,12 +135,13 @@ function handleSandboxUiDeepLink(rawUrl: string): boolean {const target = parseSandboxUiDeepLink(rawUrl)if (!target) return false- const now = Date.now()- if (lastSandboxUiDeepLink?.rawUrl === rawUrl && now - lastSandboxUiDeepLink.receivedAt < 1_000) {+ // Coalesce only while the same semantic target is awaiting renderer+ // acknowledgement. Query-parameter order cannot bypass this check, and once+ // acknowledged, an immediate user re-click creates a fresh envelope.+ if (pendingSandboxUiDeepLinks.some(pending => sandboxUiDeepLinkTargetsEqual(pending, target))) {requestMainWindow()return true}- lastSandboxUiDeepLink = { rawUrl, receivedAt: now }const envelope: SandboxUiDeepLinkEnvelope = {id: (sandboxUiDeepLinkSequence += 1),diff --git a/desktop-app/src/sandboxUiDeepLinks.ts b/desktop-app/src/sandboxUiDeepLinks.tsindex 096f1510c..1761c80d7 100644--- a/desktop-app/src/sandboxUiDeepLinks.ts+++ b/desktop-app/src/sandboxUiDeepLinks.ts@@ -140,6 +140,17 @@ export function parseSandboxUiDeepLink(rawUrl: string): SandboxUiDeepLinkTarget}}+export function sandboxUiDeepLinkTargetsEqual(+ left: SandboxUiDeepLinkTarget,+ right: SandboxUiDeepLinkTarget+): boolean {+ return (+ left.appRef === right.appRef &&+ left.path === right.path &&+ (left.teamId || '') === (right.teamId || '')+ )+}+export function extractSandboxUiViewRoute(input: SandboxUiViewRouteInput): string | null {let current: URLlet proxy: URLdiff --git a/profile-ui/app/constants/routes.ts b/profile-ui/app/constants/routes.tsindex e65874d77..5f5eb9dca 100644--- a/profile-ui/app/constants/routes.ts+++ b/profile-ui/app/constants/routes.ts@@ -25,8 +25,6 @@ export const PROFILE_ROUTES = {desktopSetup: '/desktop-setup',forgotPassword: (query?: ProfileRouteQuery) => withQuery('/forgot-password', query),invitation: (token: string) => `/invitations/${segment(token)}`,- openDesktopApp: (recipeNs: string, recipeName: string, query?: ProfileRouteQuery) =>- withQuery(`/open/apps/${segment(recipeNs)}/${segment(recipeName)}`, query),members: {root: '/members',invite: '/members/invite',diff --git a/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts b/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.tsindex 14711d596..ea50b84da 100644--- a/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts+++ b/profile-ui/app/open/apps/[recipeNs]/[recipeName]/route.ts@@ -1,4 +1,6 @@+import { randomBytes } from 'node:crypto'import {+ buildEvenfireDesktopAppContentSecurityPolicy,buildEvenfireDesktopAppLink,buildEvenfireDesktopAppRedirectDocument,} from '@lib/desktopAppLinks'@@ -28,12 +30,11 @@ export async function GET(})}- return new Response(buildEvenfireDesktopAppRedirectDocument(deepLink), {+ const scriptNonce = randomBytes(18).toString('base64')+ return new Response(buildEvenfireDesktopAppRedirectDocument(deepLink, scriptNonce), {headers: {'Cache-Control': 'no-store',- 'Content-Security-Policy':- "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; base-uri 'none'; " +- "form-action 'none'; frame-ancestors 'none'",+ 'Content-Security-Policy': buildEvenfireDesktopAppContentSecurityPolicy(scriptNonce),'Content-Type': 'text/html; charset=utf-8','Referrer-Policy': 'no-referrer','X-Content-Type-Options': 'nosniff',diff --git a/profile-ui/lib/desktopAppLinks.ts b/profile-ui/lib/desktopAppLinks.tsindex 719eb931c..1247f6ef8 100644--- a/profile-ui/lib/desktopAppLinks.ts+++ b/profile-ui/lib/desktopAppLinks.ts@@ -3,6 +3,7 @@ const TEAM_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._:-]*$/const MAX_APP_SEGMENT_LENGTH = 253const MAX_APP_ROUTE_LENGTH = 4096const MAX_TEAM_ID_LENGTH = 255+const SCRIPT_NONCE_PATTERN = /^[A-Za-z0-9+/_-]+={0,2}$/export function buildEvenfireDesktopAppLink(parts: {recipeNs: string@@ -62,12 +63,32 @@ function desktopAppDisplayName(parsed: URL): string {}}-export function buildEvenfireDesktopAppRedirectDocument(deepLink: string): string {+function normalizeScriptNonce(scriptNonce: string): string {+ const nonce = String(scriptNonce || '').trim()+ if (!nonce || nonce.length > 128 || !SCRIPT_NONCE_PATTERN.test(nonce)) {+ throw new Error('Cannot build a desktop app redirect with an invalid script nonce')+ }+ return nonce+}++export function buildEvenfireDesktopAppContentSecurityPolicy(scriptNonce: string): string {+ const nonce = normalizeScriptNonce(scriptNonce)+ return (+ `default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; ` ++ "base-uri 'none'; form-action 'none'; frame-ancestors 'none'"+ )+}++export function buildEvenfireDesktopAppRedirectDocument(+ deepLink: string,+ scriptNonce: string+): string {const parsed = new URL(deepLink)if (parsed.protocol !== 'evenfire:' || parsed.hostname !== 'app') {throw new Error('Cannot redirect to an invalid desktop app link')}+ const nonce = normalizeScriptNonce(scriptNonce)const escapedLink = escapeHtml(deepLink)const escapedAppName = escapeHtml(desktopAppDisplayName(parsed))const scriptLink = JSON.stringify(deepLink).replaceAll('<', '\\u003c')@@ -179,7 +200,7 @@ export function buildEvenfireDesktopAppRedirectDocument(deepLink: string): strin</p></section></main>- <script>window.location.replace(${scriptLink})</script>+ <script nonce="${escapeHtml(nonce)}">window.location.replace(${scriptLink})</script></body></html>`}diff --git a/profile-ui/package-lock.json b/profile-ui/package-lock.jsonindex 2073f3c55..fe767111f 100644--- a/profile-ui/package-lock.json+++ b/profile-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-profile-ui",- "version": "0.1.106",+ "version": "0.1.107","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-profile-ui",- "version": "0.1.106",+ "version": "0.1.107","dependencies": {"next": "16.2.11","react": "^18.3.1",diff --git a/profile-ui/package.json b/profile-ui/package.jsonindex 9c6d3f381..c848cf6bc 100644--- a/profile-ui/package.json+++ b/profile-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-profile-ui",- "version": "0.1.106",+ "version": "0.1.107","private": true,"scripts": {"dev": "next dev",diff --git a/profile-ui/test/desktopAppLinks.test.ts b/profile-ui/test/desktopAppLinks.test.tsindex 6c0e5bacf..17267016b 100644--- a/profile-ui/test/desktopAppLinks.test.ts+++ b/profile-ui/test/desktopAppLinks.test.ts@@ -1,6 +1,7 @@import assert from 'node:assert/strict'import test from 'node:test'import {+ buildEvenfireDesktopAppContentSecurityPolicy,buildEvenfireDesktopAppLink,buildEvenfireDesktopAppRedirectDocument,} from '../lib/desktopAppLinks'@@ -32,10 +33,12 @@ test('buildEvenfireDesktopAppLink rejects unsafe routes', () => {test('buildEvenfireDesktopAppRedirectDocument creates an unauthenticated protocol handoff', () => {const deepLink ='evenfire://app/sandbox-recipes/agentic-task-board' + '?path=%2Ftasks%2Ftask-42&team=team-123'- const document = buildEvenfireDesktopAppRedirectDocument(deepLink)+ const scriptNonce = 'dGVzdC1ub25jZQ=='+ const document = buildEvenfireDesktopAppRedirectDocument(deepLink, scriptNonce)assert.match(document, /http-equiv="refresh"/)assert.match(document, /window\.location\.replace/)+ assert.match(document, new RegExp(`<script nonce="${scriptNonce}">`))assert.match(document, /evenfire:\/\/app\/sandbox-recipes\/agentic-task-board/)assert.match(document, /<style>/)assert.match(document, /class="page-card"/)@@ -44,9 +47,28 @@ test('buildEvenfireDesktopAppRedirectDocument creates an unauthenticated protocoassert.doesNotMatch(document, /login|authenticate|authorization/i)})+test('buildEvenfireDesktopAppContentSecurityPolicy authorizes only the nonce-bearing script', () => {+ const scriptNonce = 'dGVzdC1ub25jZQ=='+ const policy = buildEvenfireDesktopAppContentSecurityPolicy(scriptNonce)++ assert.match(policy, new RegExp(`script-src 'nonce-${scriptNonce}'`))+ assert.doesNotMatch(policy, /script-src 'unsafe-inline'/)+})+test('buildEvenfireDesktopAppRedirectDocument rejects unrelated protocols', () => {assert.throws(- () => buildEvenfireDesktopAppRedirectDocument('https://example.com/app'),+ () => buildEvenfireDesktopAppRedirectDocument('https://example.com/app', 'dGVzdC1ub25jZQ=='),/invalid desktop app link/)})++test('buildEvenfireDesktopAppRedirectDocument rejects an invalid script nonce', () => {+ assert.throws(+ () =>+ buildEvenfireDesktopAppRedirectDocument(+ 'evenfire://app/sandbox-recipes/agentic-task-board?path=%2F',+ '"><script>alert(1)</script>'+ ),+ /invalid script nonce/+ )+})