Skip to content

Commit

Permalink
fix: Enhance API key validation in is_any_api_key function (#2113)
Browse files Browse the repository at this point in the history
  • Loading branch information
SakuraPuare authored Jan 29, 2025
1 parent 5ddd657 commit 44fe78f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions shared_utils/key_pattern_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def is_cohere_api_key(key):


def is_any_api_key(key):
# key 一般只包含字母、数字、下划线、逗号、中划线
if not re.match(r"^[a-zA-Z0-9_\-,]+$", key):
# 如果配置了 CUSTOM_API_KEY_PATTERN,再检查以下以免误杀
if CUSTOM_API_KEY_PATTERN := get_conf('CUSTOM_API_KEY_PATTERN'):
return bool(re.match(CUSTOM_API_KEY_PATTERN, key))
return False

if ',' in key:
keys = key.split(',')
for k in keys:
Expand Down

0 comments on commit 44fe78f

Please sign in to comment.