Compare commits

...

55 Commits

Author SHA1 Message Date
yang
fcb9b83896 ZIP条目覆盖,补充 2024-08-26 19:27:07 +08:00
yang
e16b890a8d XML外部实体注入 2024-08-26 19:26:34 +08:00
yang
376c47befc 密码管理 2024-08-26 19:26:03 +08:00
yang
674b7165eb 文件上传,白名单待定 2024-08-26 17:15:59 +08:00
yang
bea6d680e9 路径遍历 2024-08-26 17:00:10 +08:00
yang
776e1e6cbc 不安全的随机数,剩余一个缺陷 2024-08-26 16:58:53 +08:00
yang
19c3221153 资源注入、服务器端请求伪造 2024-08-26 16:57:39 +08:00
yang
1482809b0f HTTP响应截断 2024-08-26 16:56:32 +08:00
nisen
83e71dc5d6 Merge branch 'zcwy0716-llf' into yxmaster 2024-07-29 19:47:41 +08:00
nisen
f5f53557b6 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 22:21:06 +08:00
nisen
4b4f30b412 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 22:16:40 +08:00
nisen
6f19ff7b0f Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 22:11:30 +08:00
nisen
f8566d2321 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 22:06:19 +08:00
nisen
d6102d1ce1 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 21:52:10 +08:00
nisen
6521464676 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 21:38:42 +08:00
nisen
b6378b6565 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 21:20:05 +08:00
nisen
66d7f2a3cf Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 20:53:21 +08:00
nisen
faea4f8b2a Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 20:37:09 +08:00
nisen
c203956bc6 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 20:25:00 +08:00
nisen
cf4004f073 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 19:00:39 +08:00
nisen
6bf5ccbcec Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 18:59:20 +08:00
nisen
63867db58e Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 18:45:50 +08:00
nisen
7ef0f976fc Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 18:38:12 +08:00
nisen
5a05ff74b7 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 18:18:17 +08:00
nisen
a93580c387 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 18:04:08 +08:00
nisen
78184d3a11 Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 17:31:26 +08:00
nisen
bcb8b59e8a Merge branch 'zcwy0716-llf' into master-0705 2024-07-26 16:50:18 +08:00
nisen
1025f8f716 Merge branch 'zcwy0716-llf' into master-0705 2024-07-18 17:27:52 +08:00
joshen
4c6f15a707 Merge branch 'zcwy-0613-wjw' into 'master-0705'
新在线课逻辑删除库名

See merge request !115
2024-07-05 19:21:27 +08:00
xiaozhequ
488e6c2872 新在线课逻辑删除库名 2024-07-05 19:20:11 +08:00
joshen
e86afad4ef Merge branch 'zcwy-0613-wjw' into 'master-0705'
新在线课逻辑打印日志

See merge request !114
2024-07-05 19:00:59 +08:00
xiaozhequ
3285c639b9 新在线课逻辑打印日志 2024-07-05 18:59:29 +08:00
joshen
db3695019a Merge branch 'zcwy-0613-wjw' into 'master-0705'
Zcwy 0613 wjw

