mirror of
https://github.com/Dokploy/dokploy.git
synced 2026-06-15 20:25:23 +02:00
feat(validation): enhance destination path validation in file upload schema
- Updated the `destinationPath` field in the upload file schema to include a regex validation, ensuring only alphanumeric characters, dots, dashes, underscores, and forward slashes are allowed. - Added a corresponding regex check in the `uploadFileToContainer` function to validate the destination path before processing, improving input integrity and preventing errors.
This commit is contained in:
@@ -28,7 +28,13 @@ export const uploadFileToContainerSchema = zfd.formData({
|
|||||||
.min(1)
|
.min(1)
|
||||||
.regex(/^[a-zA-Z0-9.\-_]+$/, "Invalid container ID"),
|
.regex(/^[a-zA-Z0-9.\-_]+$/, "Invalid container ID"),
|
||||||
file: zfd.file(),
|
file: zfd.file(),
|
||||||
destinationPath: z.string().min(1),
|
destinationPath: z
|
||||||
|
.string()
|
||||||
|
.min(1)
|
||||||
|
.regex(
|
||||||
|
/^[a-zA-Z0-9.\-_/]+$/,
|
||||||
|
"Invalid destination path: only alphanumeric characters, dots, dashes, underscores, and forward slashes are allowed",
|
||||||
|
),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -655,6 +655,8 @@ export const getAllContainerStats = async (serverId?: string) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const destinationPathRegex = /^[a-zA-Z0-9.\-_/]+$/;
|
||||||
|
|
||||||
export const uploadFileToContainer = async (
|
export const uploadFileToContainer = async (
|
||||||
containerId: string,
|
containerId: string,
|
||||||
fileBuffer: Buffer,
|
fileBuffer: Buffer,
|
||||||
@@ -667,7 +669,10 @@ export const uploadFileToContainer = async (
|
|||||||
throw new Error("Invalid container ID");
|
throw new Error("Invalid container ID");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure destination path starts with /
|
if (!destinationPathRegex.test(destinationPath)) {
|
||||||
|
throw new Error("Invalid destination path: shell metacharacters are not allowed");
|
||||||
|
}
|
||||||
|
|
||||||
const normalizedPath = destinationPath.startsWith("/")
|
const normalizedPath = destinationPath.startsWith("/")
|
||||||
? destinationPath
|
? destinationPath
|
||||||
: `/${destinationPath}`;
|
: `/${destinationPath}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user