You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/latest/tutorial/security.md
+46-1
Original file line number
Diff line number
Diff line change
@@ -122,6 +122,7 @@ You should at least follow these steps to improve the security of your applicati
122
122
17.[Validate the `sender` of all IPC messages](#17-validate-the-sender-of-all-ipc-messages)
123
123
18.[Avoid usage of the `file://` protocol and prefer usage of custom protocols](#18-avoid-usage-of-the-file-protocol-and-prefer-usage-of-custom-protocols)
124
124
19.[Check which fuses you can change](#19-check-which-fuses-you-can-change)
125
+
20.[Do not expose Electron APIs to untrusted web content](#20-do-not-expose-electron-apis-to-untrusted-web-content)
125
126
126
127
To automate the detection of misconfigurations and insecure patterns, it is
127
128
possible to use
@@ -238,7 +239,7 @@ API to remotely loaded content via the [contextBridge API](../api/context-bridge
238
239
239
240
:::info
240
241
241
-
This recommendation is the default behavior in Electron since 12.0.0.
242
+
Context Isolation is the default behavior in Electron since 12.0.0.
242
243
243
244
:::
244
245
@@ -828,6 +829,50 @@ flipping these fuses easy. Check out the README of that module for more details
828
829
potential error cases, and refer to
829
830
[How do I flip the fuses?](./fuses.md#how-do-i-flip-the-fuses) in our documentation.
830
831
832
+
### 20. Do not expose Electron APIs to untrusted web content
833
+
834
+
You should not directly expose Electron's APIs, especially IPC, to untrusted web content in your
835
+
preload scripts.
836
+
837
+
### Why?
838
+
839
+
Exposing raw APIs like `ipcRenderer.on` is dangerous because it gives renderer processes direct
840
+
access to the entire IPC event system, allowing them to listen for any IPC events, not just the ones
841
+
intended for them.
842
+
843
+
To avoid that exposure, we also cannot pass callbacks directly through: The first
844
+
argument to IPC event callbacks is an `IpcRendererEvent` object, which includes properties like `sender`
845
+
that provide access to the underlying `ipcRenderer` instance. Even if you only listen for specific
846
+
events, passing the callback directly means the renderer gets access to this event object.
847
+
848
+
In short, we want the untrusted web content to only have access to necessary information and APIs.
0 commit comments