From 4cbfd49fefa136ebe17469ae95935033293d7c02 Mon Sep 17 00:00:00 2001 From: piexian <64474352+piexian@users.noreply.github.com> Date: Wed, 4 Feb 2026 07:47:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E6=9C=AA=E9=85=8D=E7=BD=AE=20api?= =?UTF-8?q?=5Fkey=20=E6=97=B6=E4=BD=BF=E7=94=A8=E9=BB=98=E8=AE=A4=E5=AF=86?= =?UTF-8?q?=E9=92=A5=20grok2api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复安全问题:移除空值跳过验证逻辑,确保 API 始终需要认证。 同步更新 readme 中 api_key 默认值文档。 --- app/core/auth.py | 9 ++------- readme.md | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/core/auth.py b/app/core/auth.py index 9a07f5a..7c96460 100644 --- a/app/core/auth.py +++ b/app/core/auth.py @@ -22,14 +22,9 @@ async def verify_api_key( """ 验证 Bearer Token - 如果 config.toml 中未配置 api_key,则跳过验证。 - 如果配置了 api_key,则必须提供正确的 Authorization: Bearer 。 + 如果 config.toml 中未配置 api_key,则使用默认密钥 "grok2api"。 """ - api_key = get_config("app.api_key", "") - - # 如果未配置 API Key,直接放行 - if not api_key: - return None + api_key = get_config("app.api_key", "grok2api") if not auth: raise HTTPException( diff --git a/readme.md b/readme.md index 9fad490..976ffa2 100644 --- a/readme.md +++ b/readme.md @@ -188,7 +188,7 @@ curl http://localhost:8000/v1/images/generations \ | :-------------------- | :--------------------------- | :----------- | :--------------------------------------------------- | :-------------------------------------------------------- | | **app** | `app_url` | 应用地址 | 当前 Grok2API 服务的外部访问 URL,用于文件链接访问。 | `http://127.0.0.1:8000` | | | `app_key` | 后台密码 | 登录 Grok2API 服务管理后台的密码,请妥善保管。 | `grok2api` | -| | `api_key` | API 密钥 | 调用 Grok2API 服务所需的 Bearer Token,请妥善保管。 | `""` | +| | `api_key` | API 密钥 | 调用 Grok2API 服务所需的 Bearer Token,请妥善保管。 | `grok2api` | | | `image_format` | 图片格式 | 生成的图片格式(url 或 base64)。 | `url` | | | `video_format` | 视频格式 | 生成的视频格式(仅支持 url)。 | `url` | | **grok** | `temporary` | 临时对话 | 是否启用临时对话模式。 | `true` |