From 491efa3846a24f2ee2ec95ab7c94cbf100914141 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Thu, 19 Dec 2024 16:50:11 -0600 Subject: [PATCH] #30963 --- .../src/main/java/com/dotcms/common/AssetsUtils.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/dotcms-cli/api-data-model/src/main/java/com/dotcms/common/AssetsUtils.java b/tools/dotcms-cli/api-data-model/src/main/java/com/dotcms/common/AssetsUtils.java index 703a4d6615b6..e3e3a3995714 100644 --- a/tools/dotcms-cli/api-data-model/src/main/java/com/dotcms/common/AssetsUtils.java +++ b/tools/dotcms-cli/api-data-model/src/main/java/com/dotcms/common/AssetsUtils.java @@ -194,15 +194,16 @@ public static List parseRootPaths(final File workspace, final File sourc var workspaceCount = workspacePath.getNameCount(); var sourceCount = sourcePath.getNameCount(); - if (sourceCount < workspaceCount) { + if (!sourcePath.startsWith(workspacePath) ) { throw new IllegalArgumentException("Source path cannot be outside of the workspace"); } final Path filesPath = Path.of(workspace.getAbsolutePath(), FILES_NAMESPACE) .toAbsolutePath().normalize(); // Check if we are inside the workspace but also inside the files folder - if (sourceCount > workspaceCount + 1 || (sourceCount == workspaceCount + 1 && !sourcePath.startsWith(filesPath))) { + if ((sourceCount > workspaceCount + 1 || sourceCount == workspaceCount + 1) && !sourcePath.startsWith(filesPath)) { logger.warn("Invalid source path provided for a files push {}. Source path must be inside the files folder. otherwise it will fall back to workspace. {}", sourcePath, workspacePath); + System.out.println("Invalid source path provided for a files push. Source path must be inside the files folder. otherwise it will fall back to workspace." + sourcePath + " " + workspacePath); //if a source path is provided, but it is not inside the files folder but still is a valid folder then we will fall back to the workspace return parseRootPaths(workspacePath, workspaceCount, workspaceCount); }