escaping of dangerous characters

xss
ale 2021-01-15 21:32:41 +01:00 committed by kl
parent 8bd36e37a3
commit e635ca86c5
2 changed files with 9 additions and 0 deletions

View File

@ -62,6 +62,11 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>3.7</version> <version>3.7</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
<!-- REDISSON --> <!-- REDISSON -->
<dependency> <dependency>
<groupId>org.redisson</groupId> <groupId>org.redisson</groupId>

View File

@ -16,6 +16,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import org.apache.commons.text.StringEscapeUtils;
/** /**
* *
@ -36,6 +37,9 @@ public class FileController {
// 获取文件名 // 获取文件名
String fileName = file.getOriginalFilename(); String fileName = file.getOriginalFilename();
//判断是否为IE浏览器的文件名IE浏览器下文件名会带有盘符信息 //判断是否为IE浏览器的文件名IE浏览器下文件名会带有盘符信息
// escaping dangerous characters to prevent XSS
fileName = StringEscapeUtils.escapeHtml4(fileName);
// Check for Unix-style path // Check for Unix-style path
int unixSep = fileName.lastIndexOf('/'); int unixSep = fileName.lastIndexOf('/');
// Check for Windows-style path // Check for Windows-style path