Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log4j2漏洞升级、修正currentUrl为下载后文件地址进行预览 #350

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ nbdist/

server/src/main/cache/
server/src/main/file/
.DS_Store
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<properties>
<java.version>1.8</java.version>
<spring.boot.version>2.4.2</spring.boot.version>
<log4j2.version>2.17.2</log4j2.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
30 changes: 30 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,41 @@
<version>${spring.boot.version}</version>
<scope>import</scope>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<!-- log4j -->
<dependency>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

系统没有用 log4j 哦,这个不是很必要吧

<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>${log4j2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.keking.service.impl;

import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute;
import cn.keking.model.ReturnResponse;
import cn.keking.service.FilePreview;
Expand Down Expand Up @@ -28,21 +29,24 @@ public PictureFilePreviewImpl(FileHandlerService fileHandlerService, OtherFilePr

@Override
public String filePreviewHandle(String url, Model model, FileAttribute fileAttribute) {
String base_url=ConfigConstants.getBaseUrl();
List<String> imgUrls = new ArrayList<>();
imgUrls.add(url);
String fileKey = fileAttribute.getFileKey();
List<String> zipImgUrls = fileHandlerService.getImgCache(fileKey);
if (!CollectionUtils.isEmpty(zipImgUrls)) {
imgUrls.addAll(zipImgUrls);
}
// 不是http开头,浏览器不能直接访问,需下载到本地
if (url != null && !url.toLowerCase().startsWith("http")) {
// ftp 或 http 文件先下载到本地
if (url != null && (url.toLowerCase().startsWith("http")||url.toLowerCase().startsWith("ftp"))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改后并没改变原来代码表达的含义吧??,这里不是很清楚改动

ReturnResponse<String> response = DownloadUtils.downLoad(fileAttribute, null);
if (response.isFailure()) {
return otherFilePreview.notSupportedFile(model, fileAttribute, response.getMsg());
} else {
String file = fileHandlerService.getRelativePath(response.getContent());
imgUrls.clear();
//xuenhua 修正currentUrl为下载后文件地址进行预览
file=base_url+ "/"+file;
imgUrls.add(file);
model.addAttribute("imgUrls", imgUrls);
model.addAttribute("currentUrl", file);
Expand Down