See merge request !113
2024-07-05 17:52:48 +08:00
xiaozhequ
84dd5cb192 在线课逻辑更改库名 2024-07-05 15:22:55 +08:00
xiaozhequ
407c7693bb 区分新建课 2024-07-04 16:21:48 +08:00
xiaozhequ
564bf42464 hrbp只读权限 2024-07-04 15:06:42 +08:00
xiaozhequ
55717e4dde 删除筛选 2024-07-04 12:33:35 +08:00
xiaozhequ
2698061eae 更改实体类字段 2024-07-04 12:32:44 +08:00
xiaozhequ
eb401d8fdf 新在线课逻辑 2024-07-04 10:55:17 +08:00
xiaozhequ
20374e274a 新在线课逻辑修复bug 2024-07-04 10:31:28 +08:00
xiaozhequ
c7a39a1f22 新在线课修复bug 2024-07-04 09:49:49 +08:00
xiaozhequ
7eb578127d 新在线课逻辑优化2 2024-07-03 16:30:19 +08:00
xiaozhequ
f2be349301 新在线课逻辑优化 2024-07-03 12:46:55 +08:00
xiaozhequ
e0037b8814 课程权限优化 2024-07-03 09:57:59 +08:00
xiaozhequ
0b0bd748d9 新在线课逻辑 2024-07-02 09:42:47 +08:00
xiaozhequ
9fd4171107 新在线课逻辑 2024-07-02 08:56:28 +08:00
xiaozhequ
625c41f466 在线可权限bug 2024-06-24 16:00:23 +08:00
xiaozhequ
f950788e08 课程权限学习路径图保持一致 2024-06-24 14:58:13 +08:00
xiaozhequ
a26ceb86d1 学习路径图保持一致 2024-06-24 14:04:53 +08:00
xiaozhequ
a2317d0b59 在线可权限更改逻辑 2024-06-24 13:47:34 +08:00
xiaozhequ
53c38baf22 修复查询失败bug 2024-06-21 15:46:43 +08:00
xiaozhequ
de69ba1c11 在线课权限查询 2024-06-19 15:34:53 +08:00
xiaozhequ
2fcdb6b4b6 代码还原 2024-06-18 15:49:10 +08:00
xiaozhequ
62884bcc15 所有后台人过滤在线课 2024-06-18 14:56:28 +08:00
xiaozhequ
dd0af3cbef 选择在线可时增加数据权限逻辑 2024-06-13 18:11:41 +08:00
27 changed files with 1985 additions and 1456 deletions

View File

