生成报告脚本
This commit is contained in:
@@ -2537,7 +2537,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
throw new RuntimeException("文件夹不存在,ID: " + downloadDirId);
|
||||
}
|
||||
|
||||
if(!Objects.equals(DataTypeEnum.DIRECTORY.getValue(),folderInfo.getFileType())){
|
||||
if (!Objects.equals(DataTypeEnum.DIRECTORY.getValue(), folderInfo.getFileType())) {
|
||||
throw new RuntimeException("指定 ID 不是文件夹类型: " + downloadDirId);
|
||||
}
|
||||
|
||||
@@ -2551,19 +2551,12 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
folderObjectKey += "/";
|
||||
}
|
||||
|
||||
// 2. 构建本地基础路径(直接使用 basePath + folderObjectKey)
|
||||
// 2. 构建本地基础路径(basePath 就是最终根目录)
|
||||
Path localBaseDir = Paths.get(basePath).toAbsolutePath().normalize();
|
||||
Path fullLocalBase = localBaseDir.resolve(folderObjectKey).normalize();
|
||||
|
||||
// 安全校验:确保 fullLocalBase 确实在 basePath 下
|
||||
if (!fullLocalBase.startsWith(localBaseDir)) {
|
||||
throw new RuntimeException("非法文件夹路径,可能包含路径穿越: " + folderObjectKey);
|
||||
}
|
||||
|
||||
try {
|
||||
Files.createDirectories(fullLocalBase);
|
||||
Files.createDirectories(localBaseDir); // 确保 basePath 存在
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("无法创建本地目录: " + fullLocalBase, e);
|
||||
throw new RuntimeException("无法创建本地基础目录: " + localBaseDir, e);
|
||||
}
|
||||
|
||||
// 3. 列出 MinIO 中该前缀下的所有对象(递归)
|
||||
@@ -2579,7 +2572,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 遍历并下载每个对象(任一失败立即抛出 RuntimeException)
|
||||
// 4. 遍历并下载每个对象
|
||||
for (Result<Item> result : results) {
|
||||
Item item = result.get();
|
||||
String objectKey = item.objectName();
|
||||
@@ -2589,19 +2582,29 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 如果提供了正则表达式,则进行过滤
|
||||
// 理论上 listObjects(folderObjectKey) 返回的都以 folderObjectKey 开头,但加个校验更安全
|
||||
if (!objectKey.startsWith(folderObjectKey)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 剥离文件夹前缀,得到相对路径
|
||||
String relativePath = objectKey.substring(folderObjectKey.length());
|
||||
if (relativePath.isEmpty()) {
|
||||
continue; // 忽略空路径(不应发生)
|
||||
}
|
||||
|
||||
// 如果提供了正则表达式,则只匹配文件名(不是完整路径)
|
||||
if (pattern != null) {
|
||||
String fileName = Paths.get(objectKey).getFileName().toString();
|
||||
String fileName = Paths.get(relativePath).getFileName().toString();
|
||||
if (!pattern.matcher(fileName).matches()) {
|
||||
// 不匹配正则表达式的文件跳过下载
|
||||
continue;
|
||||
continue; // 跳过不匹配的文件
|
||||
}
|
||||
}
|
||||
|
||||
// 构建本地文件路径:basePath + objectKey
|
||||
Path localFilePath = localBaseDir.resolve(objectKey).normalize();
|
||||
// 构建本地文件路径:basePath + 相对路径
|
||||
Path localFilePath = localBaseDir.resolve(relativePath).normalize();
|
||||
|
||||
// 二次安全校验:防止 objectKey 含 ../ 导致越界
|
||||
// 安全校验:防止路径穿越(例如 relativePath 含 ../../)
|
||||
if (!localFilePath.startsWith(localBaseDir)) {
|
||||
throw new RuntimeException("检测到非法对象路径,拒绝下载: " + objectKey);
|
||||
}
|
||||
@@ -2624,7 +2627,7 @@ public class MinioFileIDataFileServiceImpl implements IDataFileService {
|
||||
throw new RuntimeException("下载对象失败: " + objectKey, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return SdmResponse.success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user