mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-22 03:48:46 +00:00
fix(wss): add container ID validation to enhance security in WebSocket server
This commit is contained in:
@@ -3,7 +3,7 @@ import { findServerById, IS_CLOUD, validateRequest } from "@dokploy/server";
|
|||||||
import { spawn } from "node-pty";
|
import { spawn } from "node-pty";
|
||||||
import { Client } from "ssh2";
|
import { Client } from "ssh2";
|
||||||
import { WebSocketServer } from "ws";
|
import { WebSocketServer } from "ws";
|
||||||
import { getShell } from "./utils";
|
import { getShell, isValidContainerId } from "./utils";
|
||||||
|
|
||||||
export const setupDockerContainerLogsWebSocketServer = (
|
export const setupDockerContainerLogsWebSocketServer = (
|
||||||
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
|
||||||
@@ -42,6 +42,12 @@ export const setupDockerContainerLogsWebSocketServer = (
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Security: Validate containerId to prevent command injection
|
||||||
|
if (!isValidContainerId(containerId)) {
|
||||||
|
ws.close(4000, "Invalid container ID format");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!user || !session) {
|
if (!user || !session) {
|
||||||
ws.close();
|
ws.close();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user