@@ -3,6 +3,7 @@ package com.xboe.module.idconfig;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.NetworkInterface; import java.net.NetworkInterface;
import java.net.SocketException; import java.net.SocketException;
import java.security.SecureRandom;
import java.util.Enumeration; import java.util.Enumeration;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -50,8 +51,10 @@ public class IdGeneratorAutoConfig {
dataCenterId=ipm.getDcNum(); dataCenterId=ipm.getDcNum();
}else { }else {
log.warn("无IP【"+ip+"】的配置的workNum和DataCenterNum,系统自动生成随机数"); log.warn("无IP【"+ip+"】的配置的workNum和DataCenterNum,系统自动生成随机数");
workServerId=RandomUtils.nextInt(0,31); SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
dataCenterId=RandomUtils.nextInt(0,31); workServerId = random.nextInt(31);
dataCenterId = random.nextInt(31);
ipm=new IPMapping(); ipm=new IPMapping();
ipm.setId(md5); ipm.setId(md5);
ipm.setIp(ip); ipm.setIp(ip);

View File

@@ -1,6 +1,8 @@
package com.xboe.module.scorm.cam.load; package com.xboe.module.scorm.cam.load;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -85,6 +87,9 @@ import com.xboe.module.scorm.cam.model.datatype.NonNegativeInteger;
import com.xboe.module.scorm.cam.model.datatype.Token; import com.xboe.module.scorm.cam.model.datatype.Token;
import com.xboe.module.scorm.cam.model.datatype.VCard; import com.xboe.module.scorm.cam.model.datatype.VCard;
import com.xboe.module.scorm.common.CommonUtils; import com.xboe.module.scorm.common.CommonUtils;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
@Slf4j @Slf4j
public class ContentPackageGenerator { public class ContentPackageGenerator {
@@ -119,6 +124,10 @@ public class ContentPackageGenerator {
private String scormPkgDir; private String scormPkgDir;
public ContentPackage generateContentPackageFromFile(String scormPkgDir) { public ContentPackage generateContentPackageFromFile(String scormPkgDir) {
if (scormPkgDir.contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
if (scormPkgDir == null) { if (scormPkgDir == null) {
log.error("scorm package directory is null"); log.error("scorm package directory is null");
return contentPackage; return contentPackage;
@@ -141,6 +150,15 @@ public class ContentPackageGenerator {
Document manifestXml; Document manifestXml;
try { try {
SAXReader reader = new SAXReader(); SAXReader reader = new SAXReader();
reader.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
// 总是返回空的InputSource来忽略外部实体
return new InputSource(new StringReader(""));
}
});
manifestXml = reader.read(manifestXmlFile); manifestXml = reader.read(manifestXmlFile);
} catch (DocumentException e) { } catch (DocumentException e) {

View File

@@ -44,6 +44,10 @@ public class FileUtils {
} }
public static File createFile(String dstPath, String fileName) throws IOException { public static File createFile(String dstPath, String fileName) throws IOException {
if (dstPath.contains("..") || fileName.contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
String[] dirs = fileName.split("/"); String[] dirs = fileName.split("/");
File file = new File(dstPath); File file = new File(dstPath);

View File

@@ -119,6 +119,11 @@ public class SCORMPackageManager {
return null; return null;
} }
if (packagePath.contains("..")) {
// throw new SecurityException("输入路径包含不安全的字符");
return null;
}
// step 1: uncompress // step 1: uncompress
File f=new File(packagePath); File f=new File(packagePath);
if(!f.exists()) { if(!f.exists()) {

View File

@@ -60,6 +60,10 @@ public class ZipUtils {
} }
public static boolean decompressZip(String zipFilePath, String saveFileDir) { public static boolean decompressZip(String zipFilePath, String saveFileDir) {
if (zipFilePath.contains("..") || saveFileDir.contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
if (!isEndWithZip(zipFilePath)) { if (!isEndWithZip(zipFilePath)) {
return false; return false;
} }

View File

@@ -66,6 +66,10 @@ public class ExcelToPdfConverter implements ICourseFileConverter {
@Override @Override
public String convert(String fileType, String filePath) throws Exception{ public String convert(String fileType, String filePath) throws Exception{
if (filePath.contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
if (this.getLicense()) { if (this.getLicense()) {
FileOutputStream fileOS=null; FileOutputStream fileOS=null;
String previewPath = null; String previewPath = null;

View File

@@ -65,6 +65,10 @@ public class PPTToPdfConverter implements ICourseFileConverter {
@Override @Override
public String convert(String fileType, String filePath) throws Exception{ public String convert(String fileType, String filePath) throws Exception{
if (filePath.contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
if (this.getLicense()) { if (this.getLicense()) {
InputStream slides=null; InputStream slides=null;
Presentation pres=null; Presentation pres=null;

View File

@@ -69,6 +69,10 @@ public class WordToPdfConverter implements ICourseFileConverter {
@Override @Override
public String convert(String fileType, String filePath) throws Exception{ public String convert(String fileType, String filePath) throws Exception{
if (filePath.contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
if (this.getLicense()) { if (this.getLicense()) {
File pdfFile=null; File pdfFile=null;
FileOutputStream fileOS=null; FileOutputStream fileOS=null;

View File

@@ -17,5 +17,7 @@ public class UserOrgIds {
private Map<String,Boolean> permissions=new HashMap<String,Boolean>(); private Map<String,Boolean> permissions=new HashMap<String,Boolean>();
private List<String> ids; private List<String> ids;
//hrbp只读权限
private List<String> readIds;
} }

View File

@@ -229,8 +229,10 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
public UserOrgIds getOrgIds() { public UserOrgIds getOrgIds() {
UserOrgIds uids=new UserOrgIds(); UserOrgIds uids=new UserOrgIds();
List<String> orgIds = new ArrayList<>(); List<String> orgIds = new ArrayList<>();
List<String> readIds = new ArrayList<>();
uids.setIds(orgIds); uids.setIds(orgIds);
uids.setReadIds(readIds);
String token = TokenProxy.getToken(request); String token = TokenProxy.getToken(request);
String type="application/json"; String type="application/json";
String[] headers=new String[] {"token",token,"Content-Type",type}; String[] headers=new String[] {"token",token,"Content-Type",type};
@@ -281,7 +283,8 @@ public class OutSideDataServiceImpl implements IOutSideDataService {
while (elements.hasNext()){ while (elements.hasNext()){
String oid=elements.next().asText(); String oid=elements.next().asText();
if(!orgSetIds.contains(oid)) { if(!orgSetIds.contains(oid)) {
orgIds.add(oid); // orgIds.add(oid);
readIds.add(oid);
} }
} }
} }

View File

@@ -26,6 +26,7 @@ import com.xboe.module.boecase.vo.BrowseDurationVo;
import com.xboe.module.boecase.vo.CasesRecommendLaunchVo; import com.xboe.module.boecase.vo.CasesRecommendLaunchVo;
import com.xboe.module.boecase.vo.CasesRecommendPushVo; import com.xboe.module.boecase.vo.CasesRecommendPushVo;
import com.xboe.module.boecase.vo.CasesRecommendVo; import com.xboe.module.boecase.vo.CasesRecommendVo;
import com.xboe.system.aspectj.anno.FileFormatVerification;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.streaming.SXSSFSheet; import org.apache.poi.xssf.streaming.SXSSFSheet;
@@ -117,6 +118,7 @@ public class CasesRecommendApi extends ApiBaseController {
* @return * @return
* @throws Exception * @throws Exception
*/ */
@FileFormatVerification(whites = {"xlsx", "xls"})
@PostMapping("/import") @PostMapping("/import")
public JsonResponse<ImportData> excelImport(@RequestParam("file") MultipartFile file) throws Exception { public JsonResponse<ImportData> excelImport(@RequestParam("file") MultipartFile file) throws Exception {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream()); ExcelReader reader = ExcelUtil.getReader(file.getInputStream());

View File

@@ -227,6 +227,10 @@ public class CourseFileApi extends ApiBaseController {
return badRequest("请先选择资源归属"); return badRequest("请先选择资源归属");
} }
if (file.getFilePath().contains("..")) {
throw new SecurityException("输入路径包含不安全的字符");
}
// 重设文件类型为小写 // 重设文件类型为小写
file.setFileType(file.getFileType().toLowerCase()); file.setFileType(file.getFileType().toLowerCase());
@@ -396,6 +400,13 @@ public class CourseFileApi extends ApiBaseController {
return; return;
} }
if (cf.contains("..")) {
log.error("参数错误");
// throw new SecurityException("输入路径包含不安全的字符");
return;
}
String cfPath=null; String cfPath=null;
String fileName =""; String fileName ="";
if(StringUtils.isNotBlank(cf)) { if(StringUtils.isNotBlank(cf)) {
@@ -436,6 +447,11 @@ public class CourseFileApi extends ApiBaseController {
response.reset(); response.reset();
//由于火狐和其他浏览器显示名称的方式不相同,需要进行不同的编码处理 //由于火狐和其他浏览器显示名称的方式不相同,需要进行不同的编码处理
if (agent.indexOf("FIREFOX") != -1) {//火狐浏览器 if (agent.indexOf("FIREFOX") != -1) {//火狐浏览器
// 检查文件名中是否包含不允许的字符
if (fileName.matches(".*[\n\r;%].*")) {
throw new IllegalArgumentException("Filename contains illegal characters");
}
response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("GB2312"), "ISO-8859-1")); response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("GB2312"), "ISO-8859-1"));
} else {//其他浏览器 } else {//其他浏览器
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")); response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));

View File

@@ -1,11 +1,7 @@
package com.xboe.module.course.api; package com.xboe.module.course.api;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@@ -134,7 +130,6 @@ public class CourseManageApi extends ApiBaseController{
}else { }else {
dto.setIsSystemAdmin(false); dto.setIsSystemAdmin(false);
} }
String ids=""; String ids="";
if(userOrgIds.getIds()!=null && !userOrgIds.getIds().isEmpty()) if(userOrgIds.getIds()!=null && !userOrgIds.getIds().isEmpty())
{ {
@@ -142,12 +137,14 @@ public class CourseManageApi extends ApiBaseController{
} }
//log.info("获取到的用户的组织机构权限ids",ids); //log.info("获取到的用户的组织机构权限ids",ids);
String aid=getCurrent().getAccountId(); String aid=getCurrent().getAccountId();
// String aid="1706272694871445506";
//如果前端查询当前人的,这里去掉 //如果前端查询当前人的,这里去掉
if(StringUtils.isNotBlank(dto.getAid())) { if(StringUtils.isNotBlank(dto.getAid())) {
dto.setAid(null); dto.setAid(null);
} }
dto.setOrgAid(aid); dto.setOrgAid(aid);
dto.setOrgIds(ids); dto.setOrgIds(ids);
dto.setReadIds(userOrgIds.getReadIds());
PageList<Course> coursePageList = courseService.findPage(pager.getPageIndex(), pager.getPageSize(),dto); PageList<Course> coursePageList = courseService.findPage(pager.getPageIndex(), pager.getPageSize(),dto);
return success(coursePageList); return success(coursePageList);
}catch(Exception e) { }catch(Exception e) {

View File

@@ -2,6 +2,8 @@ package com.xboe.module.course.dto;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* 课程查询的条件对象 * 课程查询的条件对象
*/ */
@@ -102,6 +104,9 @@ public class CourseQueryDto {
* */ * */
private String orgIds; private String orgIds;
//hrpb只读
private List<String> readIds;
/**用户权限的查询*/ /**用户权限的查询*/
private String orgAid; private String orgAid;
@@ -110,6 +115,11 @@ public class CourseQueryDto {
*/ */
private Boolean isSystemAdmin; private Boolean isSystemAdmin;
/**
* 是否是新建在线可
*/
private Boolean isCreateCourse;
private Boolean visible; private Boolean visible;
private String refId; private String refId;
@@ -129,4 +139,5 @@ public class CourseQueryDto {
* 登录人id * 登录人id
*/ */
private String userId; private String userId;
} }

View File

@@ -371,6 +371,9 @@ public class Course extends BaseEntity {
@Column(name = "ref_type",length=32,columnDefinition="varchar(32) comment '反向关联的类型'") @Column(name = "ref_type",length=32,columnDefinition="varchar(32) comment '反向关联的类型'")
private String refType; private String refType;
@Transient
private Boolean isPermission=true;
@Transient @Transient
private String orgName; private String orgName;

View File

@@ -8,6 +8,7 @@ import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.xboe.system.aspectj.anno.FileFormatVerification;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
@@ -148,6 +149,7 @@ public class ExamQuestionApi extends ApiBaseController {
/** /**
* 导入 * 导入
* */ * */
@FileFormatVerification(whites = {"xls","xlsx"})
@PostMapping("/import") @PostMapping("/import")
public JsonResponse<QuestionDto> importQuestion(@RequestParam MultipartFile file){ public JsonResponse<QuestionDto> importQuestion(@RequestParam MultipartFile file){
//获取输入流 //获取输入流

View File

@@ -8,6 +8,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import com.xboe.system.aspectj.anno.FileFormatVerification;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@@ -281,6 +282,7 @@ public class XFileBaseApi extends ApiBaseController{
return wrap(list); return wrap(list);
} }
@FileFormatVerification(whites = {"zip","png","jpg","jpeg","gif","svg","bmp"})
@ApiAccess(path="xfile.file.upload") @ApiAccess(path="xfile.file.upload")
@RequestMapping(value="/file/upload", method={RequestMethod.POST}) @RequestMapping(value="/file/upload", method={RequestMethod.POST})
public JsonResponse<ListViewItem> fileUpload(HttpServletRequest request,String folderId) { public JsonResponse<ListViewItem> fileUpload(HttpServletRequest request,String folderId) {

View File

@@ -11,6 +11,7 @@ import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.xboe.system.aspectj.anno.FileFormatVerification;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@@ -198,6 +199,7 @@ public class UserGroupApi extends ApiBaseController {
* 不直接导入到数据库,而是解析文件并查询相应数据返回 * 不直接导入到数据库,而是解析文件并查询相应数据返回
* @return * @return
*/ */
@FileFormatVerification(whites = {"xlsx","xls"})
@PostMapping("/import") @PostMapping("/import")
public JsonResponse<Iterable<UserImportDto>> importUserGroup(@RequestParam MultipartFile file) { public JsonResponse<Iterable<UserImportDto>> importUserGroup(@RequestParam MultipartFile file) {

View File

@@ -14,8 +14,10 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.xboe.system.aspectj.anno.FileFormatVerification;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@@ -44,6 +46,9 @@ public class SysUploaderApi extends ApiBaseController{
@Autowired @Autowired
XFileUploader uploader; XFileUploader uploader;
@Value(value = "${boe.domain}")
String domain;
private static Set<String> fileTypeSet=new HashSet<>(); private static Set<String> fileTypeSet=new HashSet<>();
static { static {
fileTypeSet.add("mp3"); fileTypeSet.add("mp3");
@@ -62,6 +67,7 @@ public class SysUploaderApi extends ApiBaseController{
fileTypeSet.add("zip"); fileTypeSet.add("zip");
} }
@FileFormatVerification(whites = {"mp3","wmv","mp4","jpg","png","gif","doc","docx","xls","xlsx","ppt","pptx","pdf","zip"})
@RequestMapping(value = "/file/upload", method = RequestMethod.POST) @RequestMapping(value = "/file/upload", method = RequestMethod.POST)
public JsonResponse<XUploadResult> save(HttpServletRequest request, String name,String dir) throws IOException { public JsonResponse<XUploadResult> save(HttpServletRequest request, String name,String dir) throws IOException {
//以下三项用于回调 //以下三项用于回调
@@ -150,6 +156,7 @@ public class SysUploaderApi extends ApiBaseController{
public void urlDownload(HttpServletResponse res,String urlStr,String fileName) throws IOException { public void urlDownload(HttpServletResponse res,String urlStr,String fileName) throws IOException {
URL url = new URL(urlStr); URL url = new URL(urlStr);
downloadLimitation(url);
HttpURLConnection conn = (HttpURLConnection)url.openConnection(); HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置超时间为3秒 //设置超时间为3秒
conn.setConnectTimeout(3*1000); conn.setConnectTimeout(3*1000);
@@ -193,4 +200,19 @@ public class SysUploaderApi extends ApiBaseController{
//System.out.println("success"); //System.out.println("success");
} }
private void downloadLimitation(URL url) {
String allowedDomain = domain;
String allowedPathPrefix = "/upload/xfile/";
// 检查域名是否正确
if (!url.getHost().equals(allowedDomain)) {
throw new SecurityException("Download from this domain is not allowed.");
}
// 检查路径是否以允许的路径前缀开始
if (!url.getPath().startsWith(allowedPathPrefix)) {
throw new SecurityException("Download from this path is not allowed.");
}
}
} }

View File

@@ -0,0 +1,91 @@
package com.xboe.system.aspectj;
import com.xboe.system.aspectj.anno.FileFormatVerification;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
/**
* @author admin
*/
@Aspect
@Slf4j
@Component
public class UploadAspect {
@Pointcut("@annotation(com.xboe.system.aspectj.anno.FileFormatVerification)")
private void fileUpload() {
}
@Before("fileUpload()")
public void fileFormatVerifies(JoinPoint joinPoint) {
List<String> whiteList = getWhiteList(joinPoint);
String[] FILE_UPLOAD_BLACKLIST = {"exe", "sh", "py", "html", "xhtml", "php", "php5", "dat", "dbf", "dev", "asp", "aspx", "asa", "aspx", "ashx", "asmx", "asax", "ascx", "jsp", "jspx", "jspf", "cgi", "war", "ini", "js"};
List<String> blackList = Arrays.asList(FILE_UPLOAD_BLACKLIST);
// 在目标方法执行前执行的代码
Object[] args = joinPoint.getArgs(); // 获取被调用方法的参数
// 处理MultipartFile
Arrays.stream(args)
.filter(arg -> arg instanceof MultipartFile)
.map(arg -> (MultipartFile) arg)
.forEach(file -> {
String name = file.getOriginalFilename();
String fileSuffix = name.substring(name.lastIndexOf(".") + 1);
if (blackList.contains(fileSuffix) || !whiteList.contains(fileSuffix)) {
throw new RuntimeException("文件格式不支持");
}
});
// 处理HttpServletRequest中的文件名
Arrays.stream(args)
.filter(arg -> arg instanceof HttpServletRequest)
.map(arg -> (HttpServletRequest) arg)
.filter(req -> req instanceof MultipartHttpServletRequest)
.map(req -> (MultipartHttpServletRequest) req)
.forEach(req -> {
req.getFileMap().forEach((k, v) -> {
String fileSuffix = v.getOriginalFilename().substring(v.getOriginalFilename().lastIndexOf(".") + 1);
if (blackList.contains(fileSuffix) || !whiteList.contains(fileSuffix)) {
throw new RuntimeException("文件格式不支持");
}
});
});
int i = 1 / 0;
}
private static List<String> getWhiteList(JoinPoint joinPoint) {
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getMethod();
// 获取FileFormatVerification注解
FileFormatVerification annotation = method.getAnnotation(FileFormatVerification.class);
// 获取whiteList属性
String[] whites = annotation.whites();
List<String> whiteList = Arrays.asList(whites);
return whiteList;
}
}

View File

@@ -0,0 +1,15 @@
package com.xboe.system.aspectj.anno;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.METHOD) // 注解目标为方法
@Retention(RetentionPolicy.RUNTIME) // 注解在运行时有效
public @interface FileFormatVerification {
String[] whites() default {};
}

View File

@@ -4,7 +4,7 @@ spring.redis.database=1
#spring.redis.password=ENC(zA5LNV8xw3yEx6LMwdGGBGgNsOaD3Cg+) #spring.redis.password=ENC(zA5LNV8xw3yEx6LMwdGGBGgNsOaD3Cg+)
#spring.redis.port=6379 #spring.redis.port=6379
spring.redis.host=124.70.92.162 spring.redis.host=124.70.92.162
spring.redis.password=qwert!W577 spring.redis.password=ENC(5oXfdmgE2DDHUFhrGkS/UzUCxr7s8stV)
spring.redis.port=6379 spring.redis.port=6379
# cloud nacos config # cloud nacos config
@@ -20,7 +20,7 @@ spring.datasource.driverClassName=com.mysql.jdbc.Driver
#spring.datasource.password=ENC(lAoFOYuc8CAypPtigTNLYg==) #spring.datasource.password=ENC(lAoFOYuc8CAypPtigTNLYg==)
spring.datasource.url=jdbc:mysql://10.251.160.40:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull spring.datasource.url=jdbc:mysql://10.251.160.40:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=admin spring.datasource.username=admin
spring.datasource.password=boeRds01 spring.datasource.password=ENC(GrOwKqgCAlYEZYjiDYWEjVcKho+5TLgc)
logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

View File

@@ -1,7 +1,7 @@
## redis ## redis
spring.redis.database=1 spring.redis.database=1
spring.redis.host=10.251.160.38 spring.redis.host=10.251.160.38
spring.redis.password=qwert!W577 spring.redis.password=ENC(5oXfdmgE2DDHUFhrGkS/UzUCxr7s8stV)
spring.redis.port=6379 spring.redis.port=6379
#spring.redis.database=3 #spring.redis.database=3
#spring.redis.host=10.251.129.122 #spring.redis.host=10.251.129.122
@@ -17,7 +17,7 @@ spring.datasource.driverClassName=com.mysql.jdbc.Driver
# spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver # spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://10.251.129.126:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull spring.datasource.url=jdbc:mysql://10.251.129.126:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=admin spring.datasource.username=admin
spring.datasource.password=boeRds01 spring.datasource.password=ENC(GrOwKqgCAlYEZYjiDYWEjVcKho+5TLgc)
logging.level.org.hibernate.SQL=ERROR logging.level.org.hibernate.SQL=ERROR
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE #logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

View File

@@ -4,7 +4,7 @@ spring.cloud.nacos.discovery.server-addr=10.251.129.51:8848
## redis ## redis
spring.redis.database=1 spring.redis.database=1
spring.redis.host=10.251.129.122 spring.redis.host=10.251.129.122
spring.redis.password=qwert!W588 spring.redis.password=ENC(e1k00MMRGU0DUHvLX8JSOuDkCX0CWNif)
spring.redis.port=6379 spring.redis.port=6379
@@ -18,7 +18,7 @@ spring.datasource.driverClassName=com.mysql.jdbc.Driver
#spring.datasource.password=ocYMC>!{8G #spring.datasource.password=ocYMC>!{8G
spring.datasource.url=jdbc:mysql://10.251.129.126:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull spring.datasource.url=jdbc:mysql://10.251.129.126:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=admin spring.datasource.username=admin
spring.datasource.password=boeRds01 spring.datasource.password=ENC(GrOwKqgCAlYEZYjiDYWEjVcKho+5TLgc)
## 使用 hikari 连接池 ## 使用 hikari 连接池
spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.type=com.zaxxer.hikari.HikariDataSource

View File

@@ -1,7 +1,7 @@
## redis ## redis
spring.redis.database=1 spring.redis.database=1
spring.redis.host=10.251.160.38 spring.redis.host=10.251.160.38
spring.redis.password=qwert!W577 spring.redis.password=ENC(oXmZ5HIrhizHQ/DWPNv/S/1hUNJbbRjv)
spring.redis.port=6379 spring.redis.port=6379
# cloud nacos config # cloud nacos config
@@ -13,7 +13,7 @@ spring.datasource.driverClassName=com.mysql.jdbc.Driver
# spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver # spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://10.251.160.40:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull spring.datasource.url=jdbc:mysql://10.251.160.40:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=admin spring.datasource.username=admin
spring.datasource.password=boeRds01 spring.datasource.password=ENC(GrOwKqgCAlYEZYjiDYWEjVcKho+5TLgc)
## 使用 hikari 连接池 ## 使用 hikari 连接池
spring.datasource.type=com.zaxxer.hikari.HikariDataSource spring.datasource.type=com.zaxxer.hikari.HikariDataSource
@@ -72,7 +72,7 @@ jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator
xboe.elasticsearch.server.ip=10.251.129.25 xboe.elasticsearch.server.ip=10.251.129.25
xboe.elasticsearch.server.port=9200 xboe.elasticsearch.server.port=9200
xboe.elasticsearch.server.user=elastic xboe.elasticsearch.server.user=elastic
xboe.elasticsearch.server.password=Boe@es123 xboe.elasticsearch.server.password=ENC(903xqMcg31J+OhmZ0AoinYqvzLoAt8UZ)
## 邮件的配置 ## 邮件的配置
xboe.email.url=https://u-pre.boe.com/api/b1/email/send xboe.email.url=https://u-pre.boe.com/api/b1/email/send

View File

@@ -1,7 +1,7 @@
## redis ## redis
spring.redis.database=2 spring.redis.database=2
spring.redis.host=10.251.160.38 spring.redis.host=10.251.160.38
spring.redis.password=qwert!W577 spring.redis.password=ENC(5oXfdmgE2DDHUFhrGkS/UzUCxr7s8stV)
spring.redis.port=6379 spring.redis.port=6379
## datasource config ## datasource config
@@ -10,7 +10,7 @@ spring.datasource.driverClassName=com.mysql.jdbc.Driver
# spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver # spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://10.251.160.40:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull spring.datasource.url=jdbc:mysql://10.251.160.40:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
spring.datasource.username=admin spring.datasource.username=admin
spring.datasource.password=boeRds01 spring.datasource.password=ENC(GrOwKqgCAlYEZYjiDYWEjVcKho+5TLgc)
logging.level.org.hibernate.SQL=DEBUG logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
@@ -60,7 +60,7 @@ jasypt.encryptor.iv-generator-classname=org.jasypt.iv.NoIvGenerator
xboe.elasticsearch.server.ip=10.251.129.25 xboe.elasticsearch.server.ip=10.251.129.25
xboe.elasticsearch.server.port=9200 xboe.elasticsearch.server.port=9200
xboe.elasticsearch.server.user=elastic xboe.elasticsearch.server.user=elastic
xboe.elasticsearch.server.password=Boe@es123 xboe.elasticsearch.server.password=ENC(903xqMcg31J+OhmZ0AoinYqvzLoAt8UZ)
## 邮件的配置 ## 邮件的配置
xboe.email.url=https://10.251.160.135/api/b1/email/send xboe.email.url=https://10.251.160.135/api/b1/email/send