Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,19 @@ export interface ComfyDesktop2LogsBridge {
openPopout(): Promise<void>
onOutput(callback: (msg: LogsOutputMsg) => void): () => void
}
export type ComfyDesktop2ProactiveGreetingAdmission = 'allowed' | 'denied' | 'verify-firebase'
export interface ComfyDesktop2TelemetryBridge {
/** Supports validated user/workspace attribution for the proactive greeting experiment. */
readonly proactiveGreetingExperimentVersion?: 1 | 2
/** Current analytics eligibility. Pass Firebase proof only in response to verify-firebase. */
getProactiveGreetingAdmission?(
userId: string,
firebaseIdToken?: string
): Promise<ComfyDesktop2ProactiveGreetingAdmission>
/** Acknowledges local handoff to analytics, including a previously admitted pair and arm. */
enrollProactiveGreeting?(properties: ComfyDesktop2TelemetryProperties): Promise<boolean>
/** Signals that the hosted view should recheck its current actor's eligibility. */
onProactiveGreetingAdmissionChanged?(callback: () => void): () => void
capture(event: string, properties?: ComfyDesktop2TelemetryProperties): void
/** Capture a hosted-frontend exception through Desktop's privacy and release-context boundary. */
captureException?(error: ComfyDesktop2Error, properties?: ComfyDesktop2TelemetryProperties): void
Expand Down
2 changes: 1 addition & 1 deletion packages/comfyui-desktop-bridge-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@comfyorg/comfyui-desktop-bridge-types",
"version": "0.6.0",
"version": "0.7.0",
"description": "TypeScript definitions for the Comfy Desktop hosted frontend bridge",
"type": "module",
"main": "./index.js",
Expand Down
3 changes: 3 additions & 0 deletions src/main/host/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export function attachInstall(entry: ComfyWindowEntry, opts: AttachInstallOpts):
// truth for `getEntryByInstallationId(id)` — keep it in lockstep
// with `entry.installationId` (detach symmetrically clears both).
entry.installationId = installationId
entry.sourceId = installation.sourceId
entry.comfyUrl = comfyUrl
entry.titleBarText = installation.name
entry.sourceCategory = sourceMap[installation.sourceId]?.category ?? null
Expand Down Expand Up @@ -214,6 +215,7 @@ export function attachInstall(entry: ComfyWindowEntry, opts: AttachInstallOpts):
// release-cache resolves in the background).
const onInstallationUpdated = (updated: InstallationRecord): void => {
if (updated.id !== entry.installationId) return
entry.sourceId = updated.sourceId
const nextTabText = updated.name
if (nextTabText !== entry.titleBarText) {
entry.titleBarText = nextTabText
Expand Down Expand Up @@ -704,6 +706,7 @@ export function attachInstall(entry: ComfyWindowEntry, opts: AttachInstallOpts):
entry.installationId = null
}
entry.comfyUrl = ''
delete entry.sourceId
}
return true
}
2 changes: 2 additions & 0 deletions src/main/host/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ export interface ComfyWindowEntry {
* `_installCleanup` clears it — that invariant is what makes attachInstall's
* already-attached guard work. */
installationId: string | null
/** Source of the attached installation, never the chooser's preview. */
sourceId?: string
/** Partition the comfyView was constructed with (pinned; Electron can't
* change it without rebuilding). A chooser-pick claim must reject any install
* whose partition differs, else session data leaks across partition buckets. */
Expand Down
28 changes: 28 additions & 0 deletions src/main/lib/firebaseAuthIdentity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
bindMainVerifiedFirebaseUser,
deactivateFirebaseAuthReporter,
getFirebaseIdentityConsensus,
getUnverifiedLocalFirebaseSignInReport,
observeFirebaseIdentityConsensus,
PENDING_CONSENSUS_DEADLINE_MS,
reportFirebaseAuthState as recordFirebaseAuthState,
Expand Down Expand Up @@ -204,6 +205,33 @@ describe('firebaseAuthIdentity consensus', () => {
verifiedLocalPersistence.succeeds = true
})

it('keeps unverified Local reports out of consensus and expires them on sign-out or navigation', () => {
const local = new FakeWebContents('http://127.0.0.1:8188/')
const contents = local.asWebContents()
const signedIn = { status: 'signed_in', userId: 'F' } as const
activate(local)
reportFirebaseAuthState(contents, signedIn)
const initialReport = getUnverifiedLocalFirebaseSignInReport(contents)!
expect(initialReport.userId).toBe('F')
expect(viewsReportingFirebaseUser('F')).toEqual([])
expect(telemetry.applyFirebaseUserConsensus).not.toHaveBeenCalled()

reportFirebaseAuthState(contents, { status: 'signed_out' })
expect(getUnverifiedLocalFirebaseSignInReport(contents)).toBeNull()
reportFirebaseAuthState(contents, signedIn)
const currentReport = getUnverifiedLocalFirebaseSignInReport(contents)!
expect(currentReport).not.toBe(initialReport)

local.navigate(local.getURL())
expect(getUnverifiedLocalFirebaseSignInReport(contents)).toBeNull()
reportFirebaseAuthState(contents, signedIn)
expect(getUnverifiedLocalFirebaseSignInReport(contents)).not.toBe(currentReport)
expect(viewsReportingFirebaseUser('F')).toEqual([])
expect(telemetry.applyFirebaseUserConsensus).not.toHaveBeenCalled()
expect(telemetry.bindUserId).not.toHaveBeenCalled()
expect(verifiedLocalUsers.size).toBe(0)
})

it('waits for every live trusted reporter before binding one agreed user', () => {
const first = new FakeWebContents(cloudUrl)
const second = new FakeWebContents(cloudUrl)
Expand Down
40 changes: 40 additions & 0 deletions src/main/lib/firebaseAuthIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {
readVerifiedLocalFirebaseUser
} from './verifiedLocalFirebaseAuth'

interface LocalFirebaseSignInReport {
readonly userId: string
readonly origin: string
}

interface Reporter {
eligible: boolean
active: boolean
Expand All @@ -18,6 +23,7 @@ interface Reporter {
pendingExpired: boolean
localReportingAuthorized: boolean
localExpectedUserId: string | null
localSignInReport: LocalFirebaseSignInReport | null
/** Where this view was last seen signed in; storage is per origin, and a view can navigate. */
signedInOrigin: string | null
awaitingCommittedFrame: boolean
Expand Down Expand Up @@ -254,6 +260,24 @@ function currentMainFrame(webContents: WebContents): FirebaseAuthFrameIdentity {
}
}

/** A current report is only a candidate for verification, never proof of identity. */
export function getUnverifiedLocalFirebaseSignInReport(
webContents: WebContents
): LocalFirebaseSignInReport | null {
const reporter = reporters.get(webContents)
if (!reporter?.eligible || reporter.localReportingAuthorized || webContents.isDestroyed()) {
return null
}
const report = reporter.localSignInReport
return report &&
report.origin === originOf(webContents.getURL()) &&
!reporter.awaitingCommittedFrame &&
reporter.mainFrameNavigationsInFlight === 0 &&
isSameFrame(reporter.committedFrame, currentMainFrame(webContents))
? report
: null
}

function failureTerminalKey(
errorCode: number,
validatedURL: string,
Expand Down Expand Up @@ -610,6 +634,7 @@ export function trackFirebaseAuthReporter(webContents: WebContents): void {
pendingExpired: false,
localReportingAuthorized: false,
localExpectedUserId: null,
localSignInReport: null,
signedInOrigin: null,
awaitingCommittedFrame: true,
mainFrameNavigationsInFlight: 0,
Expand All @@ -620,6 +645,7 @@ export function trackFirebaseAuthReporter(webContents: WebContents): void {
state: { status: 'pending' },
onDidStartNavigation: (details) => {
if (!details.isMainFrame || details.isSameDocument) return
reporter.localSignInReport = null
if (
reporter.mainFrameNavigationsInFlight === 0 &&
!reporter.awaitingCommittedFrame &&
Expand Down Expand Up @@ -745,6 +771,7 @@ export function activateFirebaseAuthReporter(webContents: WebContents): void {
reporter.pendingExpired = false
reporter.awaitingCommittedFrame = true
reporter.committedFrame = null
reporter.localSignInReport = null
reporter.recoverableState = null
reporter.committedCandidate = null
reporter.active = refreshReporterAuthScope(reporter, webContents.getURL())
Expand All @@ -758,6 +785,7 @@ export function deactivateFirebaseAuthReporter(webContents: WebContents): void {
if (!reporter) return
reporter.eligible = false
reporter.active = false
reporter.localSignInReport = null
reporter.state = { status: 'pending' }
mainVerifiedStates.delete(webContents)
reconcile()
Expand All @@ -773,6 +801,18 @@ export function reportFirebaseAuthState(
const reporter = reporters.get(webContents)
if (!reporter?.eligible) return
const currentOrigin = originOf(webContents.getURL())
if (
currentOrigin !== null &&
isLoopbackOrigin(currentOrigin) &&
!reporter.awaitingCommittedFrame &&
reporter.mainFrameNavigationsInFlight === 0 &&
isSameFrame(reporter.committedFrame, frame)
) {
if (state.status !== 'signed_in') reporter.localSignInReport = null
else if (reporter.localSignInReport?.userId !== state.userId) {
reporter.localSignInReport = { userId: state.userId, origin: currentOrigin }
}
}
const trustedCloud = isTrustedCloudUrl(webContents.getURL())
const trustedLocal =
currentOrigin !== null && isLoopbackOrigin(currentOrigin) && reporter.localReportingAuthorized
Expand Down
Loading
Loading