fix(安全/健壮性): 全工作区审查修复——鉴权兜底扩展+路径穿越+忙等+泄漏
- AdminApiGuardFilter 兜底扩展到 /api/collect-data、/api/price-track:无需鉴权的 工具接口纳入 JWT/内部令牌校验(原匿名可达即越权读写他人数据) - pricetrack asinFiles 改为仅允许上传临时目录内文件(canonical 前缀校验), 修复请求路径直接 new File 可读服务器任意 csv/xlsx 的穿越 - dedupe 删除导入逐行 REQUIRES_NEW 事务改 500 条一批 IN 删除,50 万行导入 由 50 万个事务收敛为千级 - 前端记住密码 XOR 硬编码密钥改 WebCrypto AES-GCM(密钥随机生成独立存储), 登录流程接口改 async 并保证自动登录恢复时序 - 任务进度轮询失败按指数退避(原固定 5s 无限撞);下载进度终态条目 2 分钟 自动清理(原永久堆积);AmazonConsolePage statusTimer 卸载清理
This commit is contained in:
+21
-3
@@ -42,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -1462,15 +1463,16 @@ public class PriceTrackTaskService {
|
||||
if (rawPath == null || rawPath.isBlank()) {
|
||||
continue;
|
||||
}
|
||||
File file = new File(rawPath);
|
||||
// 只允许解析上传落库的临时目录文件:直接 new File(请求路径) 可被穿越读服务器任意 csv/xlsx
|
||||
File file = new File(localFileStorageService.localTempRoot().getAbsolutePath(), rawPath);
|
||||
if (!file.isFile()) {
|
||||
// 直接路径不可读时兜底:按上传返回的 fileKey 反查服务器本地临时目录
|
||||
// 传入的是 fileKey/索引键时按上传索引反查临时目录
|
||||
File resolved = localFileStorageService.findLocalSourceFile(rawPath);
|
||||
if (resolved != null) {
|
||||
file = resolved;
|
||||
}
|
||||
}
|
||||
if (!file.isFile()) {
|
||||
if (!file.isFile() || !isInsideTempDir(file)) {
|
||||
throw new BusinessException("ASIN 文件不存在或不可读: " + rawPath);
|
||||
}
|
||||
String lowerName = file.getName().toLowerCase(Locale.ROOT);
|
||||
@@ -1487,6 +1489,22 @@ public class PriceTrackTaskService {
|
||||
return merged;
|
||||
}
|
||||
|
||||
/** 穿越校验:文件必须位于上传临时目录内(canonical path 前缀,防 ../ 与符号链接)。 */
|
||||
private boolean isInsideTempDir(File file) {
|
||||
try {
|
||||
File root = localFileStorageService.localTempRoot();
|
||||
if (!root.exists()) {
|
||||
return false;
|
||||
}
|
||||
String rootPath = root.getCanonicalPath();
|
||||
String filePath = file.getCanonicalPath();
|
||||
return filePath.equals(rootPath) || filePath.startsWith(rootPath + File.separator);
|
||||
} catch (IOException e) {
|
||||
log.warn("[price-track] ASIN 文件路径规范化失败,拒绝解析: {}", file, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, List<Map<String, String>>> parseWorkbookAsinRows(File file, List<String> countryCodes) {
|
||||
Map<String, List<Map<String, String>>> out = new LinkedHashMap<>();
|
||||
AtomicReference<Map<String, Integer>> headerIndexHolder = new AtomicReference<>(Map.of());
|
||||
|
||||
Reference in New Issue
Block a user