Skip to content

Commit c77bf3d

Browse files
committed
修复未授权任意文件写入漏洞
1 parent 3407027 commit c77bf3d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

case-server/src/main/java/com/xiaoju/framework/util/FileUtil.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ public static boolean decompressZip(String zipPath, String descDir) {
3838
InputStream in = zip.getInputStream(entry);
3939
//指定解压后的文件夹+当前zip文件的名称
4040
String outPath = (descDir+zipEntryName).replace("/", File.separator);
41-
//判断路径是否存在,不存在则创建文件路径
41+
42+
//判断路径是否存在,不存在则创建文件路径,同时添加检验
43+
String canonicalDescDirPath = pathFile.getCanonicalPath();
4244
File file = new File(outPath.substring(0, outPath.lastIndexOf(File.separator)));
45+
String CanonicalDescFile = file.getCanonicalPath() + "/";
46+
if(!CanonicalDescFile.startsWith(canonicalDescDirPath + File.separator)){
47+
throw new ArithmeticException("Entry is outside of the target dir: " + zipEntryName);
48+
}
49+
4350
if(!file.exists()){
4451
file.mkdirs();
4552
}

0 commit comments

Comments
 (0)