[PM-41251] Disable nodeIntegration, add preload + IPC layer - #1212
Conversation
…to main process and call via IPC from render process
There was a problem hiding this comment.
This all works, but its not perfect. It yanks everything that relies on node out of the renderer process in a pretty unceremonious manner. Theres probably room for improvement but this is the gist what we do in clients... Just looking for general feedback, this minimally resolves the linked issue. I can iterate on any async feedback once I am back from PTO so no rush here.
The bunch of comments are for future me, who will thank me when reading them in 2 weeks. 🤝
|
|
||
| try { | ||
| const promise = this.authService.logIn({ clientId, clientSecret }); | ||
| const promise = ipc.auth.logIn({ clientId, clientSecret }); |
There was a problem hiding this comment.
@eliykat curious on your opinion on this pattern. I don't know if I am a fan of the IPC calls as they're done here, maybe we want an abstraction to sit between the IPC calls and these renderer call sites that we can DI into the components. Maybe each main process service that has an IPC channel, similar to what ended up in src-gui/services/electron/electronRendererSecureStorage.service.ts?
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1212 +/- ##
============================
============================
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
While this addresses the ticket, this leaves DC in a rather fragile state. GUI build will bork if you accidentally pull in any node api in the renderer process, which is relatively easy to do accidentally (especially with |
I have addressed this with a new linter rule preventing node API and electron imports in the renderer. I think that should take care of this concern |
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE Reviewed the one commit since the last pass ( Code Review DetailsNo new findings in this pass. Dependency Changes
|
|
@coltonhurst If you're available to give the just the IPC implementation here some feedback it would be much appreciated, as I've been told you have some experience with it. |
|
Direction seems sound and I haven't seen anything that I could identify as alarming. My only question: I assume the IPC layer entirely is managed by electron, so we have nothing to handle on our side in terms of transient failures (either for the connection as a whole, or on a per-message basis) between the renderer<->main process? |
Yes, electron manages the IPC wrt the messaging between renderer and main. The only thing we really have to concern ourselves with is the |
jrmccannon
left a comment
There was a problem hiding this comment.
As much as I can tell it looks good.
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-41251
📔 Objective
Disables Electron's
nodeIntegrationin the renderer process and establishes a secure IPC boundary. Migrates services that rely on node out of the renderer process and into the main process. These services are now called from the renderer process via the IPC layer.Big changes:
nodeIntegration: falserenderer no longer has direct Node.js accesspreload.tswhich exposes a typedwindow.ipcAPI via electron'scontextBridgeso renderer can call its old servicesipcMain.handle, which is a wrappper around the electron API w/ some extra error handling.webpack.preload.mjsconfig for preload bundleThe renderer process should now be fully sandboxed. all privileged operations that require node run in main and are exposed only through whitelisted IPC channels.
📸 Screenshots