Skip to content
Closed
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
4 changes: 2 additions & 2 deletions apps/desktop/src/main/activation-queue.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DeepLink } from './deeplink.js'

export type JoinActivation = Extract<DeepLink, { kind: 'join' }>
export type ActivationResult = 'handled' | 'defer'
type JoinActivation = Extract<DeepLink, { kind: 'join' }>
type ActivationResult = 'handled' | 'defer'

const MAX_PENDING = 32

Expand Down
7 changes: 3 additions & 4 deletions apps/desktop/src/main/client-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CLIENT_HOST, CLIENT_IPC, CLIENT_ORIGIN, CLIENT_SCHEME, CLIENT_URL, type
import { businessUrl, parsePrivateOrigin } from './business-url.js'
import type { Access, Inspect } from './control-types.js'
import { runControl } from './control-client.js'
import { MAX_HTTP_BODY, MAX_LAN_FRAME, MAX_LAN_LINE } from './limits.js'
import WebSocket from 'ws'

export const CLIENT_SCHEME_DESCRIPTOR = {
Expand All @@ -32,9 +33,7 @@ export type ClientHostOptions = {

const DEVICE_ID = /^[a-f0-9]{64}$/
const HEX_TOKEN = /^[a-f0-9]{64}$/
const MAX_HTTP_BODY = 1024 * 1024
const MAX_WS_MESSAGE = 65535
const MAX_LAN_FRAME = 1024 * 1024
const MAX_QUEUED_FRAMES = 16
const MAX_LAN_ADDRESSES = 16
const MIME = new Map<string, string>([
Expand Down Expand Up @@ -365,7 +364,7 @@ class CoreLanBridge implements FrameCarrier {
}

private onLine(line: string): void {
if (line.length > 1_500_000) { this.fail(new Error('LAN bridge response too large')); return }
if (line.length > MAX_LAN_LINE) { this.fail(new Error('LAN bridge response too large')); return }
let value: unknown
try { value = JSON.parse(line) } catch { this.fail(new Error('Invalid LAN bridge response')); return }
if (!isRecord(value) || typeof value.type !== 'string') { this.fail(new Error('Invalid LAN bridge response')); return }
Expand Down Expand Up @@ -410,7 +409,7 @@ class CoreLanBridge implements FrameCarrier {
private write(value: Record<string, unknown>): Promise<void> {
if (this.closed) return Promise.reject(this.failure ?? new Error('LAN stream closed'))
const line = `${JSON.stringify(value)}\n`
if (Buffer.byteLength(line) > Math.ceil(MAX_LAN_FRAME * 4 / 3) + 4096) return Promise.reject(new Error('LAN frame too large'))
if (Buffer.byteLength(line) > MAX_LAN_LINE) return Promise.reject(new Error('LAN frame too large'))
return new Promise((resolveWrite, rejectWrite) => {
this.child.stdin.write(line, error => error ? rejectWrite(error) : resolveWrite())
})
Expand Down
9 changes: 9 additions & 0 deletions apps/desktop/src/main/limits.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/** Match `vibeface_control::MAX_CONTROL_PACKET`. */
export const MAX_CONTROL_PACKET = 1024 * 1024

/** Match `vibeface_secure_ffi::lan::MAX_FRAME_BYTES`. */
export const MAX_LAN_FRAME = 1024 * 1024

/** Local HTTP proxy bodies fail closed at the same 1 MiB cap as control packets. */
export const MAX_HTTP_BODY = MAX_CONTROL_PACKET

/** Base64 JSON line wrapping a LAN frame, matching Core `MAX_LINE_BYTES`. */
export const MAX_LAN_LINE = Math.ceil(MAX_LAN_FRAME * 4 / 3) + 4096
19 changes: 19 additions & 0 deletions apps/desktop/tests/client-host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Duplex } from 'node:stream'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { CLIENT_IPC, CLIENT_ORIGIN, CLIENT_URL } from '../src/shared/client-contract.js'
import type { Inspect } from '../src/main/control-types.js'
import { MAX_HTTP_BODY } from '../src/main/limits.js'

const mocks = vi.hoisted(() => ({
handlers: new Map<string, (event: unknown, ...args: unknown[]) => unknown>(),
Expand Down Expand Up @@ -210,6 +211,24 @@ describe('Desktop client host', () => {
host.dispose()
})

it('rejects a local Node HTTP body that exceeds the shared size cap', async () => {
const fixture = await localFixture((request, response) => {
if (request.path === '/api/local/exchange') {
response.writeHead(200, { 'content-type': 'application/json' })
response.end('x'.repeat(MAX_HTTP_BODY + 1))
} else json(response, 404, {})
})
const window = contents()
const host = createClientHost({
runtimeRoot: '/unused', getClientContents: () => window.value as never, resolveSelectedNode: async () => inspected(fixture.origin),
showNodePanel: () => {}, clientBridgeProgram: () => '/unused/core',
})
host.installIpc()
const call = trustedEvent(window.value, window.frame)
await expect(invoke(CLIENT_IPC.localEntry, call, clientId, { token: localToken, deviceId: nodeId, rejoin: false })).rejects.toThrow('Local response too large')
host.dispose()
})

it('uses the selected local Node normal gateway channel for bootstrap with one fixed connect frame and no cookie', async () => {
let connectFrames = 0
const fixture = await localFixture((_request, response) => json(response, 404, {}))
Expand Down