This repository has been archived by the owner on Feb 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 67
Implement Electron security guidelines #129
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5229d8f
Remove nodeintegration
amaury1093 0d79fde
Remove parity-utils proxy
amaury1093 4c2a4b5
Add CSP to renderer
amaury1093 75bd0aa
Add handling chromium permissiosn
amaury1093 251511c
Remove unsafe-eval csp
amaury1093 2b00ab4
Add context isolation for preload
amaury1093 0566a13
Fix small bug
amaury1093 7083b22
Verify contextIsolation
amaury1093 cadc67b
Remove comments
amaury1093 78a82d5
Add some comments
amaury1093 cba501d
Add comment
amaury1093 7ab0f2c
Fix bugs
amaury1093 e945c49
Re-allow eval() for builtins
amaury1093 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ | |
flex-grow: 1; | ||
margin: 0; | ||
padding: 0; | ||
opacity: 0; | ||
width: 100%; | ||
z-index: 1; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
<style> | ||
html { | ||
background: white; | ||
background-repeat: round; | ||
} | ||
|
||
html, body, #container { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
font-family: Sans-Serif; | ||
} | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta http-equiv="Content-Security-Policy" content="<%= htmlWebpackPlugin.options.csp %>"> | ||
<title> | ||
<%= htmlWebpackPlugin.options.title %> | ||
</title> | ||
<style> | ||
html { | ||
background: white; | ||
background-repeat: round; | ||
} | ||
|
||
.loading { | ||
text-align: center; | ||
padding-top: 5em; | ||
font-size: 2em; | ||
color: #999; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div class="loading">Loading</div> | ||
</div> | ||
</body> | ||
</html> | ||
html, | ||
body, | ||
#container { | ||
width: 100%; | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
font-family: Sans-Serif; | ||
} | ||
|
||
.loading { | ||
text-align: center; | ||
padding-top: 5em; | ||
font-size: 2em; | ||
color: #999; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div id="container"> | ||
<div class="loading">Loading</div> | ||
</div> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2015-2017 Parity Technologies (UK) Ltd. | ||
// This file is part of Parity. | ||
|
||
// Parity is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
|
||
// Parity is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import fs from 'fs'; | ||
import { ipcRenderer, remote, webFrame } from 'electron'; | ||
import path from 'path'; | ||
|
||
// The following two lines is just a proxy between the webview and the renderer process. | ||
// If we receive an IPC message from the shell, we relay it to the webview as | ||
// postMessage. | ||
ipcRenderer.on('PARITY_SHELL_IPC_CHANNEL', (_, data) => window.postMessage(data, '*')); | ||
// If we receive a postMessage from the webview, we transfer it to the renderer | ||
// as an IPC message. | ||
window.addEventListener('message', (event) => { | ||
ipcRenderer.sendToHost('PARITY_SHELL_IPC_CHANNEL', { data: event.data }); | ||
}); | ||
|
||
// Load inject.js as a string, and inject it into the webview with executeJavaScript | ||
fs.readFile(path.join(remote.getGlobal('dirName'), '..', '.build', 'inject.js'), 'utf8', (err, injectFile) => { | ||
if (err) { | ||
console.error(err); | ||
return; | ||
} | ||
webFrame.executeJavaScript(injectFile); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const shared = [ | ||
// Restrict everything to the same origin by default. | ||
"default-src 'self';", | ||
// Allow connecting to WS servers and HTTP(S) servers. | ||
// We could be more restrictive and allow only RPC server URL. | ||
'connect-src http: https: ws: wss:;', | ||
// Allow framing any content from HTTP(S). | ||
// Again we could only allow embedding from RPC server URL. | ||
// (deprecated) | ||
"frame-src 'none';", | ||
// Allow framing and web workers from HTTP(S). | ||
"child-src 'self' http: https:;", | ||
// We allow data: blob: and HTTP(s) images. | ||
// We could get rid of wildcarding HTTP and only allow RPC server URL. | ||
// (http required for local dapps icons) | ||
"img-src 'self' 'unsafe-inline' file: data: blob: http: https:;", | ||
// Allow style from data: blob: and HTTPS. | ||
"style-src 'self' 'unsafe-inline' data: blob: https:;", | ||
// Allow fonts from data: and HTTPS. | ||
"font-src 'self' data: https:;", | ||
// Same restrictions as script-src with additional | ||
// blob: that is required for camera access (worker) | ||
"worker-src 'self' https: blob:;", | ||
// Disallow submitting forms from any dapps | ||
"form-action 'none';", | ||
// Never allow mixed content | ||
'block-all-mixed-content;' | ||
]; | ||
|
||
// These are the CSP for the renderer process (aka the shell) | ||
const rendererCsp = [ | ||
...shared, | ||
// Allow <webview> which are objects | ||
"object-src 'self';", | ||
// Allow scripts | ||
"script-src 'self';" | ||
]; | ||
|
||
module.exports = { | ||
rendererCsp | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use
getBuildPath()
fromsrc/util/host.js
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not, I was getting a
window.require
is not a function.Reason is: in preload.js,
isElectron()
is true, however it's not a renderer process so you would dorequire('electron')
instead ofwindow.require('electron')