CVE-2021-27693: Server-Side Request Forgery (SSRF) (CWE-918)
value: Server-side Request Forgery (SSRF) vulnerability in PublicCMS before 4.0.202011.b via /publiccms/admin/ueditor when the action is catchimage.
CWE description: The web server receives a URL or similar request from an upstream component and retrieves the contents of this URL, but it does not sufficiently ensure that the request is being sent to the expected destination.
CVSS v3 base score: 9.8
Published: 2022-09-02T18:15Z
Repository: https://github.com/sanluan/PublicCMS
Language: Java
Files changed: publiccms-parent/publiccms-core/src/main/java/com/publiccms/controller/admin/sys/UeditorAdminController.java
Commit date: 2021-02-24 10:53:02 +0800
Commit message: https://github.com/sanluan/PublicCMS/issues/51
Diff: diff --git a/publiccms-parent/publiccms-core/src/main/java/com/publiccms/controller/admin/sys/UeditorAdminController.java b/publiccms-parent/publiccms-core/src/main/java/com/publiccms/controller/admin/sys/UeditorAdminController.java
index 7d02c96a..03469036 100644
--- a/publiccms-parent/publiccms-core/src/main/java/com/publiccms/controller/admin/sys/UeditorAdminController.java
+++ b/publiccms-parent/publiccms-core/src/main/java/com/publiccms/controller/admin/sys/UeditorAdminController.java
@@ -216,11 +216,12 @@ public class UeditorAdminController {
                     HttpEntity entity = response.getEntity();
                     if (null != entity) {
                         BufferedInputStream inputStream = new BufferedInputStream(entity.getContent());
                         FileType fileType = FileTypeDetector.detectFileType(inputStream);
                         String suffix = fileType.getCommonExtension();
-                        if (CommonUtils.notEmpty(suffix)) {
+                        if (null != fileType.getMimeType() && fileType.getMimeType().startsWith("image/")
+                                && CommonUtils.notEmpty(suffix)) {
                             String fileName = CmsFileUtils.getUploadFileName(suffix);
                             String filePath = siteComponent.getWebFilePath(site, fileName);
                             CmsFileUtils.copyInputStreamToFile(inputStream, filePath);
                             FileSize fileSize = CmsFileUtils.getFileSize(filePath, suffix);
                             logUploadService.save(new LogUpload(site.getId(), admin.getId(), LogLoginService.CHANNEL_WEB_MANAGER,
@@ -236,13 +237,17 @@ public class UeditorAdminController {
                         }
 
                     }
                     EntityUtils.consume(entity);
                 }
-                Map<String, Object> map = getResultMap(true);
-                map.put("list", list);
-                return map;
+                if (list.isEmpty()) {
+                    return getResultMap(false);
+                } else {
+                    Map<String, Object> map = getResultMap(true);
+                    map.put("list", list);
+                    return map;
+                }
             }
         } catch (Exception e) {
             log.error(e.getMessage(), e);
             return getResultMap(false);
         }

Vulnerable code:                         if (CommonUtils.notEmpty(suffix)) {
                Map<String, Object> map = getResultMap(true);
                map.put("list", list);
                return map;
Fixed code:                         if (null != fileType.getMimeType() && fileType.getMimeType().startsWith("image/")
                                && CommonUtils.notEmpty(suffix)) {
                if (list.isEmpty()) {
                    return getResultMap(false);
                } else {
                    Map<String, Object> map = getResultMap(true);
                    map.put("list", list);
                    return map;
                }