fix(terminal-dev-loop): address branch review findings

Security:
- Reject same-site and cross-site state-changing requests on cookie-authenticated routes unless the origin is trusted
- Drop Manager and ocm_preview Set-Cookie headers from preview responses
- Show and hash the full executable content of .ocm/project.json at trust time
- Restrict action URLs to http(s) and refuse symlinked repo config paths
- Keep the preview start redirect on the gateway origin

Lifecycle:
- Stop terminals in OpenCode workspace siblings when a repo is deleted
- Report preview as unavailable instead of crashing when the gateway port cannot be bound

Performance:
- Skip branch lookups when validating terminal and project-config directories
- Stop the /proc scan once all listening sockets are mapped and pause port polling while a preview is open
- Close slow WebSocket clients with 1013 so they reconnect with replay
- Lazy-load the xterm terminal view and skip unchanged resize requests
- Request uncompressed responses from preview targets

Cleanup:
- Share one repo directory resolver, trusted-origins parser, cookie prefix, WebSocket frame forwarder, header filter, icon map and dialog-param helper
- Remove unused props, options and exports

Docs: update terminal, preview, project actions, sandboxing, internal API and environment pages
This commit is contained in:
Chris Scott committed 2026-10-03 10:00:33 -04:00
1 parent 16b91ccf02
commit c60a9b35f2
72 files changed
+2039 -596

No files matched your search

