feat(wss): add directory validation for WebSocket server log paths

This commit is contained in:
Mauricio Siu
2026-01-27 09:56:28 -06:00
parent 24c1c2a377
commit 5967f48c6b
2 changed files with 17 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ import type http from "node:http";
import { findServerById, IS_CLOUD, validateRequest } from "@dokploy/server";
import { Client } from "ssh2";
import { WebSocketServer } from "ws";
import { readValidDirectory } from "./utils";
export const setupDeploymentLogsWebSocketServer = (
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>,
@@ -40,6 +41,11 @@ export const setupDeploymentLogsWebSocketServer = (
return;
}
if (!readValidDirectory(logPath)) {
ws.close(4000, "Invalid log path");
return;
}
if (!user || !session) {
ws.close();
return;

View File

@@ -32,6 +32,17 @@ export const isValidShell = (shell: string): boolean => {
return allowedShells.includes(shell);
};
export const readValidDirectory = (directory: string) => {
const { BASE_PATH } = paths();
const resolvedBase = path.resolve(BASE_PATH);
const resolvedDir = path.resolve(directory);
return (
resolvedDir === resolvedBase ||
resolvedDir.startsWith(resolvedBase + path.sep)
);
};
export const getShell = () => {
if (IS_CLOUD) {
return "NO_AVAILABLE";