From 504d672ba2fc0f43053bef68ee6c0e7169896967 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 8 Jun 2026 18:52:08 -0700 Subject: [PATCH] Map orchestration v2 WS methods to auth scopes - Require operate scope for v2 command dispatch - Allow read scope for v2 thread and shell subscriptions --- apps/server/src/ws.ts | 72 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/apps/server/src/ws.ts b/apps/server/src/ws.ts index 92a4ca2401..c521f5d015 100644 --- a/apps/server/src/ws.ts +++ b/apps/server/src/ws.ts @@ -297,19 +297,65 @@ export function isThreadDetailEvent(event: OrchestrationEvent): event is Extract const PROVIDER_STATUS_DEBOUNCE_MS = 200; -// When a resuming client's cursor is more than this many events behind the -// current head, skip the per-event catch-up replay and send a fresh shell -// snapshot instead. Replaying each intervening event costs a shell refetch; -// past this gap a single O(active-threads) snapshot is cheaper and bounded. -// Matches the event store's default page size (DEFAULT_READ_FROM_SEQUENCE_LIMIT). -const SHELL_RESUME_MAX_GAP = 1_000; - -// Same bound for thread resume. The replay reads the *global* event range and -// filters per-thread afterwards, so a stale cursor far behind the head would -// otherwise decode every intervening event's payload — reconnects with cursors -// hundreds of thousands of events behind have OOM-killed servers on large -// databases. Past this gap the client is reset with a fresh thread snapshot. -const THREAD_RESUME_MAX_GAP = 1_000; +const RPC_REQUIRED_SCOPE = new Map([ + [ORCHESTRATION_WS_METHODS.dispatchCommand, AuthOrchestrationOperateScope], + [ORCHESTRATION_WS_METHODS.getTurnDiff, AuthOrchestrationReadScope], + [ORCHESTRATION_WS_METHODS.getFullThreadDiff, AuthOrchestrationReadScope], + [ORCHESTRATION_WS_METHODS.replayEvents, AuthOrchestrationReadScope], + [ORCHESTRATION_WS_METHODS.subscribeShell, AuthOrchestrationReadScope], + [ORCHESTRATION_WS_METHODS.getArchivedShellSnapshot, AuthOrchestrationReadScope], + [ORCHESTRATION_WS_METHODS.subscribeThread, AuthOrchestrationReadScope], + [ORCHESTRATION_V2_WS_METHODS.dispatchCommand, AuthOrchestrationOperateScope], + [ORCHESTRATION_V2_WS_METHODS.getThreadProjection, AuthOrchestrationReadScope], + [ORCHESTRATION_V2_WS_METHODS.subscribeShell, AuthOrchestrationReadScope], + [ORCHESTRATION_V2_WS_METHODS.subscribeThread, AuthOrchestrationReadScope], + [WS_METHODS.serverGetConfig, AuthOrchestrationReadScope], + [WS_METHODS.serverRefreshProviders, AuthOrchestrationOperateScope], + [WS_METHODS.serverUpdateProvider, AuthOrchestrationOperateScope], + [WS_METHODS.serverUpsertKeybinding, AuthOrchestrationOperateScope], + [WS_METHODS.serverRemoveKeybinding, AuthOrchestrationOperateScope], + [WS_METHODS.serverGetSettings, AuthOrchestrationReadScope], + [WS_METHODS.serverUpdateSettings, AuthOrchestrationOperateScope], + [WS_METHODS.serverDiscoverSourceControl, AuthOrchestrationReadScope], + [WS_METHODS.serverGetTraceDiagnostics, AuthOrchestrationReadScope], + [WS_METHODS.serverGetProcessDiagnostics, AuthOrchestrationReadScope], + [WS_METHODS.serverGetProcessResourceHistory, AuthOrchestrationReadScope], + [WS_METHODS.serverSignalProcess, AuthOrchestrationOperateScope], + [WS_METHODS.cloudGetRelayClientStatus, AuthRelayWriteScope], + [WS_METHODS.cloudInstallRelayClient, AuthRelayWriteScope], + [WS_METHODS.sourceControlLookupRepository, AuthOrchestrationReadScope], + [WS_METHODS.sourceControlCloneRepository, AuthOrchestrationOperateScope], + [WS_METHODS.sourceControlPublishRepository, AuthOrchestrationOperateScope], + [WS_METHODS.projectsSearchEntries, AuthOrchestrationReadScope], + [WS_METHODS.projectsWriteFile, AuthOrchestrationOperateScope], + [WS_METHODS.shellOpenInEditor, AuthOrchestrationOperateScope], + [WS_METHODS.filesystemBrowse, AuthOrchestrationReadScope], + [WS_METHODS.subscribeVcsStatus, AuthOrchestrationReadScope], + [WS_METHODS.vcsRefreshStatus, AuthOrchestrationReadScope], + [WS_METHODS.vcsPull, AuthOrchestrationOperateScope], + [WS_METHODS.gitRunStackedAction, AuthOrchestrationOperateScope], + [WS_METHODS.gitResolvePullRequest, AuthOrchestrationOperateScope], + [WS_METHODS.gitPreparePullRequestThread, AuthOrchestrationOperateScope], + [WS_METHODS.vcsListRefs, AuthOrchestrationReadScope], + [WS_METHODS.vcsCreateWorktree, AuthOrchestrationOperateScope], + [WS_METHODS.vcsRemoveWorktree, AuthOrchestrationOperateScope], + [WS_METHODS.vcsCreateRef, AuthOrchestrationOperateScope], + [WS_METHODS.vcsSwitchRef, AuthOrchestrationOperateScope], + [WS_METHODS.vcsInit, AuthOrchestrationOperateScope], + [WS_METHODS.reviewGetDiffPreview, AuthReviewWriteScope], + [WS_METHODS.terminalOpen, AuthTerminalOperateScope], + [WS_METHODS.terminalAttach, AuthTerminalOperateScope], + [WS_METHODS.terminalWrite, AuthTerminalOperateScope], + [WS_METHODS.terminalResize, AuthTerminalOperateScope], + [WS_METHODS.terminalClear, AuthTerminalOperateScope], + [WS_METHODS.terminalRestart, AuthTerminalOperateScope], + [WS_METHODS.terminalClose, AuthTerminalOperateScope], + [WS_METHODS.subscribeTerminalEvents, AuthTerminalOperateScope], + [WS_METHODS.subscribeTerminalMetadata, AuthTerminalOperateScope], + [WS_METHODS.subscribeServerConfig, AuthOrchestrationReadScope], + [WS_METHODS.subscribeServerLifecycle, AuthOrchestrationReadScope], + [WS_METHODS.subscribeAuthAccess, AuthAccessReadScope], +]); function toAuthAccessStreamEvent( change: PairingGrantStore.BootstrapCredentialChange | SessionStore.SessionCredentialChange,