From d9e6346911fe8cb665d3aa4d9ec2757c4f17c1ce Mon Sep 17 00:00:00 2001 From: fawney19 Date: Thu, 8 Jan 2026 01:53:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=99=8D=E4=BD=8E=20API=20Key=20?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6=E8=87=B3?= =?UTF-8?q?=203=20=E4=B8=AA=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../features/providers/components/KeyFormDialog.vue | 4 ++-- frontend/src/utils/errorParser.ts | 2 +- src/models/endpoint_models.py | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/frontend/src/features/providers/components/KeyFormDialog.vue b/frontend/src/features/providers/components/KeyFormDialog.vue index 3c2c70c..b0e5a5b 100644 --- a/frontend/src/features/providers/components/KeyFormDialog.vue +++ b/frontend/src/features/providers/components/KeyFormDialog.vue @@ -349,8 +349,8 @@ const apiKeyError = computed(() => { } // 如果输入了值,检查长度 - if (apiKey.length < 10) { - return 'API 密钥至少需要 10 个字符' + if (apiKey.length < 3) { + return 'API 密钥至少需要 3 个字符' } return '' diff --git a/frontend/src/utils/errorParser.ts b/frontend/src/utils/errorParser.ts index ad92f41..661ac42 100644 --- a/frontend/src/utils/errorParser.ts +++ b/frontend/src/utils/errorParser.ts @@ -54,7 +54,7 @@ const fieldNameMap: Record = { */ const errorTypeMap: Record string> = { 'string_too_short': (error) => { - const minLength = error.ctx?.min_length || 10 + const minLength = error.ctx?.min_length || 3 return `长度不能少于 ${minLength} 个字符` }, 'string_too_long': (error) => { diff --git a/src/models/endpoint_models.py b/src/models/endpoint_models.py index af3124c..ec6ba55 100644 --- a/src/models/endpoint_models.py +++ b/src/models/endpoint_models.py @@ -134,7 +134,7 @@ class EndpointAPIKeyCreate(BaseModel): """为 Endpoint 添加 API Key""" endpoint_id: str = Field(..., description="Endpoint ID") - api_key: str = Field(..., min_length=10, max_length=500, description="API Key(将自动加密)") + api_key: str = Field(..., min_length=3, max_length=500, description="API Key(将自动加密)") name: str = Field(..., min_length=1, max_length=100, description="密钥名称(必填,用于识别)") # 成本计算 @@ -175,13 +175,9 @@ class EndpointAPIKeyCreate(BaseModel): @classmethod def validate_api_key(cls, v: str) -> str: """验证 API Key 安全性""" - # 移除首尾空白 + # 移除首尾空白(长度校验由 Field min_length 处理) v = v.strip() - # 检查最小长度 - if len(v) < 10: - raise ValueError("API Key 长度不能少于 10 个字符") - # 检查危险字符(SQL 注入防护) dangerous_chars = ["'", '"', ";", "--", "/*", "*/", "<", ">"] for char in dangerous_chars: @@ -219,7 +215,7 @@ class EndpointAPIKeyUpdate(BaseModel): """更新 Endpoint API Key""" api_key: Optional[str] = Field( - default=None, min_length=10, max_length=500, description="API Key(将自动加密)" + default=None, min_length=3, max_length=500, description="API Key(将自动加密)" ) name: Optional[str] = Field(default=None, min_length=1, max_length=100, description="密钥名称") rate_multiplier: Optional[float] = Field(default=None, ge=0.01, description="成本倍率")