fix: 优化同步上游模型,过滤克隆载荷中的敏感 credentials 字段,规避重写导致脱敏密钥丢失/清空的事故风险
This commit is contained in:
@@ -67,6 +67,12 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
MASK = "***"
|
||||
SECRET_KEYS = {"password", "token", "key", "secret", "api_key"}
|
||||
SENSITIVE_CREDENTIAL_KEYS = {
|
||||
"access_token", "refresh_token", "id_token",
|
||||
"api_key", "session_key", "cookie",
|
||||
"aws_secret_access_key", "aws_session_token",
|
||||
"service_account_json", "service_account", "private_key",
|
||||
}
|
||||
ALGORITHMS = {"max_plus_percent", "average_plus_percent", "min_plus_percent"}
|
||||
|
||||
|
||||
@@ -1391,8 +1397,11 @@ def sync_website_accounts_upstream_models(
|
||||
continue
|
||||
|
||||
# 1. 先安全修复 base_url (不依赖同步模型结果)
|
||||
# 在 remote_acc.get("credentials") 基础上进行修改,保留其他非敏感 credentials (例如 compact_model_mapping)
|
||||
current_creds = dict(remote_acc.get("credentials") or {})
|
||||
# 在 remote_acc.get("credentials") 基础上过滤掉敏感字段,保留其他非敏感 credentials (例如 compact_model_mapping)
|
||||
current_creds = {
|
||||
k: v for k, v in (remote_acc.get("credentials") or {}).items()
|
||||
if k not in SENSITIVE_CREDENTIAL_KEYS
|
||||
}
|
||||
current_creds["base_url"] = upstream_base_url
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user