mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
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:
1 parent
16b91ccf02
commit
c60a9b35f2
72 files changed
+2039
-596
No files matched your search
@@ -1,6 +1,7 @@
|
||||
export interface WebSocketPeer {
|
||||
send(data: string | Uint8Array<ArrayBuffer>): void
|
||||
close(code?: number, reason?: string): void
|
||||
bufferedAmount(): number
|
||||
}
|
||||
|
||||
export interface WebSocketBridge {
|
||||
@@ -8,8 +9,28 @@ export interface WebSocketBridge {
|
||||
close(): void
|
||||
}
|
||||
|
||||
export interface BridgeWebSocketOptions {
|
||||
mapCloseCode?: (code: number) => number
|
||||
export const MAX_PEER_BUFFERED_BYTES = 4 * 1024 * 1024
|
||||
|
||||
export function peerBufferedAmount(peer: { raw?: unknown }): number {
|
||||
const raw = peer.raw as { bufferedAmount?: number } | undefined
|
||||
return typeof raw?.bufferedAmount === 'number' ? raw.bufferedAmount : 0
|
||||
}
|
||||
|
||||
export async function forwardPeerMessage(
|
||||
bridge: WebSocketBridge,
|
||||
data: string | Blob | ArrayBufferLike,
|
||||
): Promise<void> {
|
||||
if (typeof data === 'string') {
|
||||
bridge.send(data)
|
||||
return
|
||||
}
|
||||
if (data instanceof Blob) {
|
||||
bridge.send(await data.arrayBuffer())
|
||||
return
|
||||
}
|
||||
if (data instanceof ArrayBuffer) {
|
||||
bridge.send(data)
|
||||
}
|
||||
}
|
||||
|
||||
function defaultMapCloseCode(code: number): number {
|
||||
@@ -22,13 +43,8 @@ function toBytes(data: ArrayBuffer | Uint8Array): Uint8Array<ArrayBuffer> {
|
||||
return data instanceof Uint8Array ? (data as Uint8Array<ArrayBuffer>) : new Uint8Array(data)
|
||||
}
|
||||
|
||||
export function bridgeWebSocket(
|
||||
upstream: WebSocket,
|
||||
peer: WebSocketPeer,
|
||||
options: BridgeWebSocketOptions = {},
|
||||
): WebSocketBridge {
|
||||
export function bridgeWebSocket(upstream: WebSocket, peer: WebSocketPeer): WebSocketBridge {
|
||||
upstream.binaryType = 'arraybuffer'
|
||||
const mapCloseCode = options.mapCloseCode ?? defaultMapCloseCode
|
||||
|
||||
const queue: Array<string | Uint8Array> = []
|
||||
let upstreamOpen = false
|
||||
@@ -46,18 +62,24 @@ export function bridgeWebSocket(
|
||||
})
|
||||
|
||||
upstream.addEventListener('message', (event) => {
|
||||
if (finished) return
|
||||
const data = (event as MessageEvent).data
|
||||
if (typeof data === 'string') {
|
||||
peer.send(data)
|
||||
} else if (data instanceof ArrayBuffer || data instanceof Uint8Array) {
|
||||
peer.send(toBytes(data))
|
||||
}
|
||||
if (peer.bufferedAmount() > MAX_PEER_BUFFERED_BYTES) {
|
||||
finish()
|
||||
upstream.close()
|
||||
peer.close(1013, 'Client too slow')
|
||||
}
|
||||
})
|
||||
|
||||
upstream.addEventListener('close', (event) => {
|
||||
if (finished) return
|
||||
finish()
|
||||
peer.close(mapCloseCode((event as CloseEvent).code))
|
||||
peer.close(defaultMapCloseCode((event as CloseEvent).code))
|
||||
})
|
||||
|
||||
upstream.addEventListener('error', () => {
|
||||
|
||||
Reference in new issue
Block a user