From 6298ab5f4f0ffb7223a6bb38a475c85993e50924 Mon Sep 17 00:00:00 2001 From: scott Date: Sat, 24 Oct 2026 05:34:35 -0400 Subject: [PATCH] =?UTF-8?q?fix(airag):=20AI=20=E8=81=8A=E5=A4=A9=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=9B=BE=E7=89=87=E6=94=B9=E7=94=A8=E7=A6=81=E6=AD=A2?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BD=AC=E3=80=81=E9=80=90=E8=B7=B3?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E7=9A=84=E5=AE=89=E5=85=A8=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=20SSRF=20=E9=87=8D=E5=AE=9A?= =?UTF-8?q?=E5=90=91=E7=BB=95=E8=BF=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../airag/llm/handler/AIChatHandler.java | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/AIChatHandler.java b/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/AIChatHandler.java index ba3128dfb..c913d9371 100644 --- a/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/AIChatHandler.java +++ b/jeecg-boot/jeecg-boot-module/jeecg-boot-module-airag/src/main/java/org/jeecg/modules/airag/llm/handler/AIChatHandler.java @@ -13,6 +13,7 @@ import org.jeecg.ai.handler.LLMHandler; import org.jeecg.common.exception.JeecgBootBizTipException; import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.util.AssertUtils; +import org.jeecg.common.util.FileDownloadUtils; import org.jeecg.common.util.filter.SsrfFileTypeFilter; import org.jeecg.common.util.oConvertUtils; import org.jeecg.config.AiChatConfig; @@ -654,20 +655,11 @@ public class AIChatHandler implements IAIChatHandler { //update-begin---author:zhangdaihao ---date:2026-08-06 for:【issues/9805】AI图生图imageUrl未校验导致SSRF,增加URL安全校验----------- SsrfFileTypeFilter.checkSsrfHttpUrl(imageUrl); //update-end---author:zhangdaihao ---date:2026-08-06 for:【issues/9805】AI图生图imageUrl未校验导致SSRF,增加URL安全校验----------- - java.net.URL url = new java.net.URL(imageUrl); - java.net.URLConnection conn = url.openConnection(); - conn.setConnectTimeout(5000); - conn.setReadTimeout(10000); - try (java.io.InputStream in = conn.getInputStream()) { - java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream(); - int nRead; - byte[] data = new byte[1024]; - while ((nRead = in.read(data, 0, data.length)) != -1) { - buffer.write(data, 0, nRead); - } - buffer.flush(); - fileContent = buffer.toByteArray(); - } + //update-begin---author:wangshuai ---date:20261015 for:只校验初始URL、openConnection默认跟随302导致SSRF重定向绕过,改用禁止自动跳转且逐跳SSRF校验的安全下载----------- + // 原裸 openConnection 默认自动跟随 3xx 且跳转目标不复检,攻击者用跳板 302 跳到 127.0.0.1、169.254.169.254(云元数据) 即可绕过上面的初始校验; + // download2BytesFromNet 内部禁止自动跳转,并对初始URL及每一跳重定向目标都做SSRF校验(与 #9681 同口径)。 + fileContent = FileDownloadUtils.download2BytesFromNet(imageUrl); + //update-end---author:wangshuai ---date:20261015 for:只校验初始URL、openConnection默认跟随302导致SSRF重定向绕过,改用禁止自动跳转且逐跳SSRF校验的安全下载----------- } else { //update-begin---author:liusq ---date:2026-03-30 for:【issues/9431】修复getFirstImageBase64路径遍历漏洞(CWE-22)----------- // 本地文件