feat(deployment-logs): enhance readValidDirectory function to accept serverId parameter

- Updated the readValidDirectory function to include an optional serverId parameter, improving its flexibility for directory validation.
- Modified the deployment logs WebSocket server setup to utilize the updated readValidDirectory function, ensuring proper log path validation based on server context.
This commit is contained in:
Mauricio Siu
2026-02-07 23:19:33 -06:00
parent 4bc494e009
commit f1d0fb95f4
2 changed files with 6 additions and 4 deletions
+1 -2
View File
@@ -34,14 +34,13 @@ export const setupDeploymentLogsWebSocketServer = (
// Generate unique connection ID for tracking // Generate unique connection ID for tracking
const connectionId = `deployment-logs-${Date.now()}-${Math.random().toString(36).substring(7)}`; const connectionId = `deployment-logs-${Date.now()}-${Math.random().toString(36).substring(7)}`;
if (!logPath) { if (!logPath) {
console.log(`[${connectionId}] logPath no provided`); console.log(`[${connectionId}] logPath no provided`);
ws.close(4000, "logPath no provided"); ws.close(4000, "logPath no provided");
return; return;
} }
if (!readValidDirectory(logPath)) { if (!readValidDirectory(logPath, serverId)) {
ws.close(4000, "Invalid log path"); ws.close(4000, "Invalid log path");
return; return;
} }
+5 -2
View File
@@ -32,8 +32,11 @@ export const isValidShell = (shell: string): boolean => {
return allowedShells.includes(shell); return allowedShells.includes(shell);
}; };
export const readValidDirectory = (directory: string) => { export const readValidDirectory = (
const { BASE_PATH } = paths(); directory: string,
serverId?: string | null,
) => {
const { BASE_PATH } = paths(!!serverId);
const resolvedBase = path.resolve(BASE_PATH); const resolvedBase = path.resolve(BASE_PATH);
const resolvedDir = path.resolve(directory); const resolvedDir = path.resolve(directory);