+5 -7
View File
@@ -3,16 +3,14 @@ import type { CreatePreviewSessionResponse, PreviewPortsResponse } from '@openco
import { API_BASE_URL } from '@/config'
import { fetchWrapper } from './fetchWrapper'
function directoryQuery(directory: string | undefined): string {
return directory ? `?${new URLSearchParams({ directory }).toString()}` : ''
}
export function previewPortsQueryKey(directory: string | undefined) {
function previewPortsQueryKey(directory: string | undefined) {
return ['previewPorts', directory ?? null] as const
}
export function listPreviewPorts(directory?: string): Promise<PreviewPortsResponse> {
return fetchWrapper(`${API_BASE_URL}/api/preview/ports${directoryQuery(directory)}`)
function listPreviewPorts(directory?: string): Promise<PreviewPortsResponse> {
return fetchWrapper(`${API_BASE_URL}/api/preview/ports`, {
params: { directory },
})
}
export function createPreviewSession(port: number): Promise<CreatePreviewSessionResponse> {
+20 -20
View File
@@ -9,43 +9,43 @@ import type {
import { API_BASE_URL } from '@/config'
import { fetchWrapper } from './fetchWrapper'
function directoryQuery(directory: string | undefined): string {
return directory ? `?${new URLSearchParams({ directory }).toString()}` : ''
}
export function projectConfigQueryKey(repoId: number, directory: string | undefined) {
function projectConfigQueryKey(repoId: number, directory: string | undefined) {
return ['projectConfig', repoId, directory ?? null] as const
}
export function getProjectConfig(repoId: number, directory?: string): Promise<ProjectConfigResponse> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config${directoryQuery(directory)}`)
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config`, {
params: { directory },
})
}
export function updateProjectActions(
function updateProjectActions(
repoId: number,
actions: ProjectAction[],
directory?: string,
): Promise<ProjectConfigResponse> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/actions${directoryQuery(directory)}`, {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/actions`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ actions }),
params: { directory },
})
}
export function updateWorktreeSetup(
function updateWorktreeSetup(
repoId: number,
commands: string[],
directory?: string,
): Promise<ProjectConfigResponse> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/worktree-setup${directoryQuery(directory)}`, {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/worktree-setup`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ commands }),
params: { directory },
})
}
export function trustRepoConfig(repoId: number, request: TrustRepoConfigRequest): Promise<ProjectConfigResponse> {
function trustRepoConfig(repoId: number, request: TrustRepoConfigRequest): Promise<ProjectConfigResponse> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/trust`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -53,7 +53,7 @@ export function trustRepoConfig(repoId: number, request: TrustRepoConfigRequest)
})
}
export function moveProjectItem(repoId: number, request: MoveProjectItemRequest): Promise<ProjectConfigResponse> {
function moveProjectItem(repoId: number, request: MoveProjectItemRequest): Promise<ProjectConfigResponse> {
return fetchWrapper(`${API_BASE_URL}/api/repos/${repoId}/project-config/move`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -61,7 +61,7 @@ export function moveProjectItem(repoId: number, request: MoveProjectItemRequest)
})
}
export function runProjectAction(
function runProjectAction(
repoId: number,
actionId: string,
directory?: string,
@@ -89,7 +89,7 @@ export function useUpdateProjectActions(repoId: number, directory: string | unde
return useMutation({
mutationFn: (actions: ProjectAction[]) => updateProjectActions(repoId, actions, directory),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['projectConfig', repoId] })
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, directory) })
},
})
}
@@ -99,7 +99,7 @@ export function useUpdateWorktreeSetup(repoId: number, directory: string | undef
return useMutation({
mutationFn: (commands: string[]) => updateWorktreeSetup(repoId, commands, directory),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['projectConfig', repoId] })
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, directory) })
},
})
}
@@ -108,8 +108,8 @@ export function useTrustRepoConfig(repoId: number) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (request: TrustRepoConfigRequest) => trustRepoConfig(repoId, request),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['projectConfig', repoId] })
onSuccess: (_data, request) => {
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, request.directory) })
},
})
}
@@ -118,8 +118,8 @@ export function useMoveProjectItem(repoId: number) {
const queryClient = useQueryClient()
return useMutation({
mutationFn: (request: MoveProjectItemRequest) => moveProjectItem(repoId, request),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['projectConfig', repoId] })
onSuccess: (_data, request) => {
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, request.directory) })
},
})
}
@@ -129,7 +129,7 @@ export function useRunProjectAction(repoId: number, directory: string | undefine
return useMutation({
mutationFn: (actionId: string) => runProjectAction(repoId, actionId, directory),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['projectConfig', repoId] })
queryClient.invalidateQueries({ queryKey: projectConfigQueryKey(repoId, directory) })
queryClient.invalidateQueries({ queryKey: ['terminals', repoId] })
},
})
+18 -17
View File
@@ -3,22 +3,23 @@ import type { CreateTerminalRequest, ResizeTerminalRequest, TerminalInfo } from
import { API_BASE_URL } from '@/config'
import { fetchWrapper, fetchWrapperVoid } from './fetchWrapper'
function directoryQuery(directory: string | undefined): string {
return directory ? `?${new URLSearchParams({ directory }).toString()}` : ''
}
export function terminalsQueryKey(repoId: number, directory: string | undefined) {
function terminalsQueryKey(repoId: number, directory: string | undefined) {
return ['terminals', repoId, directory ?? null] as const
}
export async function listTerminals(repoId: number, directory?: string): Promise<TerminalInfo[]> {
function terminalsRepoQueryKey(repoId: number) {
return ['terminals', repoId] as const
}
async function listTerminals(repoId: number, directory?: string): Promise<TerminalInfo[]> {
const data = await fetchWrapper<{ terminals: TerminalInfo[] }>(
`${API_BASE_URL}/api/repos/${repoId}/terminals${directoryQuery(directory)}`,
`${API_BASE_URL}/api/repos/${repoId}/terminals`,
{ params: { directory } },
)
return data.terminals
}
export async function createTerminal(repoId: number, body: CreateTerminalRequest): Promise<TerminalInfo> {
async function createTerminal(repoId: number, body: CreateTerminalRequest): Promise<TerminalInfo> {
return fetchWrapper<TerminalInfo>(`${API_BASE_URL}/api/repos/${repoId}/terminals`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -34,14 +35,14 @@ export async function resizeTerminal(repoId: number, ptyID: string, body: Resize
})
}
export async function removeTerminal(repoId: number, ptyID: string, directory?: string): Promise<void> {
return fetchWrapperVoid(
`${API_BASE_URL}/api/repos/${repoId}/terminals/${encodeURIComponent(ptyID)}${directoryQuery(directory)}`,
{ method: 'DELETE' },
)
async function removeTerminal(repoId: number, ptyID: string, directory?: string): Promise<void> {
return fetchWrapperVoid(`${API_BASE_URL}/api/repos/${repoId}/terminals/${encodeURIComponent(ptyID)}`, {
method: 'DELETE',
params: { directory },
})
}
export interface UseTerminalsOptions {
interface UseTerminalsOptions {
enabled: boolean
refetchInterval?: number | false
}
@@ -60,12 +61,12 @@ export function useCreateTerminal(repoId: number) {
return useMutation({
mutationFn: (body: CreateTerminalRequest) => createTerminal(repoId, body),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['terminals', repoId] })
queryClient.invalidateQueries({ queryKey: terminalsRepoQueryKey(repoId) })
},
})
}
export interface RemoveTerminalVariables {
interface RemoveTerminalVariables {
ptyID: string
directory?: string
}
@@ -75,7 +76,7 @@ export function useRemoveTerminal(repoId: number) {
return useMutation({
mutationFn: ({ ptyID, directory }: RemoveTerminalVariables) => removeTerminal(repoId, ptyID, directory),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['terminals', repoId] })
queryClient.invalidateQueries({ queryKey: terminalsRepoQueryKey(repoId) })
},
})
}