Ludc
9 小时以前 9bb1ee8d456d1a6c1149963eeb9c8285844466ef
Source/UBCS/ubcs-common/src/main/java/com/vci/ubcs/common/validator/ComprehensiveFileValidator.java
@@ -21,7 +21,7 @@
   /**
    * 文件白名单
    */
   @Value("${app.upload.security.allowed-extensions:jpg,jpeg,png,pdf}")
   @Value("${app.upload.security.allowed-extensions:xls,xlsx,jar,doc,docx,jpg,jpeg,png,pdf}")
   private String allowedExtensionsConfig;
   /**
@@ -274,9 +274,13 @@
   private boolean contentSecurityValidation(MultipartFile file, UploadValidationResult result) {
      // 内容类型验证
      if (validateContentType && !validateContentType(file)) {
         result.setMessage("文件内容类型不匹配");
         return false;
      if (validateContentType) { //配置了校验位true
         //后缀不在白名单中,并且文件内容与类型不匹配直接返回
         String finalExtension = getFinalExtension(file.getOriginalFilename().toLowerCase());
         if(!allowedExtensions.contains(finalExtension) && !validateContentType(file)){
            result.setMessage("文件内容类型不匹配[后缀:"+finalExtension+";ContentType:"+file.getContentType()+"]");
            return false;
         }
      }
      // 文件头验证
@@ -313,9 +317,11 @@
         if (declaredType == null) {
            return true; // 没有声明类型,放过
         }
         log.info("===========================ContentType: " + declaredType);
         // 简单的类型匹配检查
         String finalExtension = getFinalExtension(file.getOriginalFilename()).toLowerCase();
         log.info("===========================finalExtension: " + finalExtension);
         return isContentTypeConsistent(declaredType, finalExtension);
      } catch (Exception e) {
         log.error("内容类型验证失败", e);