fix(auth): 未配置 api_key 时使用默认密钥 grok2api

修复安全问题:移除空值跳过验证逻辑,确保 API 始终需要认证。
同步更新 readme 中 api_key 默认值文档。
This commit is contained in:
piexian committed 2026-02-04 07:47:54 +08:00
1 parent d25d2eae18
commit 4cbfd49fef
2 files changed
+3 -8

No files matched your search

+2 -7
View File
@@ -22,14 +22,9 @@ async def verify_api_key(
"""
验证 Bearer Token
如果 config.toml 中未配置 api_key,则跳过验证。
如果配置了 api_key,则必须提供正确的 Authorization: Bearer <key>。
如果 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(
+1 -1
View File
@@ -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` |