refactor: 文件路径校验,防止路径穿越问题
This commit is contained in:
parent
37b7fd75fd
commit
77fc18b6f7
|
@ -57,6 +57,7 @@ public class LocalFileRepository implements FileRepository {
|
|||
|
||||
@Override
|
||||
public void deleteFolder(FileRequest request) throws Exception {
|
||||
MsFileUtils.validateFileName(request.getProjectId(), request.getFileName());
|
||||
this.delete(request);
|
||||
}
|
||||
|
||||
|
@ -81,10 +82,12 @@ public class LocalFileRepository implements FileRepository {
|
|||
}
|
||||
|
||||
private String getFilePath(FileRequest request) {
|
||||
MsFileUtils.validateFileName(request.getProjectId(), request.getFileName());
|
||||
return StringUtils.join(getFileDir(request), "/", request.getFileName());
|
||||
}
|
||||
|
||||
private String getFileDir(FileRequest request) {
|
||||
MsFileUtils.validateFileName(request.getProjectId(), request.getFileName());
|
||||
return StringUtils.join(MsFileUtils.DATE_ROOT_DIR, "/", request.getProjectId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class MsFileUtils {
|
|||
public static void validateFileName(String... fileNames) {
|
||||
if (fileNames != null) {
|
||||
for (String fileName : fileNames) {
|
||||
if (StringUtils.isNotEmpty(fileName) && StringUtils.contains(fileName, "." + File.separator)) {
|
||||
if (StringUtils.isNotBlank(fileName) && StringUtils.contains(fileName, "." + File.separator)) {
|
||||
throw new MSException(Translator.get("invalid_parameter"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue