From d479f2cf65d3fe5272d397eb7ed857196ed12e4f Mon Sep 17 00:00:00 2001 From: Vinh Trinh Date: Thu, 12 Nov 2026 12:42:06 -0800 Subject: [PATCH 1/2] feat(apps): open the apps page that matches the Cloud Desktop signs in to Production Cloud opens https://comfy.org/apps/ and staging Cloud opens the staging-built website preview. A development build still takes COMFY_APPS_URL or a .apps-url file over either. --- src/main/apps/appsView.ts | 2 +- src/main/apps/guards.test.ts | 34 ++++++++++++++++++++++++++++------ src/main/apps/guards.ts | 19 ++++++++++++++++--- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/src/main/apps/appsView.ts b/src/main/apps/appsView.ts index 53d760d7e..9e28ffc6c 100644 --- a/src/main/apps/appsView.ts +++ b/src/main/apps/appsView.ts @@ -43,7 +43,7 @@ import { } from './localComfy' import { localBuilds, openInComfy } from './openInComfy' -const APPS_URL = appsUrl(process.env, app.isPackaged) +const APPS_URL = appsUrl(process.env, app.isPackaged, CLOUD_CONFIG.issuer) const APPS_ORIGIN = appsOrigin(APPS_URL) const APPS_PARTITION = 'persist:comfy-apps' diff --git a/src/main/apps/guards.test.ts b/src/main/apps/guards.test.ts index 9a0b33a2b..916b5642e 100644 --- a/src/main/apps/guards.test.ts +++ b/src/main/apps/guards.test.ts @@ -47,15 +47,37 @@ import { } from './guards' describe('appsUrl', () => { - it('defaults to the hosted site and takes an override in a development build', () => { - expect(appsUrl({}, false)).toBe(DEFAULT_APPS_URL) - expect(appsUrl({ COMFY_APPS_URL: 'http://127.0.0.1:5310/' }, false)).toBe( - 'http://127.0.0.1:5310/' - ) + const prod = 'https://cloud.comfy.org' + const staging = 'https://stagingcloud.comfy.org' + const stagingApps = 'https://comfy-website-preview-pr-384.vercel.app/apps/' + + it('opens the comfy.org apps page for production Cloud', () => { + expect(DEFAULT_APPS_URL).toBe('https://comfy.org/apps/') + expect(appsUrl({}, false, prod)).toBe(DEFAULT_APPS_URL) + expect(appsUrl({}, true, `${prod}/`)).toBe(DEFAULT_APPS_URL) + }) + + it('opens the staging website apps page for staging Cloud, packaged or not', () => { + expect(appsUrl({}, false, staging)).toBe(stagingApps) + expect(appsUrl({}, true, staging)).toBe(stagingApps) + }) + + it('falls back to the comfy.org apps page for any other Cloud', () => { + expect(appsUrl({}, false, 'https://testcloud.comfy.org')).toBe(DEFAULT_APPS_URL) + expect(appsUrl({}, false, 'http://stagingcloud.comfy.org')).toBe(DEFAULT_APPS_URL) + expect(appsUrl({}, false, 'not a url')).toBe(DEFAULT_APPS_URL) + }) + + it('takes an override in a development build over either Cloud', () => { + const env = { COMFY_APPS_URL: 'http://127.0.0.1:5310/' } + expect(appsUrl(env, false, prod)).toBe('http://127.0.0.1:5310/') + expect(appsUrl(env, false, staging)).toBe('http://127.0.0.1:5310/') }) it('ignores the override in a packaged build', () => { - expect(appsUrl({ COMFY_APPS_URL: 'https://evil.example/' }, true)).toBe(DEFAULT_APPS_URL) + const env = { COMFY_APPS_URL: 'https://evil.example/' } + expect(appsUrl(env, true, prod)).toBe(DEFAULT_APPS_URL) + expect(appsUrl(env, true, staging)).toBe(stagingApps) }) }) diff --git a/src/main/apps/guards.ts b/src/main/apps/guards.ts index 1493f60f7..ec9472a26 100644 --- a/src/main/apps/guards.ts +++ b/src/main/apps/guards.ts @@ -1,7 +1,20 @@ -export const DEFAULT_APPS_URL = 'https://apps.comfy.org/' +export const DEFAULT_APPS_URL = 'https://comfy.org/apps/' -export function appsUrl(env: NodeJS.ProcessEnv, packaged: boolean): string { - return (!packaged && env['COMFY_APPS_URL']) || DEFAULT_APPS_URL +const APPS_URL_BY_CLOUD: ReadonlyMap = new Map([ + ['https://cloud.comfy.org', DEFAULT_APPS_URL], + ['https://stagingcloud.comfy.org', 'https://comfy-website-preview-pr-384.vercel.app/apps/'] +]) + +function cloudAppsUrl(issuer: string): string { + try { + return APPS_URL_BY_CLOUD.get(new URL(issuer).origin) ?? DEFAULT_APPS_URL + } catch { + return DEFAULT_APPS_URL + } +} + +export function appsUrl(env: NodeJS.ProcessEnv, packaged: boolean, issuer: string): string { + return (!packaged && env['COMFY_APPS_URL']) || cloudAppsUrl(issuer) } export function appsOrigin(url: string): string | null { From 84ac736449b57c663ccc1843728b6c5bc5f653fa Mon Sep 17 00:00:00 2001 From: Vinh Trinh Date: Thu, 12 Nov 2026 15:24:00 -0800 Subject: [PATCH 2/2] fix(apps): keep the bridge and navigation inside /apps/ on comfy.org The Apps page now lives under /apps/ on the shared comfy.org site, so an origin-only check let any comfy.org page (for example /hub/) stay in the Apps view and call the Desktop bridge. isAppsFrameUrl now takes the Apps URL and requires the same origin and a path at or under its base path; navigation, bridge authorization and local event delivery all use it. A development override at a site root still allows its whole origin. --- src/main/apps/appsView.ts | 14 ++++++-------- src/main/apps/guards.test.ts | 36 +++++++++++++++++++++++++++++++----- src/main/apps/guards.ts | 8 ++++++-- src/main/apps/wiring.test.ts | 6 ++++++ 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/apps/appsView.ts b/src/main/apps/appsView.ts index ca04df492..ab8dcbdaa 100644 --- a/src/main/apps/appsView.ts +++ b/src/main/apps/appsView.ts @@ -107,8 +107,8 @@ function secureAppsSession(): void { securedSession = appsSession } -function keepOnAppsOrigin(event: { preventDefault(): void }, url: string): void { - if (isAppsFrameUrl(url, APPS_ORIGIN)) return +function keepInApps(event: { preventDefault(): void }, url: string): void { + if (isAppsFrameUrl(url, APPS_URL)) return event.preventDefault() openOutside(url) } @@ -126,9 +126,9 @@ function createAppsView(key: number): WebContentsView { }) view.setBorderRadius(14) const wc = view.webContents - wc.on('will-navigate', keepOnAppsOrigin) + wc.on('will-navigate', keepInApps) wc.on('will-redirect', (event, url, _isInPlace, isMainFrame) => { - if (isMainFrame) keepOnAppsOrigin(event, url) + if (isMainFrame) keepInApps(event, url) }) wc.setWindowOpenHandler(({ url }) => { openOutside(url) @@ -203,9 +203,7 @@ function hideApps(event: IpcMainEvent): void { function fromAppsPage(event: IpcMainInvokeEvent): boolean { const ours = [...views.values()].some((v) => v.webContents === event.sender) const frame = event.senderFrame - return ( - ours && !!frame && frame === event.sender.mainFrame && isAppsFrameUrl(frame.url, APPS_ORIGIN) - ) + return ours && !!frame && frame === event.sender.mainFrame && isAppsFrameUrl(frame.url, APPS_URL) } function authState(): AppsAuthState { @@ -501,7 +499,7 @@ function handleFromApps( function appsPages(): WebContents[] { return [...views.values()] .map((v) => v.webContents) - .filter((wc) => !wc.isDestroyed() && isAppsFrameUrl(wc.getURL(), APPS_ORIGIN)) + .filter((wc) => !wc.isDestroyed() && isAppsFrameUrl(wc.getURL(), APPS_URL)) } export function registerAppsIpc(): void { diff --git a/src/main/apps/guards.test.ts b/src/main/apps/guards.test.ts index 448ee1a28..ac529da2b 100644 --- a/src/main/apps/guards.test.ts +++ b/src/main/apps/guards.test.ts @@ -122,11 +122,37 @@ describe('isAllowedAppsPermission', () => { describe('isAppsFrameUrl', () => { it('matches the exact origin', () => { - const origin = 'https://apps.comfy.org' - expect(isAppsFrameUrl('https://apps.comfy.org/upscale', origin)).toBe(true) - expect(isAppsFrameUrl('https://apps.comfy.org.evil.com/', origin)).toBe(false) - expect(isAppsFrameUrl('https://evil.com/?https://apps.comfy.org', origin)).toBe(false) - expect(isAppsFrameUrl('https://apps.comfy.org/', null)).toBe(false) + const apps = 'https://apps.comfy.org/' + expect(isAppsFrameUrl('https://apps.comfy.org/upscale', apps)).toBe(true) + expect(isAppsFrameUrl('https://apps.comfy.org.evil.com/', apps)).toBe(false) + expect(isAppsFrameUrl('https://evil.com/?https://apps.comfy.org', apps)).toBe(false) + expect(isAppsFrameUrl('http://apps.comfy.org/', 'http://apps.comfy.org/')).toBe(false) + expect(isAppsFrameUrl('https://apps.comfy.org/', 'not a url')).toBe(false) + }) + + it.each([DEFAULT_APPS_URL, 'https://comfy-website-preview-pr-384.vercel.app/apps/'])( + 'keeps %s to its apps pages', + (apps) => { + const site = new URL(apps).origin + expect(isAppsFrameUrl(`${site}/apps/`, apps)).toBe(true) + expect(isAppsFrameUrl(`${site}/apps`, apps)).toBe(true) + expect(isAppsFrameUrl(`${site}/apps/some-app`, apps)).toBe(true) + expect(isAppsFrameUrl(`${site}/apps/text-to-image/desktop.html#/run`, apps)).toBe(true) + expect(isAppsFrameUrl(`${site}/hub/`, apps)).toBe(false) + expect(isAppsFrameUrl(`${site}/`, apps)).toBe(false) + expect(isAppsFrameUrl(`${site}/appsfoo`, apps)).toBe(false) + expect(isAppsFrameUrl(`${site}/apps-evil/`, apps)).toBe(false) + expect(isAppsFrameUrl(`${site}/apps/../hub/`, apps)).toBe(false) + expect(isAppsFrameUrl(`${site}/apps/%2e%2e/hub/`, apps)).toBe(false) + expect(isAppsFrameUrl(`${site}/hub/?next=/apps/`, apps)).toBe(false) + } + ) + + it('lets a development site at its root use the whole origin', () => { + const apps = 'http://localhost:5173/' + expect(isAppsFrameUrl('http://localhost:5173/', apps)).toBe(true) + expect(isAppsFrameUrl('http://localhost:5173/some-app/desktop.html', apps)).toBe(true) + expect(isAppsFrameUrl('http://localhost:5174/', apps)).toBe(false) }) }) diff --git a/src/main/apps/guards.ts b/src/main/apps/guards.ts index 58a3eadf5..4776ad853 100644 --- a/src/main/apps/guards.ts +++ b/src/main/apps/guards.ts @@ -38,10 +38,14 @@ export function isAllowedAppsPermission(permission: string): boolean { return ALLOWED_APPS_PERMISSIONS.has(permission) } -export function isAppsFrameUrl(frameUrl: string, origin: string | null): boolean { +export function isAppsFrameUrl(frameUrl: string, appsPage: string): boolean { + const origin = appsOrigin(appsPage) if (!origin) return false try { - return new URL(frameUrl).origin === origin + const frame = new URL(frameUrl) + const base = new URL(appsPage).pathname.replace(/\/+$/, '') + if (frame.origin !== origin) return false + return frame.pathname === base || frame.pathname.startsWith(`${base}/`) } catch { return false } diff --git a/src/main/apps/wiring.test.ts b/src/main/apps/wiring.test.ts index a81fad95b..5a3cc129d 100644 --- a/src/main/apps/wiring.test.ts +++ b/src/main/apps/wiring.test.ts @@ -43,6 +43,12 @@ describe('Apps bridge wiring', () => { expect(main).not.toMatch(/ipcMain\.handle\('comfy-apps:/) }) + it('every apps-page check is held to the Apps URL path, not just its origin', () => { + const checks = all(main, /isAppsFrameUrl\([^,]+, (\w+)\)/g) + expect(checks).toHaveLength(3) + expect(new Set(checks)).toEqual(new Set(['APPS_URL'])) + }) + it('local events go out on the channel the preload listens to', () => { const sent = local.match(/LOCAL_EVENT_CHANNEL = '([\w:-]+)'/)![1] expect(preload).toContain(`ipcRenderer.on('${sent}'`)