mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-07-28 09:15:24 +02:00
fix: prevent to pass invalid docker container names
This commit is contained in:
@@ -1,9 +1,41 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { execAsync, paths } from "@dokploy/server";
|
||||
import { execAsync, IS_CLOUD, paths } from "@dokploy/server";
|
||||
|
||||
/**
|
||||
* Validates that the container ID matches Docker's expected format.
|
||||
* Docker container IDs are 64-character hex strings (or 12-char short form).
|
||||
* Also allows container names: alphanumeric, underscores, hyphens, and dots.
|
||||
*/
|
||||
export const isValidContainerId = (id: string): boolean => {
|
||||
// Match full ID (64 hex chars), short ID (12 hex chars), or container name
|
||||
const hexPattern = /^[a-f0-9]{12,64}$/i;
|
||||
const namePattern = /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/;
|
||||
return hexPattern.test(id) || (namePattern.test(id) && id.length <= 128);
|
||||
};
|
||||
|
||||
/**
|
||||
* Validates that the shell is one of the allowed shells.
|
||||
*/
|
||||
export const isValidShell = (shell: string): boolean => {
|
||||
const allowedShells = [
|
||||
"sh",
|
||||
"bash",
|
||||
"zsh",
|
||||
"ash",
|
||||
"/bin/sh",
|
||||
"/bin/bash",
|
||||
"/bin/zsh",
|
||||
"/bin/ash",
|
||||
];
|
||||
return allowedShells.includes(shell);
|
||||
};
|
||||
|
||||
export const getShell = () => {
|
||||
if (IS_CLOUD) {
|
||||
return "CLOUD_VERSION";
|
||||
}
|
||||
switch (os.platform()) {
|
||||
case "win32":
|
||||
return "powershell.exe";
|
||||
|
||||
Reference in New Issue
Block a user