Skip to content

Commit 98c5863

Browse files
committed
fix: refine access token validation in chat_headers_middleware to handle trailing slashes
1 parent 9213f80 commit 98c5863

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎apps/common/middleware/chat_headers_middleware.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ def process_response(self, request, response):
1818

1919
if request.path.startswith(CONFIG.get_chat_path()) and not request.path.startswith(
2020
CONFIG.get_chat_path() + '/api'):
21-
access_token = request.path.replace(CONFIG.get_chat_path() + '/', '')
22-
if access_token.__contains__('/') or access_token == 'undefined':
21+
# 路由会把 URL 规范成带结尾斜杠的形式,去掉末尾 '/' 后再校验,
22+
# 否则刷新页面时 access_token 会带 '/',标题替换会被跳过、退回默认 MaxKB
23+
access_token = request.path.replace(CONFIG.get_chat_path() + '/', '').rstrip('/')
24+
if access_token == '' or access_token == 'undefined' or '/' in access_token:
2325
return response
2426
application_access_token = get_application_access_token(access_token, True)
2527
if application_access_token is not None:

0 commit comments

Comments
 (0)