From 13e440f46cee19c8732eff3d5deb577f9c2721c4 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 21 Oct 2026 10:22:00 +0800 Subject: [PATCH] fix: refine access token validation in chat_headers_middleware to handle trailing slashes --- apps/common/middleware/chat_headers_middleware.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/common/middleware/chat_headers_middleware.py b/apps/common/middleware/chat_headers_middleware.py index 904ab229892..1980a66ded2 100644 --- a/apps/common/middleware/chat_headers_middleware.py +++ b/apps/common/middleware/chat_headers_middleware.py @@ -18,8 +18,10 @@ def process_response(self, request, response): if request.path.startswith(CONFIG.get_chat_path()) and not request.path.startswith( CONFIG.get_chat_path() + '/api'): - access_token = request.path.replace(CONFIG.get_chat_path() + '/', '') - if access_token.__contains__('/') or access_token == 'undefined': + # 路由会把 URL 规范成带结尾斜杠的形式,去掉末尾 '/' 后再校验, + # 否则刷新页面时 access_token 会带 '/',标题替换会被跳过、退回默认 MaxKB + access_token = request.path.replace(CONFIG.get_chat_path() + '/', '').rstrip('/') + if access_token == '' or access_token == 'undefined' or '/' in access_token: return response application_access_token = get_application_access_token(access_token, True) if application_access_token is not None: