This commit is contained in:
jarek committed 2026-06-17 08:21:38 +02:00
1 parent aa45be6844
commit efb634701c
56 files changed
+9101 -117

No files matched your search

+25
View File
@@ -574,6 +574,20 @@ function webSocketPlugin(): Plugin {
return;
}
const authFn = (globalThis as any).__authenticateWsUpgrade;
if (typeof authFn !== 'function') {
ws.send(JSON.stringify({ type: 'error', message: 'service unavailable' }));
ws.close(1011, 'service unavailable');
return;
}
const wsAuth = await authFn(req.headers);
if (!wsAuth) {
ws.send(JSON.stringify({ type: 'error', message: 'Unauthorized' }));
ws.close(1008, 'unauthorized');
return;
}
(ws as any).__auth = wsAuth;
// Assign unique connection ID to this WebSocket
const connId = `ws-${++wsConnectionCounter}`;
meta.connId = connId;
@@ -594,6 +608,17 @@ function webSocketPlugin(): Plugin {
return;
}
const canAccessFn = (globalThis as any).__canAccessEnvForUser;
if (typeof canAccessFn === 'function') {
const ok = await canAccessFn(wsAuth, envId);
if (!ok) {
console.warn(`[WS] env access denied: user=${wsAuth.username} envId=${envId}`);
ws.send(JSON.stringify({ type: 'error', message: 'Access denied for this environment' }));
ws.close(1008, 'env access denied');
return;
}
}
const target = getDockerTarget(envId);
try {