feat: 添加 CSP 安全策略 + 统一日志器 + 清理空 catch + 移除明文兼容#2
Merged
Conversation
…logging - Add Content-Security-Policy via onHeadersReceived (production only) Blocks eval, external scripts, object/embed; allows HTTPS/localhost for API calls - Add centralized logger utility (main/utils/logger.ts) - Replace empty catch blocks in main.ts, mainWindow.ts, codexAppServer.ts, LocalSettingsService.ts with structured logger calls - Remove backward compatibility in SecureStorageService: unencrypted values are now discarded instead of being passed through as plaintext
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
继 PR #1 之后的第二轮安全与可维护性改进:
session.defaultSession.webRequest.onHeadersReceived注入严格 CSP,禁止eval、外部脚本注入、object/embed;允许内联样式/脚本(Vue + 主题初始化所需)、HTTPS 和 localhost 用于 API 调用。main/utils/logger.ts):提供debug/info/warn/error四级日志,带 tag 前缀,替代散落的console.warn/error,为后续接入文件日志或上报预留统一入口。main.ts、mainWindow.ts、codexAppServer.ts、LocalSettingsService.ts中的空catch {}为带上下文的logger.warn/error调用。SecureStorageService不再回退读取未加密明文值——未加密的旧值会被丢弃并提示用户重新输入 API Key。Scope
packages/app/src/main/security/contentSecurityPolicy.ts(新增)packages/app/src/main/utils/logger.ts(新增)packages/app/src/main/main.ts(引入 CSP + logger,替换 console + 空 catch)packages/app/src/main/windows/mainWindow.ts(替换空 catch)packages/app/src/main/codexAppServer.ts(替换 stop() 中 6 处空 catch)packages/app/src/main/services/SecureStorageService.ts(移除明文回退)packages/app/src/main/services/LocalSettingsService.ts(加 logger)Verification
pnpm run format:checkpnpm run lintpnpm run typecheckpnpm run test— 30 tests passedScreenshots or Recordings
N/A(无 UI 变更)
Notes
!isDev),避免干扰 Vite HMR 开发体验。Link to Devin session: https://app.devin.ai/sessions/26c0ad2a81d3440eaa67d6f4feb3df33
Requested by: @QinQinChina