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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Electron security guidelines (#129)
* Remove nodeintegration * Remove parity-utils proxy * Add CSP to renderer * Add handling chromium permissiosn * Remove unsafe-eval csp * Add context isolation for preload * Fix small bug * Verify contextIsolation * Remove comments * Add some comments * Add comment * Fix bugs * Re-allow eval() for builtins
- Loading branch information
1 parent
7f84c7a
commit 31d6e86
Showing
12 changed files
with
251 additions
and
70 deletions.
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.