File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- 5e29e21a6019d5e222f8e67c7b5f7b51538b0125
1+ d14320748df1c868437b413083846302660c5804
Original file line number Diff line number Diff line change @@ -28,7 +28,9 @@ hide_title: false
2828 associated with the window, making it compatible with the Chromium
2929 OS-level sandbox and disabling the Node.js engine. This is not the same as
3030 the ` nodeIntegration ` option and the APIs available to the preload script
31- are more limited. Read more about the option [ here] ( ../../tutorial/sandbox.md ) .
31+ are more limited. Default is ` true ` since Electron 20. The sandbox will
32+ automatically be disabled when ` nodeIntegration ` is set to ` true ` .
33+ Read more about the option [ here] ( ../../tutorial/sandbox.md ) .
3234* ` session ` [ Session] ( ../session.md#class-session ) (optional) - Sets the session used by the
3335 page. Instead of passing the Session object directly, you can also choose to
3436 use the ` partition ` option instead, which accepts a partition string. When
Original file line number Diff line number Diff line change @@ -20,7 +20,13 @@ the GPU service and the network service.
2020See Chromium's [ Sandbox design document] [ sandbox ] for more information.
2121
2222Starting from Electron 20, the sandbox is enabled for renderer processes without any
23- further configuration. If you want to disable the sandbox for a process, see the
23+ further configuration.
24+
25+ Sandboxing is tied to Node.js integration. _ Enabling Node.js integration_ for a
26+ renderer process by setting ` nodeIntegration: true ` _ disables the sandbox_ for the
27+ process.
28+
29+ If you want to disable the sandbox for a process, see the
2430[ Disabling the sandbox for a single process] ( #disabling-the-sandbox-for-a-single-process )
2531section.
2632
@@ -105,7 +111,8 @@ app.whenReady().then(() => {
105111```
106112
107113Sandboxing is also disabled whenever Node.js integration is enabled in the renderer.
108- This can be done through the BrowserWindow constructor with the ` nodeIntegration: true ` flag.
114+ This can be done through the BrowserWindow constructor with the ` nodeIntegration: true ` flag
115+ or by providing the respective HTML boolean attribute for a ` webview ` .
109116
110117``` js title='main.js'
111118app .whenReady ().then (() => {
@@ -118,6 +125,10 @@ app.whenReady().then(() => {
118125})
119126```
120127
128+ ``` html title='index.html (Renderer Process)'
129+ <webview nodeIntegration src =" page.html" ></webview >
130+ ```
131+
121132### Enabling the sandbox globally
122133
123134If you want to force sandboxing for all renderers, you can also use the
Original file line number Diff line number Diff line change @@ -254,6 +254,10 @@ to enable this behavior.
254254Even when ` nodeIntegration: false ` is used, to truly enforce strong isolation
255255and prevent the use of Node primitives ` contextIsolation ` ** must** also be used.
256256
257+ Beware that _ disabling context isolation_ for a renderer process by setting
258+ ` nodeIntegration: true ` _ also disables process sandboxing_ for that process.
259+ See section below.
260+
257261::: info
258262
259263For more information on what ` contextIsolation ` is and how to enable it please
@@ -263,6 +267,18 @@ see our dedicated [Context Isolation](context-isolation.md) document.
263267
264268### 4. Enable process sandboxing
265269
270+ ::: info
271+
272+ This recommendation is the default behavior in Electron since 20.0.0.
273+
274+ Additionally, process sandboxing can be enforced for all renderer processes
275+ application wide: [ Enabling the sandbox globally] ( sandbox.md#enabling-the-sandbox-globally )
276+
277+ _ Disabling context isolation_ (see above) _ also disables process sandboxing_ ,
278+ regardless of the default, ` sandbox: false ` or globally enabled sandboxing!
279+
280+ :::
281+
266282[ Sandboxing] ( https://chromium.googlesource.com/chromium/src/+/HEAD/docs/design/sandbox.md )
267283is a Chromium feature that uses the operating system to
268284significantly limit what renderer processes have access to. You should enable
You can’t perform that action at this time.
0 commit comments