From 6920ed4c0de5fdffe26c0a1748bc98be0804bab3 Mon Sep 17 00:00:00 2001 From: wanghu Date: Fri, 4 Sep 2026 12:04:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E8=B7=B3=E7=99=BD=E5=90=8D=E5=8D=95?= =?UTF-8?q?=E6=94=BE=E8=A1=8C=E6=9C=AC=E6=9C=BA=E8=81=94=E8=B0=83=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=EF=BC=9A=E5=AE=8C=E6=95=B4=20http(s)=20=E5=9B=9E?= =?UTF-8?q?=E8=B7=B3=E7=9B=AE=E6=A0=87=E5=85=81=E8=AE=B8=20Uri.IsLoopback(?= =?UTF-8?q?localhost/127.0.0.1/::1)=EF=BC=8C=E6=9C=AC=E5=9C=B0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E8=B0=83=E7=BA=BF=E4=B8=8A=20docprint=20API=20?= =?UTF-8?q?=E7=9A=84=E7=99=BB=E5=BD=95=E9=93=BE=E5=8F=AF=E5=9B=9E=E5=88=B0?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E9=A1=B5=EF=BC=9B=E5=A4=96=E7=AB=99=20host?= =?UTF-8?q?=20=E4=BB=8D=E6=8B=92=E7=BB=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs b/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs index 03bf204..94c11a4 100644 --- a/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs +++ b/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs @@ -266,8 +266,10 @@ namespace YhCore.WebApi.Auth /// /// 判定回跳目标是否允许: /// 1. 本地相对路径(/xxx 开头):拒绝协议相对地址(//host)与反斜杠变体(/\…)——原有安全口径; - /// 2. 完整 http(s) URL:host 必须与 service 根 host(AppBaseUrl 或当前请求)一致——供前端页完整 - /// 地址(yschreferer 携带,含 #/ 路由片段)作回跳目标,杜绝开放重定向到任意外站。 + /// 2. 完整 http(s) URL:host 须与 service 根 host(AppBaseUrl 或当前请求)一致,或为本机联调地址 + /// (localhost / 127.0.0.1 / ::1,Uri.IsLoopback)——前端页完整地址(yschreferer 携带,含 #/ + /// 路由片段)作回跳目标;放行本机地址以支持"本地页面调线上 docprint API"的联调登录链 + /// (redirectToReferer 解析后为 http://localhost:PORT/),外站 host 仍拒绝,杜绝开放重定向。 /// 其余情况(null/空、非 http(s) 协议、外站 host)一律拒绝。 /// 防御:含控制字符(0x00-0x1F / 0x7F)的目标一律拒绝——hex 解码产物(平台 char 维度 hex 对 /// 非 ASCII 码点有损,可能还原出控制字符)或手工构造的畸形 URL,Uri 解析/302 Location 序列化 @@ -300,7 +302,8 @@ namespace YhCore.WebApi.Auth return false; } return string.IsNullOrEmpty(allowedHost) - || string.Equals(uri.Host, allowedHost, StringComparison.OrdinalIgnoreCase); + || string.Equals(uri.Host, allowedHost, StringComparison.OrdinalIgnoreCase) + || uri.IsLoopback; } /// service 根地址的 host(回跳白名单基准):AppBaseUrl 未配置时取当前请求 host。