Skip to content

feat: 添加 CSP 安全策略 + 统一日志器 + 清理空 catch + 移除明文兼容#2

Merged
QinQinChina merged 1 commit into
mainfrom
devin/1780829830-security-and-logging
Jun 7, 2026
Merged

feat: 添加 CSP 安全策略 + 统一日志器 + 清理空 catch + 移除明文兼容#2
QinQinChina merged 1 commit into
mainfrom
devin/1780829830-security-and-logging

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

继 PR #1 之后的第二轮安全与可维护性改进:

  1. Content-Security-Policy:生产环境通过 session.defaultSession.webRequest.onHeadersReceived 注入严格 CSP,禁止 eval、外部脚本注入、object/embed;允许内联样式/脚本(Vue + 主题初始化所需)、HTTPS 和 localhost 用于 API 调用。
  2. 统一日志器 (main/utils/logger.ts):提供 debug/info/warn/error 四级日志,带 tag 前缀,替代散落的 console.warn/error,为后续接入文件日志或上报预留统一入口。
  3. 清理空 catch:替换 main.tsmainWindow.tscodexAppServer.tsLocalSettingsService.ts 中的空 catch {} 为带上下文的 logger.warn/error 调用。
  4. 移除明文兼容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:check
  • pnpm run lint
  • pnpm run typecheck
  • pnpm run test — 30 tests passed

Screenshots or Recordings

N/A(无 UI 变更)

Notes

  • CSP 仅在生产环境生效(!isDev),避免干扰 Vite HMR 开发体验。
  • 明文兼容移除后,使用旧版本的用户需在设置中重新输入 API Key(一次性迁移代价),之后全部走 DPAPI 加密。

Link to Devin session: https://app.devin.ai/sessions/26c0ad2a81d3440eaa67d6f4feb3df33
Requested by: @QinQinChina

…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
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@QinQinChina QinQinChina merged commit 863d36f into main Jun 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant