From 3b64e18b5e3f3e1bb6401ea7f6e681b89411a2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=B5=E6=91=87=E5=B0=8F=E5=AD=90?= <969409112@qq.com> Date: Sun, 26 Jul 2026 20:45:53 +0800 Subject: [PATCH] =?UTF-8?q?chore(security):=20=E7=A7=BB=E9=99=A4=20AI=20?= =?UTF-8?q?=E5=86=85=E7=BD=AE=20Key=20fallback=20+=20=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=A8=A1=E5=9E=8B=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 发布版本不再自动从环境变量读取 VITE_DEEPSEEK_API_KEY 创建默认 DeepSeek provider。 ensureEnvironmentMigration() 改为 no-op(保留方法作为占位)。 用户首次启动必须在「设置 → AI 模型」手动配置 API Key。 migrateLegacy() 保留:用于把用户自己之前存在 localStorage 的旧配置迁移到加密存储, 与内置 Key 是两回事。 附带修正 .env.example 默认模型名:deepseek-v4-flash 是已弃用/不存在的标识符, DeepSeek 官方未发布此模型,统一改为 deepseek-chat。 --- .env.example | 5 ++++- src/main/services/ai-provider-service.ts | 14 ++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 5436001..cd56eb5 100644 --- a/.env.example +++ b/.env.example @@ -6,9 +6,12 @@ VITE_DB_KEY= VITE_AUTO_LOGIN=false # AI API Configuration (Optional, can be entered in UI) +# 注意:发布版本不再自动读取以下环境变量。 +# 如果你只是本地开发想用默认值,可以在自己机器的 .env.local 里填, +# 然后在「设置 → AI 模型」里手动完成"添加供应商"流程。 VITE_DEEPSEEK_API_KEY= VITE_AI_BASE_URL=https://api.deepseek.com -VITE_AI_MODEL=deepseek-v4-flash +VITE_AI_MODEL=deepseek-chat # Message types to filter out (comma separated). Empty means show all message types. VITE_FILTER_MSG_TYPES= diff --git a/src/main/services/ai-provider-service.ts b/src/main/services/ai-provider-service.ts index 5accd30..3335dd9 100644 --- a/src/main/services/ai-provider-service.ts +++ b/src/main/services/ai-provider-service.ts @@ -41,7 +41,6 @@ export class AIProviderService { constructor(private readonly keyStore = new AIProviderKeyStore()) {} list(): AIProviderListResult { - this.ensureEnvironmentMigration() try { const data = this.readMetadata() return { @@ -339,15 +338,10 @@ export class AIProviderService { } private ensureEnvironmentMigration(): void { - const data = this.readMetadata() - if (data.providers.length) return - const apiKey = String(import.meta.env.VITE_DEEPSEEK_API_KEY || '').trim() - if (!apiKey) return - this.migrateLegacy({ - apiKey, - baseUrl: String(import.meta.env.VITE_AI_BASE_URL || ''), - model: String(import.meta.env.VITE_AI_MODEL || '') - }) + // 已禁用:内置环境变量 Key 自动迁移策略。 + // 安全要求:发布给最终用户的版本不应携带任何内置 API Key, + // 必须由用户自己在 UI 里手动配置(或者通过自己的 .env.local 注入)。 + // 保留此方法作为占位,方便后续重新评估。 } private toSummary(