feat(deployment): enhance log retrieval by encoding log path in base64

- Updated the WebSocket server to encode the log path in base64 before executing the tail command on the remote server.
- Added validation to ensure the directory name adheres to a specified regex pattern, improving input integrity for directory paths.
This commit is contained in:
Mauricio Siu
2026-05-09 00:01:45 -06:00
parent 06a349152f
commit a4e2317f3e
2 changed files with 8 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
import { spawn } from "node:child_process"; import { spawn } from "node:child_process";
import type http from "node:http"; import type http from "node:http";
import { findServerById, IS_CLOUD, validateRequest } from "@dokploy/server"; import { findServerById, IS_CLOUD, validateRequest } from "@dokploy/server";
import { encodeBase64 } from "@dokploy/server/utils/docker/utils";
import { readValidDirectory } from "@dokploy/server/wss/utils"; import { readValidDirectory } from "@dokploy/server/wss/utils";
import { Client } from "ssh2"; import { Client } from "ssh2";
import { WebSocketServer } from "ws"; import { WebSocketServer } from "ws";
@@ -70,9 +71,9 @@ export const setupDeploymentLogsWebSocketServer = (
sshClient = new Client(); sshClient = new Client();
sshClient sshClient
.on("ready", () => { .on("ready", () => {
const command = ` const encodedPath = encodeBase64(logPath);
tail -n +1 -f ${logPath}; const command = `tail -n +1 -f "$(echo '${encodedPath}' | base64 -d)"`;
`;
sshClient!.exec(command, (err, stream) => { sshClient!.exec(command, (err, stream) => {
if (err) { if (err) {
sshClient!.end(); sshClient!.end();

View File

@@ -40,6 +40,10 @@ export const readValidDirectory = (
directory: string, directory: string,
serverId?: string | null, serverId?: string | null,
) => { ) => {
if (!/^[\w/. -]{1,500}$/.test(directory)) {
return false;
}
const { BASE_PATH } = paths(!!serverId); const { BASE_PATH } = paths(!!serverId);
const resolvedBase = path.resolve(BASE_PATH); const resolvedBase = path.resolve(BASE_PATH);