@@ -44,7 +44,7 @@ Chromium shared library and Node.js. Vulnerabilities affecting these components
4444may impact the security of your application. By updating Electron to the latest
4545version, you ensure that critical vulnerabilities (such as * nodeIntegration bypasses* )
4646are already patched and cannot be exploited in your application. For more information,
47- see "[ Use a current version of Electron] ( #15 -use-a-current-version-of-electron ) ".
47+ see "[ Use a current version of Electron] ( #16 -use-a-current-version-of-electron ) ".
4848
4949* ** Evaluate your dependencies.** While NPM provides half a million reusable packages,
5050it is your responsibility to choose trusted 3rd-party libraries. If you use outdated
@@ -88,18 +88,19 @@ You should at least follow these steps to improve the security of your applicati
88881 . [ Only load secure content] ( #1-only-load-secure-content )
89892 . [ Disable the Node.js integration in all renderers that display remote content] ( #2-do-not-enable-nodejs-integration-for-remote-content )
90903 . [ Enable context isolation in all renderers that display remote content] ( #3-enable-context-isolation-for-remote-content )
91- 4 . [ Use ` ses.setPermissionRequestHandler() ` in all sessions that load remote content] ( #4-handle-session-permission-requests-from-remote-content )
92- 5 . [ Do not disable ` webSecurity ` ] ( #5-do-not-disable-websecurity )
93- 6 . [ Define a ` Content-Security-Policy ` ] ( #6-define-a-content-security-policy ) and use restrictive rules (i.e. ` script-src 'self' ` )
94- 7 . [ Do not set ` allowRunningInsecureContent ` to ` true ` ] ( #7-do-not-set-allowrunninginsecurecontent-to-true )
95- 8 . [ Do not enable experimental features] ( #8-do-not-enable-experimental-features )
96- 9 . [ Do not use ` enableBlinkFeatures ` ] ( #9-do-not-use-enableblinkfeatures )
97- 10 . [ ` <webview> ` : Do not use ` allowpopups ` ] ( #10-do-not-use-allowpopups )
98- 11 . [ ` <webview> ` : Verify options and params] ( #11-verify-webview-options-before-creation )
99- 12 . [ Disable or limit navigation] ( #12-disable-or-limit-navigation )
100- 13 . [ Disable or limit creation of new windows] ( #13-disable-or-limit-creation-of-new-windows )
101- 14 . [ Do not use ` openExternal ` with untrusted content] ( #14-do-not-use-openexternal-with-untrusted-content )
102- 15 . [ Use a current version of Electron] ( #15-use-a-current-version-of-electron )
91+ 4 . [ Enable sandboxing] ( #4-enable-sandboxing )
92+ 5 . [ Use ` ses.setPermissionRequestHandler() ` in all sessions that load remote content] ( #5-handle-session-permission-requests-from-remote-content )
93+ 6 . [ Do not disable ` webSecurity ` ] ( #6-do-not-disable-websecurity )
94+ 7 . [ Define a ` Content-Security-Policy ` ] ( #7-define-a-content-security-policy ) and use restrictive rules (i.e. ` script-src 'self' ` )
95+ 8 . [ Do not set ` allowRunningInsecureContent ` to ` true ` ] ( #8-do-not-set-allowrunninginsecurecontent-to-true )
96+ 9 . [ Do not enable experimental features] ( #9-do-not-enable-experimental-features )
97+ 10 . [ Do not use ` enableBlinkFeatures ` ] ( #10-do-not-use-enableblinkfeatures )
98+ 11 . [ ` <webview> ` : Do not use ` allowpopups ` ] ( #11-do-not-use-allowpopups )
99+ 12 . [ ` <webview> ` : Verify options and params] ( #12-verify-webview-options-before-creation )
100+ 13 . [ Disable or limit navigation] ( #13-disable-or-limit-navigation )
101+ 14 . [ Disable or limit creation of new windows] ( #14-disable-or-limit-creation-of-new-windows )
102+ 15 . [ Do not use ` openExternal ` with untrusted content] ( #15-do-not-use-openexternal-with-untrusted-content )
103+ 16 . [ Use a current version of Electron] ( #16-use-a-current-version-of-electron )
103104
104105To automate the detection of misconfigurations and insecure patterns, it is
105106possible to use
@@ -239,7 +240,26 @@ and prevent the use of Node primitives `contextIsolation` **must** also be used.
239240For more information on what ` contextIsolation ` is and how to enable it please
240241see our dedicated [ Context Isolation] ( context-isolation.md ) document.
241242
242- ## 4) Handle Session Permission Requests From Remote Content
243+ ## 4) Enable Sandboxing
244+
245+ [ Sandboxing] ( sandbox.md ) is a Chromium feature that uses the operating system to
246+ significantly limit what renderer processes have access to. You should enable
247+ the sandbox in all renderers. Loading, reading or processing any untrusted
248+ content in an unsandboxed process, including the main process, is not advised.
249+
250+ ### How?
251+
252+ When creating a window, pass the ` sandbox: true ` option in ` webPreferences ` :
253+
254+ ``` js
255+ const win = new BrowserWindow ({
256+ webPreferences: {
257+ sandbox: true
258+ }
259+ })
260+ ```
261+
262+ ## 5) Handle Session Permission Requests From Remote Content
243263
244264You may have seen permission requests while using Chrome: They pop up whenever
245265the website attempts to use a feature that the user has to manually approve (
@@ -277,7 +297,7 @@ session
277297 })
278298```
279299
280- ## 5 ) Do Not Disable WebSecurity
300+ ## 6 ) Do Not Disable WebSecurity
281301
282302_ Recommendation is Electron's default_
283303
@@ -318,7 +338,7 @@ const mainWindow = new BrowserWindow()
318338<webview src =" page.html" ></webview >
319339```
320340
321- ## 6 ) Define a Content Security Policy
341+ ## 7 ) Define a Content Security Policy
322342
323343A Content Security Policy (CSP) is an additional layer of protection against
324344cross-site-scripting attacks and data injection attacks. We recommend that they
@@ -374,7 +394,7 @@ on a page directly in the markup using a `<meta>` tag:
374394<meta http-equiv =" Content-Security-Policy" content =" default-src 'none'" >
375395```
376396
377- ## 7 ) Do Not Set ` allowRunningInsecureContent ` to ` true `
397+ ## 8 ) Do Not Set ` allowRunningInsecureContent ` to ` true `
378398
379399_ Recommendation is Electron's default_
380400
@@ -407,7 +427,7 @@ const mainWindow = new BrowserWindow({
407427const mainWindow = new BrowserWindow ({})
408428```
409429
410- ## 8 ) Do Not Enable Experimental Features
430+ ## 9 ) Do Not Enable Experimental Features
411431
412432_ Recommendation is Electron's default_
413433
@@ -439,7 +459,7 @@ const mainWindow = new BrowserWindow({
439459const mainWindow = new BrowserWindow ({})
440460```
441461
442- ## 9 ) Do Not Use ` enableBlinkFeatures `
462+ ## 10 ) Do Not Use ` enableBlinkFeatures `
443463
444464_ Recommendation is Electron's default_
445465
@@ -471,7 +491,7 @@ const mainWindow = new BrowserWindow({
471491const mainWindow = new BrowserWindow ()
472492```
473493
474- ## 10 ) Do Not Use ` allowpopups `
494+ ## 11 ) Do Not Use ` allowpopups `
475495
476496_ Recommendation is Electron's default_
477497
@@ -498,7 +518,7 @@ you know it needs that feature.
498518<webview src =" page.html" ></webview >
499519```
500520
501- ## 11 ) Verify WebView Options Before Creation
521+ ## 12 ) Verify WebView Options Before Creation
502522
503523A WebView created in a renderer process that does not have Node.js integration
504524enabled will not be able to enable integration itself. However, a WebView will
@@ -545,7 +565,7 @@ app.on('web-contents-created', (event, contents) => {
545565Again, this list merely minimizes the risk, it does not remove it. If your goal
546566is to display a website, a browser will be a more secure option.
547567
548- ## 12 ) Disable or limit navigation
568+ ## 13 ) Disable or limit navigation
549569
550570If your app has no need to navigate or only needs to navigate to known pages,
551571it is a good idea to limit navigation outright to that known scope, disallowing
@@ -589,7 +609,7 @@ app.on('web-contents-created', (event, contents) => {
589609})
590610```
591611
592- ## 13 ) Disable or limit creation of new windows
612+ ## 14 ) Disable or limit creation of new windows
593613
594614If you have a known set of windows, it's a good idea to limit the creation of
595615additional windows in your app.
@@ -636,7 +656,7 @@ app.on('web-contents-created', (event, contents) => {
636656})
637657```
638658
639- ## 14 ) Do not use ` openExternal ` with untrusted content
659+ ## 15 ) Do not use ` openExternal ` with untrusted content
640660
641661Shell's [ ` openExternal ` ] [ open-external ] allows opening a given protocol URI with
642662the desktop's native utilities. On macOS, for instance, this function is similar
@@ -663,7 +683,7 @@ const { shell } = require('electron')
663683shell .openExternal (' https://example.com/index.html' )
664684```
665685
666- ## 15 ) Use a current version of Electron
686+ ## 16 ) Use a current version of Electron
667687
668688You should strive for always using the latest available version of Electron.
669689Whenever a new major version is released, you should attempt to update your
0 commit comments