fix(仪表板): 修复不安全上传文件路径问题

This commit is contained in:
wangjiahao 2024-03-27 16:06:39 +08:00
parent 6d79bd52bd
commit 8de7337f19

View File

@ -44,9 +44,10 @@ public class StaticResourceService {
}
String originName = file.getOriginalFilename();
String newFileName = fileId + originName.substring(originName.lastIndexOf("."), originName.length());
Path uploadPath = Paths.get(staticDir.toString(), newFileName);
Path basePath = Paths.get(staticDir.toString());
// create dir is absent
FileUtils.createIfAbsent(Paths.get(staticDir.toString()));
FileUtils.createIfAbsent(basePath);
Path uploadPath = basePath.resolve(newFileName);
Files.createFile(uploadPath);
file.transferTo(uploadPath);
} catch (IOException e) {
@ -86,9 +87,10 @@ public class StaticResourceService {
}
public void saveSingleFileToServe(String fileName, String content) {
Path uploadPath = Paths.get(staticDir.toString(), fileName);
Path basePath = Paths.get(staticDir.toString());
Path uploadPath = basePath.resolve(fileName);
try {
if (uploadPath.toFile().exists()) {
if (Files.exists(uploadPath)) {
LogUtil.info("file exists");
} else {
if (StringUtils.isNotEmpty(content)) {