Skip to content

Commit cdb20d2

Browse files
🔧 WebSecurity
1 parent 7e79ae7 commit cdb20d2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

docs/tutorial/security.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,43 @@ const mainWindow = new BrowserWindow()
358358
```
359359

360360

361+
## Do Not Disable WebSecurity
362+
363+
You may have already guessed that disabling the `webSecurity` property on a
364+
renderer process (`BrowserView`, `BrowserWindow`, `WebView`) disables crucial
365+
security features.
366+
367+
Legitimate use cases for this property exist in testing cases, but generally
368+
speaking, `webSecurity` should never be disabled in any production application.
369+
370+
### Why?
371+
372+
Disabling `webSecurity` will disable the same-origin policy as well as
373+
implicitly setting the `allowRunningInsecureContent` property to `true`. In
374+
other words, it allows the execution of insecure code from different domains.
375+
376+
### How?
377+
```js
378+
// Bad
379+
const mainWindow = new BrowserWindow({
380+
webPreferences: {
381+
webSecurity: false
382+
}
383+
})
384+
385+
// Good
386+
const mainWindow = new BrowserWindow()
387+
```
388+
389+
```html
390+
<!-- Bad -->
391+
<webview disablewebsecurity src="page.html"></webview>
392+
393+
<!-- Good -->
394+
<webview src="page.html"></webview>
395+
```
396+
397+
361398
## Verify WebView Options Before Creation
362399
A WebView created in a renderer process that does not have Node.js integration
363400
enabled will not be able to enable integration itself. However, a WebView will

0 commit comments

Comments
 (0)