wangzhinan недель назад: 2
Родитель
Сommit
828b05e97d

+ 6 - 0
business/base-service/pom.xml

@ -98,6 +98,12 @@
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>2.0.24</version>
        </dependency>
        <!--解析html-->
        <dependency>
            <groupId>org.jsoup</groupId>

+ 28 - 1
business/base-service/src/main/java/com/yihu/jw/file_upload/FileUploadService.java

@ -16,6 +16,8 @@ import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.poi.util.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -81,6 +83,10 @@ public class FileUploadService {
        if (!isFileFlag(fileType)){
            throw new FileWrongFormatException("不符合文件上传格式");
        }
//        PDDocument document = PDDocument.load(inputStream);
//        if (containsXSS(document)){
//            throw new FileWrongFormatException("该PDF文件包含XSS攻击脚本!");
//        }
        long max = 5*1024*1024;
        if(fileSize > max){
@ -167,6 +173,10 @@ public class FileUploadService {
        if (!isFileFlag(fileType)){
            throw new FileWrongFormatException("不符合文件上传格式");
        }
//        PDDocument document = PDDocument.load(inputStream);
//        if (containsXSS(document)){
//            throw new FileWrongFormatException("该PDF文件包含XSS攻击脚本!");
//        }
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(inputStream, fileType, "");
        //解析返回的objectNode
@ -210,6 +220,10 @@ public class FileUploadService {
       if (!isFileFlag(type)){
           throw new FileWrongFormatException("不符合文件上传格式");
       }
//        PDDocument document = PDDocument.load(multipartFile.getInputStream());
//        if (containsXSS(document)){
//            throw new FileWrongFormatException("该PDF文件包含XSS攻击脚本!");
//        }
        String response = request(wlyyUrl + "/upload/chat", multipartFile, type);
        org.json.JSONObject rs = new org.json.JSONObject(response);
@ -519,6 +533,10 @@ public class FileUploadService {
        if (!isFileFlag(type)){
            throw new FileWrongFormatException("不符合文件上传格式");
        }
//        PDDocument document = PDDocument.load(file.getInputStream());
//        if (containsXSS(document)){
//            throw new FileWrongFormatException("该PDF文件包含XSS攻击脚本!");
//        }
        HttpEntity entity = builder.build();
        httpPost.setEntity(entity);
        HttpResponse response = httpClient.execute(httpPost);// 执行提交
@ -667,11 +685,20 @@ public class FileUploadService {
        logger.info(type);
        List img = new ArrayList(Arrays.asList("jpeg","bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx","psd",
                "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp","xls","xlsx","text/plain","mp3","mp4","m4v","avi",
                "ogm","wmv","mpg","webm","ogv","mov","asx","mpeg","image/png","amr","doc","docx","pdf"));
                "ogm","wmv","mpg","webm","ogv","mov","asx","mpeg","image/png","amr","doc","docx"));
        if (!img.contains(type)) {
            return false;
        }
        return true;
    }
    public boolean containsXSS(PDDocument document) throws IOException {
        PDFTextStripper pdfStripper = new PDFTextStripper();
        String text = pdfStripper.getText(document);
        // 检测文本中是否包含恶意脚本
        return text.contains("<script>") || text.contains("javascript:") || text.contains("alert");
    }
}

+ 5 - 0
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/file_upload/FileUploadEndpoint.java

@ -17,6 +17,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -176,6 +177,10 @@ public class FileUploadEndpoint extends EnvelopRestEndpoint {
        if (!fileUploadService.isFileFlag(type1)){
            throw new FileWrongFormatException("不符合文件上传格式");
        }
//        PDDocument document = PDDocument.load(file.getInputStream());
//        if (fileUploadService.containsXSS(document)){
//            throw new FileWrongFormatException("该PDF文件包含XSS攻击脚本!");
//        }
        files.setObjectType(objectType);
        files.setSize(file.getSize());
        files.setTaskId(taskId);