mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 05:55:44 +01:00
Validate filepath and filename to prevent path traversal (#1604)
Validate filepath and filename to prevent path traversal in modification command and provide validations for editor plugin. Co-authored-by: René Pfeuffer <rene.pfeuffer@cloudogu.com>
This commit is contained in:
@@ -44,10 +44,11 @@ export const isNumberValid = (number: any) => {
|
||||
return !isNaN(number);
|
||||
};
|
||||
|
||||
const pathRegex = /^((?!\/{2,}).)*$/;
|
||||
|
||||
export const isPathValid = (path: string) => {
|
||||
return pathRegex.test(path);
|
||||
return path !== "."
|
||||
&& !path.includes("../")
|
||||
&& !path.includes("//")
|
||||
&& path !== "..";
|
||||
};
|
||||
|
||||
const urlRegex = /^[A-Za-z0-9]+:\/\/[^\s$.?#].[^\s]*$/;
|
||||
@@ -55,3 +56,9 @@ const urlRegex = /^[A-Za-z0-9]+:\/\/[^\s$.?#].[^\s]*$/;
|
||||
export const isUrlValid = (url: string) => {
|
||||
return urlRegex.test(url);
|
||||
};
|
||||
|
||||
const filenameRegex = /^[^/\\:]+$/;
|
||||
|
||||
export const isFilenameValid = (filename: string) => {
|
||||
return filenameRegex.test(filename) && filename !== "." && filename !== ".." && !filename.includes("./");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user