From 70ccd1cb8e2976516f70fabc08691e7d5ccf7f28 Mon Sep 17 00:00:00 2001 From: wanghu Date: Fri, 4 Sep 2026 11:53:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E8=B7=B3=E7=9B=AE=E6=A0=87=E5=81=A5?= =?UTF-8?q?=E5=A3=AE=E6=80=A7=EF=BC=9AIsAllowedReturnTarget=20=E6=8B=92?= =?UTF-8?q?=E7=BB=9D=E5=90=AB=E6=8E=A7=E5=88=B6=E5=AD=97=E7=AC=A6(0x00-0x1?= =?UTF-8?q?F/0x7F)=E7=9A=84=E7=95=B8=E5=BD=A2=E5=9C=B0=E5=9D=80=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=20Uri=20=E8=A7=A3=E6=9E=90/302=20=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E5=BC=82=E5=B8=B8=E5=AF=BC=E8=87=B4=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs b/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs index 4e2a255..03bf204 100644 --- a/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs +++ b/src/YhCore.WebApi/Auth/Cas/CasAuthenticationHandler.cs @@ -269,6 +269,9 @@ namespace YhCore.WebApi.Auth /// 2. 完整 http(s) URL:host 必须与 service 根 host(AppBaseUrl 或当前请求)一致——供前端页完整 /// 地址(yschreferer 携带,含 #/ 路由片段)作回跳目标,杜绝开放重定向到任意外站。 /// 其余情况(null/空、非 http(s) 协议、外站 host)一律拒绝。 + /// 防御:含控制字符(0x00-0x1F / 0x7F)的目标一律拒绝——hex 解码产物(平台 char 维度 hex 对 + /// 非 ASCII 码点有损,可能还原出控制字符)或手工构造的畸形 URL,Uri 解析/302 Location 序列化 + /// 都可能抛异常导致 500,此处前置拦截并安全降级(调用方回根路径或原 URL)。 /// private static bool IsAllowedReturnTarget(string url, string allowedHost) { @@ -276,6 +279,13 @@ namespace YhCore.WebApi.Auth { return false; } + foreach (var ch in url) + { + if (ch < 0x20 || ch == 0x7f) + { + return false; + } + } if (url[0] == '/') { return !url.StartsWith("//", StringComparison.Ordinal)