Skip to content

Commit f1e678e

Browse files
tomas-sexenianBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:Compress' into beta
1 parent 305dc0d commit f1e678e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

gxcompress/src/main/java/com/genexus/compression/GXCompressor.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,23 @@ public static Boolean compress(ArrayList<String> files, String path, GXBaseColle
6161
int index = 0;
6262
for (String filePath : files) {
6363
File file = new File(filePath);
64-
if (!file.exists()) {
65-
log.error("{}{}", FILE_NOT_EXISTS, filePath);
66-
storageMessages(FILE_NOT_EXISTS + filePath, messages[0]);
67-
continue;
64+
try {
65+
String normalizedPath = file.getCanonicalPath();
66+
if (!file.exists()) {
67+
log.error("{}{}", FILE_NOT_EXISTS, filePath);
68+
storageMessages(FILE_NOT_EXISTS + filePath, messages[0]);
69+
continue;
70+
}
71+
if (normalizedPath.contains(File.separator + ".." + File.separator) ||
72+
normalizedPath.endsWith(File.separator + "..") ||
73+
normalizedPath.startsWith(".." + File.separator)) {
74+
log.warn("Potential directory traversal attack detected: {}", filePath);
75+
continue;
76+
}
77+
toCompress[index++] = file;
78+
} catch (IOException e) {
79+
log.error("Error normalizing path for file: {}", filePath, e);
6880
}
69-
toCompress[index++] = file;
7081
}
7182
String format = CommonUtil.getFileType(path).toLowerCase();
7283
try {

0 commit comments

Comments
 (0)