Skip to content

feat: enhance security by enabling context isolation and disabling no… - #1500

Merged
zerob13 merged 1 commit into
devfrom
safety
Apr 21, 2026
Merged

feat: enhance security by enabling context isolation and disabling no…#1500
zerob13 merged 1 commit into
devfrom
safety

Conversation

@zhangmo8

@zhangmo8 zhangmo8 commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

…de integration in web preferences

Summary by CodeRabbit

  • Chores
    • Enhanced Electron application window security configuration across splash screens, chat windows, and settings
    • Made renderer API objects immutable for improved code stability

@coderabbitai

coderabbitai Bot commented Apr 21, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR enhances Electron application security by disabling Node.js integration and enabling context isolation across all BrowserWindow instances, and making renderer-exposed APIs immutable via Object.freeze() to prevent runtime modification.

Changes

Cohort / File(s) Summary
BrowserWindow Security Configuration
src/main/presenter/lifecyclePresenter/SplashWindowManager.ts, src/main/presenter/windowPresenter/index.ts
Added nodeIntegration: false and contextIsolation: true to webPreferences for splash window and managed chat/Settings windows to harden Electron security.
Preload Script API Immutability
src/preload/index.ts
Wrapped renderer-exposed API objects (api, deepchatDevApi, deepchatBridge) with Object.freeze() to make them immutable and prevent tampering from renderer process.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat: splash window #1370: Modifies SplashWindowManager.ts BrowserWindow webPreferences configuration with overlapping security hardening adjustments.

Poem

🐰 A bunny hops through secure gates,
With frozen APIs, context isolated,
Node integration? Not today, friend!
Our windows stand strong, code locked tight,
Safety whiskers twitching with delight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main security enhancements: enabling context isolation and disabling node integration in web preferences across multiple files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch safety

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/preload/index.ts (1)

33-107: ⚠️ Potential issue | 🟡 Minor

Update renderer test mocks for the frozen bridge objects.

The production hardening is good, but existing tests will fail due to property mutations on frozen objects:

  • test/renderer/components/ChatInputBox.test.ts:170 uses Object.assign(((window as any).api ??= {}), {...}) which attempts to mutate the frozen api object
  • test/renderer/stores/uiSettingsStore.test.ts:182 uses window.deepchat.invoke = invoke which attempts to mutate the frozen bridge object

These patterns will throw TypeError once the preload installs the frozen objects. Update these tests to either assign fresh globals before imports or use vi.stubGlobal / Object.defineProperty instead of mutating the exposed objects.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/preload/index.ts` around lines 33 - 107, Tests fail because preload now
freezes bridge objects (api and deepchat) and tests attempt to mutate them
(e.g., Object.assign on window.api and assigning window.deepchat.invoke). Update
those tests to avoid mutating frozen globals by creating fresh globals before
importing the modules or stubbing them via the test runner: replace patterns
like Object.assign(((window as any).api ??= {}), {...}) and direct assignment to
window.deepchat.invoke with vi.stubGlobal('api', {...}) /
vi.stubGlobal('deepchat', {...}) or use Object.defineProperty to define
non-writable properties, ensuring you reference the exposed symbols api and
deepchat (and specific test files ChatInputBox.test.ts and
uiSettingsStore.test.ts) when making the replacements.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/preload/index.ts`:
- Around line 33-107: Tests fail because preload now freezes bridge objects (api
and deepchat) and tests attempt to mutate them (e.g., Object.assign on
window.api and assigning window.deepchat.invoke). Update those tests to avoid
mutating frozen globals by creating fresh globals before importing the modules
or stubbing them via the test runner: replace patterns like
Object.assign(((window as any).api ??= {}), {...}) and direct assignment to
window.deepchat.invoke with vi.stubGlobal('api', {...}) /
vi.stubGlobal('deepchat', {...}) or use Object.defineProperty to define
non-writable properties, ensuring you reference the exposed symbols api and
deepchat (and specific test files ChatInputBox.test.ts and
uiSettingsStore.test.ts) when making the replacements.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 83220f07-af66-49ef-ac07-184872466a53

📥 Commits

Reviewing files that changed from the base of the PR and between fc012db and a3a8c99.

📒 Files selected for processing (3)
  • src/main/presenter/lifecyclePresenter/SplashWindowManager.ts
  • src/main/presenter/windowPresenter/index.ts
  • src/preload/index.ts

@zerob13
zerob13 merged commit 20078f5 into dev Apr 21, 2026
3 checks passed
@zhangmo8
zhangmo8 deleted the safety branch April 21, 2026 04:51
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.

2 participants