Skip to content

security: comprehensive security hardening for API keys, TLS, and data privacy#1121

Open
Littleyd wants to merge 23 commits intotisfeng:mainfrom
Littleyd:security/comprehensive-audit-fixes
Open

security: comprehensive security hardening for API keys, TLS, and data privacy#1121
Littleyd wants to merge 23 commits intotisfeng:mainfrom
Littleyd:security/comprehensive-audit-fixes

Conversation

@Littleyd
Copy link
Copy Markdown

Summary

This PR addresses multiple security vulnerabilities identified during a comprehensive security audit of the Easydict codebase. The changes focus on protecting user data and API credentials.

High-Priority Fixes

  1. API Keys migrated to macOS Keychain — All translation service API keys/secrets (DeepL, Baidu, Ali, Tencent, Volcano, NiuTrans, Caiyun, and OpenAI-compatible stream services) are now stored in Keychain instead of UserDefaults. A transparent migration runs on first launch.

  2. WebView TLS certificate validation restored — Removed allowsAnyHTTPSCertificateForHost:YES and the blanket trust in didReceiveAuthenticationChallenge:. WebView now properly validates server certificates.

  3. App Transport Security tightened — Replaced NSAllowsArbitraryLoads = YES with NSAllowsLocalNetworking = YES in both Info.plist and Info-debug.plist, restricting plaintext HTTP to localhost only.

  4. Hardcoded Baidu session cookie removed — Removed embedded BDUSS/BDUSS_BFESS values from EZWebViewTranslator.m.

  5. URL Scheme key read/write gated by user confirmationeasydict://writeKeyValue and easydict://readValueOfKey now show an NSAlert requiring explicit user approval before executing.

Medium-Priority Fixes

  1. Analytics & crash reporting default to opt-inallowCrashLog and allowAnalytics now default to false.

  2. OCR text truncated in logs — Full OCR results are no longer written to system logs.

  3. Sensitive keys filtered from backup export — API keys, secrets, and tokens are excluded from the user data export file.

  4. Bing endpoint upgraded to HTTPS — Changed http:// to https:// for the Bing China host.

New Files

  • Easydict/Swift/Utility/KeychainHelper.swift — Keychain CRUD helper + migration logic from UserDefaults to Keychain.

Test Plan

  • Fresh install: verify no crash on first launch (migration runs with empty UserDefaults)
  • Upgrade from existing install: verify API keys are migrated to Keychain and removed from UserDefaults
  • Translation services (DeepL, Baidu, Tencent, Ali, Volcano, NiuTrans, Caiyun, OpenAI): verify keys are read from Keychain and services function normally
  • WebView-based translators (Google, Bing, Baidu web): verify pages load correctly with restored TLS validation
  • URL Scheme: test easydict://writeKeyValue?EZTest=abc shows confirmation dialog
  • URL Scheme: test easydict://readValueOfKey?EZTest shows confirmation dialog
  • Settings → Service config: enter a new API key, close settings, verify key persists (synced to Keychain)
  • Backup export: verify exported file does not contain API keys or tokens
  • Analytics: verify Firebase/Sentry are disabled by default on fresh install

Made with Cursor

darcyYe and others added 22 commits March 2, 2026 22:04
- add native MiniMax service via OpenAI-compatible endpoint
- register MiniMax in QueryServiceFactory and ObjC ServiceType bridge
- add localization key and service icon
- update supported models to MiniMax Text OpenAI API official list
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit moves the "enable_remove_books_excerpt_info" toggle to a different position in the advanced settings section. The setting now appears after "auto_select_all_text_field" instead of its previous placement.

This reordering improves the logical grouping and flow of settings in the text selection and replacement section.
This commit fixes the regular expression for removing book copyright notices from Chinese text. The pattern was updated from "摘自" to "摘" to better match different variations of the copyright notice format.

The change expands the regex to capture more cases of Chinese copyright notices, ensuring the text extraction feature works more reliably for different book formats.
This refactoring improves the code structure and performance for the book copyright removal feature:

- Swift extension: Added guard clause to return early if feature is disabled
- Simplified regex pattern construction and made regex compilation more efficient
- Removed redundant conditional logic and streamlined text extraction flow
- Improved code organization by separating concerns more clearly

The changes make the feature more efficient and easier to maintain while preserving all existing functionality.
This commit fixes an inconsistency where book copyright removal was only applied to keyboard shortcut queries but not mouse selection queries.

Previously, the copyright text removal logic was only executed in the keyboard shortcut handling path. Now both keyboard and mouse selection queries will have their text processed through the same copyright removal pipeline, ensuring consistent behavior regardless of how the user initiates a query.
The Vision framework import was being used in MenuItemView but was not actually required by the code. Removing this unused import improves code cleanliness and reduces unnecessary dependencies.
Update the contribution guidelines in both English and Chinese documentation files.
This clarifies the branch naming conventions (feat/xxx, fix/xxx) and prohibits direct commits to  or  branches, emphasizing the need for feature branches and pull requests.
This commit removes the redundant `NSWindowDidResizeNotification` observation in `EZBaseQueryWindow.m`.

The window resizing logic is now primarily managed within `EZBaseQueryViewController.m`, making the direct observation of `NSWindowDidResizeNotification` in the window unnecessary. This change aims to centralize window resize handling and improve stability.
Avoid recalculating window height while the frame is being updated internally, and skip frame changes when the target only differs by minor floating-point drift.

This keeps query window resizing stable and reduces redundant reload and frame update cycles.
Replace the Claude-specific commit command doc with a symlink to the shared git-commit skill and update AGENTS references to the relocated rule files.

Also add an MCP server note for OpenAI developer documentation workflows.
Document the `/git-commit` workflow in both English and Chinese READMEs for contributors using Codex or Claude.

Clarify that contributors should stage changes first, review the generated message preview, and explicitly approve before the commit is created.
Update the command line build examples to use `~/Library/Developer/Xcode/DerivedData` instead of the repo-local DerivedData path.

Add a note explaining the home-path assumption and document `xcbeautify` installation with Homebrew.
Remove the duplicate Build Commands section from AGENTS.md and replace the stale root-relative link with `.claude/rules/build.md`.

This keeps agent guidance aligned with the single source of truth for command line build and test commands.
…a privacy

- Store API keys in macOS Keychain instead of UserDefaults (with auto-migration)
- Remove WebView trust-all-certificates bypass (EZURLSchemeHandler)
- Tighten App Transport Security: NSAllowsLocalNetworking only (was NSAllowsArbitraryLoads)
- Remove hardcoded Baidu session cookies (BDUSS)
- Add user confirmation dialog for URL Scheme API key read/write operations
- Change Bing endpoint from HTTP to HTTPS
- Default analytics (Firebase) and crash logging (Sentry) to opt-in (was opt-out)
- Truncate OCR text in logs to prevent sensitive data leakage
- Filter API keys/tokens from backup export to Downloads folder

Made-with: Cursor
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Littleyd, Thank you for your first PR contribution 🎉 Littleyd

Easydict connects to many translation services over HTTP (Ollama on
localhost, Bing China, etc.). NSAllowsLocalNetworking alone is too
restrictive and breaks Ollama. Restore NSAllowsArbitraryLoads while
keeping NSAllowsLocalNetworking as explicit documentation.

Made-with: Cursor
@tisfeng
Copy link
Copy Markdown
Owner

tisfeng commented Mar 28, 2026

Please use dev branch as base branch

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.

4 participants