Skip to content

Commit

Permalink
!286 修复远程文件,文件名带有穿越的BUG
Browse files Browse the repository at this point in the history
Merge pull request !286 from 高雄/chuanyue
  • Loading branch information
gitchenjh authored and gitee-org committed Apr 17, 2024
2 parents ab370e6 + b65a048 commit 7bf07cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion server/src/main/java/cn/keking/utils/WebUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ public static String urlEncoderencode(String urlStr) {
urlStr = clearFullfilenameParam(urlStr);
} else {
fullFileName = getFileNameFromURL(urlStr); //获取文件名

}
if (KkFileUtils.isIllegalFileName(fullFileName)) { //判断文件名是否带有穿越漏洞
return null;
}
if (!UrlEncoderUtils.hasUrlEncoded(fullFileName)) { //判断文件名是否转义
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
Expand Down Expand Up @@ -76,7 +77,11 @@ public String onlinePreview(String url, Model model, HttpServletRequest req) {
model.addAttribute("file", fileAttribute);
FilePreview filePreview = previewFactory.get(fileAttribute);
logger.info("预览文件url:{},previewType:{}", fileUrl, fileAttribute.getType());
return filePreview.filePreviewHandle(WebUtils.urlEncoderencode(fileUrl), model, fileAttribute); //统一在这里处理 url
fileUrl =WebUtils.urlEncoderencode(fileUrl);
if (ObjectUtils.isEmpty(fileUrl)) {
return otherFilePreview.notSupportedFile(model, "非法路径,不允许访问");
}
return filePreview.filePreviewHandle(fileUrl, model, fileAttribute); //统一在这里处理 url
}

@GetMapping( "/picturesPreview")
Expand Down

0 comments on commit 7bf07cb

Please sign in to comment.