Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
4f6c2fd
feat: Security aspects for fether-electron. See #124
ltfschoen Jan 13, 2019
a0a80db
chore: merge latest master and fix conflicts
ltfschoen Feb 25, 2019
0f9c3d1
feat: Add Source Maps support
ltfschoen Feb 25, 2019
845c0cc
docs: Add Source Maps guide to Readme
ltfschoen Feb 25, 2019
944bd9d
feat: Add webpack-build-notifier add-on with custom Webpack config
ltfschoen Feb 25, 2019
3bb2208
fix: Remove duplicate dependency
ltfschoen Feb 28, 2019
c54c4ed
WIP
ltfschoen Mar 1, 2019
f6dce7c
WIP
ltfschoen Mar 1, 2019
02fb145
review-fix: Configure CSP depending on NODE_ENV
ltfschoen Mar 13, 2019
db907c3
fix: Fix worker-src for the camera in production
ltfschoen Mar 13, 2019
068ef6a
review-fix: Remove unnecessary config of source maps dependency
ltfschoen Mar 13, 2019
1ee0ffa
Use preload script as buffer between main and renderer processes (#463)
amaury1093 Mar 14, 2019
e596cc8
merge latest from master
ltfschoen Mar 15, 2019
8e64347
fix: Remove is-electron since now using preload script
ltfschoen Mar 15, 2019
8064e19
fix: Remove old preload script
ltfschoen Mar 15, 2019
357ac3a
fix: Do not expose electron, remote, or require to web app
ltfschoen Mar 16, 2019
b93a5c9
fix: Add newline
ltfschoen Mar 16, 2019
7a97924
feat: Single Fether instance lock
ltfschoen Mar 17, 2019
10d84ca
fix: Move preload to static folder so works with binary
ltfschoen Mar 17, 2019
0bdac10
review-fix: Remove fix for webview since not used. Add comment incase…
ltfschoen Mar 21, 2019
e510c7b
review-fix: Add optional opt-in to using Webpack notifier plugin by r…
ltfschoen Mar 21, 2019
bc180b4
review-fix: Use pino.debug instead of console.log
ltfschoen Mar 21, 2019
0114b85
review-fix: Add worker-src blob to CSP in development for webcam
ltfschoen Mar 21, 2019
502cb69
review-fix: Update handling of untrusted urls and sessions and certif…
ltfschoen Mar 21, 2019
2e5bc92
review-fix: Convert to WSS. Move CSP into array like in Parity-JS She…
ltfschoen Mar 22, 2019
d10b4ec
review-fix: Update CSP to avoid duplication
ltfschoen Mar 22, 2019
88c9924
review-fix: Remove from new-window event listener that which applies …
ltfschoen Mar 22, 2019
b8d0ddd
review-fix: Combined pino logs
ltfschoen Mar 22, 2019
7930793
review-fix: Change to parsedUrl.href instead of origin. Fix trusted u…
ltfschoen Mar 22, 2019
a2afb9d
fix: Remote https 127.0.0.1 in prod
ltfschoen Mar 23, 2019
aab094d
review-fix: Move WebpackBuildNotifier images so not in binary. Fix ic…
ltfschoen Mar 23, 2019
1c59d89
fix: Remove console.logs
ltfschoen Mar 23, 2019
cc456ef
refactor: Cleanup so can merge. Extract for inclusion in separate PR
ltfschoen Mar 25, 2019
4c9ac7d
review-fix: Remove debugging notes since better in wiki
ltfschoen Mar 25, 2019
7d906bf
review-fix: Remove other lines due to move to wiki
ltfschoen Mar 25, 2019
8b57717
fix comment
ltfschoen Mar 25, 2019
657fc00
review-fix: Remove setPermissionRequestHandler since not know if need…
ltfschoen Mar 25, 2019
8cc13f3
review-fix: Move CSP debugging into onHeadersReceived
ltfschoen Mar 25, 2019
7df49cc
review-fix: Fix isParityRunningStatus
ltfschoen Mar 25, 2019
119766f
review-fix: Replace parse-url with Node.js url parser
ltfschoen Mar 25, 2019
254c03f
review-fix: Remove parse-url from dependencies
ltfschoen Mar 25, 2019
c8fb23c
fix: Fix logic in setCertificateVerifyProc
ltfschoen Mar 25, 2019
b40308c
merge latest master and fix conflicts
ltfschoen Mar 25, 2019
daa27f2
WIP
ltfschoen Mar 30, 2019
d916bf9
review-fix: Dynamically add WS port from CLI to trusted
ltfschoen Mar 30, 2019
f4c6937
review-fix: Update comments with security warnings
ltfschoen Mar 30, 2019
01ce652
merge latest from master and fix conflicts
ltfschoen Mar 30, 2019
0faceb4
chore: Remove useless console.log
ltfschoen Mar 30, 2019
a062aeb
fix merge conflicts
ltfschoen Mar 30, 2019
77c40c2
misc: See commit details
ltfschoen Mar 30, 2019
ba9f98c
review-fix: Use appIsPackaged instead of NODE_ENV
ltfschoen Mar 30, 2019
eb6043d
fix: Add IS_PROD to constants and assign appIsPackaged to it. Expose …
ltfschoen Mar 31, 2019
1a0a15e
feat: Add wiki Fether FAQ to trusted urls since required by PR #482
ltfschoen Mar 31, 2019
40422f7
fix: Fix untrusted blockscout.com error in setCertificateVerifyProc
Apr 4, 2019
37edbe4
review-fix: fix blocked image hosting and external blockscout urls
Apr 5, 2019
58fab3d
review-fix: trust github token icons
Apr 5, 2019
4de10ab
review-fix: Rename network to fetherNetwork so custom config avoids n…
Apr 5, 2019
a2f494d
review-fix: Remove duplicate pino.debug for CSP
Apr 5, 2019
54b9eac
review-fix: Remove WsSecure until wss and certificates implemented
Apr 5, 2019
db12be9
review-fix: Update config to show Electron security warnings in all e…
Apr 5, 2019
b042a85
review-fix: Remove use of wsInterface
Apr 5, 2019
4579045
refactor: Refactor tests inside describe blocks
Apr 5, 2019
a45f317
tests: Add chrome dev tools to tests for trusted urls
Apr 5, 2019
6640fe7
review-fix: Use NODE_ENV and Electron app.isPackaged
Apr 5, 2019
01726e3
fix: Rebuild yarn.lock
Apr 5, 2019
783aa35
merge latest master and rebuild yarn.lock
Apr 5, 2019
8e754af
fix: Fix linting to arg passed to correct script
Apr 5, 2019
c4ecc01
review-fix: Remove ws-origins flag and trusted ws origins
Apr 6, 2019
f2fe570
test: Fix failing test
Apr 6, 2019
2ac6625
review-fix: Remove package-lock.json
Apr 6, 2019
6f574c9
fix: Use NODE_ENV consistently instead of process.defaultApp
Apr 7, 2019
10146cf
fix: Change to hash instead of transactionHash for blockscout
Apr 7, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"build": "lerna run build",
"preelectron": "yarn build",
"electron": "cd packages/fether-electron && yarn electron",
"lint-files": "./scripts/lint-files.sh",
"lint": "yarn lint-files '**/*.js'",
"lint-files": "./scripts/lint-files.sh '**/*.js'",
"lint": "yarn lint-files",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? This makes the pre-commit hook less performant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the change it was trying to lint the .ts files and the pre-commit hook was preventing me from pushing

"prepackage": "yarn build",
"package": "cd packages/fether-electron && yarn package",
"release": "cd packages/fether-electron && yarn release",
Expand Down Expand Up @@ -76,4 +76,4 @@
"ts-node": "^8.0.3",
"typescript": "^3.3.4000"
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions packages/fether-electron/custom.webpack.additions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// https://webpack.electron.build/add-ons
// https://www.npmjs.com/package/webpack-build-notifier
const path = require('path');
const WebpackBuildNotifierPlugin = require('webpack-build-notifier');

const withWebpackBuildNotifier = process.env.NOTIFIER === 'true';

module.exports = withWebpackBuildNotifier
? {
plugins: [
new WebpackBuildNotifierPlugin({
title: 'Fether Webpack Build',
logo: path.resolve('./build/icons/icon.ico'),
suppressSuccess: false,
compileIcon: path.resolve('./build/icons/webpack/compile.png'),
failureIcon: path.resolve('./build/icons/webpack/failure.png'),
successIcon: path.resolve('./build/icons/webpack/success.png'),
warningIcon: path.resolve('./build/icons/webpack/warning.png')
})
]
}
: {};
6 changes: 5 additions & 1 deletion packages/fether-electron/electron-webpack.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"main": {
"webpackConfig": "custom.webpack.additions.js"
},
"renderer": {
"sourceDirectory": null
}
},
"title": "Fether"
}
12 changes: 7 additions & 5 deletions packages/fether-electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
"scripts": {
"prebuild": "copyfiles -u 2 \"../fether-react/build/**/*\" static/ && ./scripts/fixElectronBug.sh",
"build": "electron-webpack",
"electron": "cross-env SKIP_PREFLIGHT_CHECK=true electron dist/main/main.js",
"electron": "electron dist/main/main.js",
"prepackage": "./scripts/revertElectronBug.sh",
"package": "electron-builder",
"prerelease": "./scripts/revertElectronBug.sh",
"release": "electron-builder",
"start": "cross-env ELECTRON_START_URL=http://localhost:3000 electron-webpack dev --ws-origins all",
"start": "cross-env ELECTRON_START_URL=http://localhost:3000 electron-webpack dev",
"test": "jest --all --color --coverage"
},
"dependencies": {
Expand All @@ -48,14 +48,16 @@
"fether-react": "^0.3.0",
"pino": "^4.16.1",
"pino-multi-stream": "^3.1.2",
"source-map-support": "^0.5.10"
"source-map-support": "^0.5.10",
"url-pattern": "^1.0.3"
},
"devDependencies": {
"copyfiles": "^2.1.0",
"cross-env": "^5.2.0",
"electron": "^4.0.1",
"electron-builder": "^20.38.5",
"electron-webpack": "^2.6.1",
"webpack": "^4.29.1"
"webpack": "^4.29.1",
"webpack-build-notifier": "^0.1.30"
}
}
}
23 changes: 12 additions & 11 deletions packages/fether-electron/src/main/app/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: BSD-3-Clause

import cli from 'commander';

import { DEFAULT_CHAIN, DEFAULT_WS_PORT } from '../constants';
const { productName } = require('../../../../electron-builder.json');
const { version } = require('../../../../package.json');

Expand All @@ -24,30 +24,31 @@ cli
.allowUnknownOption()
.option(
'--chain <chain>',
'The network to connect to, can be one of "foundation", "kovan" or "ropsten". (default: "kovan")',
'kovan'
`The network to connect to, can be one of "foundation", "kovan" or "ropsten". (default: "${DEFAULT_CHAIN}")`,
DEFAULT_CHAIN
)
.option(
'--no-run-parity',
`${productName} will not attempt to run the locally installed parity.`
)
.option(
'--ws-interface <ip>',
`Specify the hostname portion of the WebSockets server ${productName} will connect to. IP should be an interface's IP address. (default: 127.0.0.1)`,
'127.0.0.1'
)
.option(
'--ws-port <port>',
`Specify the port portion of the WebSockets server ${productName} will connect to. (default: 8546)`,
8546
`Specify the port portion of the WebSockets server ${productName} will connect to. (default: ${DEFAULT_WS_PORT})`,
DEFAULT_WS_PORT
)

.parse(
process.argv
// We want to ignore some flags and not pass them down to Parity:
// --inspect: `electron-webpack dev` runs Electron with the `--inspect` flag for HMR
// -psn_*: https://github.com/paritytech/fether/issues/188
.filter(arg => !arg.startsWith('--inspect') && !arg.startsWith('-psn_'))
.filter(
arg =>
!arg.startsWith('--inspect') &&
!arg.startsWith('-psn_') &&
!arg.startsWith('--ws-interface') &&
!arg.startsWith('--ws-origins')
)
);

export default cli;
27 changes: 27 additions & 0 deletions packages/fether-electron/src/main/app/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
// This file is part of Parity.
//
// SPDX-License-Identifier: BSD-3-Clause

import { IS_PACKAGED } from '../utils/paths';

const IS_PROD = process.env.NODE_ENV === 'production';

/**
* Security. Additional network security is configured after `cli` is available:
* in fether-electron/src/main/app/options/config/index.js
*
* Note: 127.0.0.1 is a trusted loopback and more trustworthy than localhost.
* See https://letsencrypt.org/docs/certificates-for-localhost/
*/
const DEFAULT_CHAIN = 'kovan';
const DEFAULT_WS_PORT = '8546';
const TRUSTED_LOOPBACK = '127.0.0.1';

export {
DEFAULT_CHAIN,
DEFAULT_WS_PORT,
IS_PACKAGED,
IS_PROD,
TRUSTED_LOOPBACK
};
3 changes: 2 additions & 1 deletion packages/fether-electron/src/main/app/menu/template/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// SPDX-License-Identifier: BSD-3-Clause

import electron from 'electron';
import { IS_PROD } from '../../constants';

const { shell } = electron;

Expand Down Expand Up @@ -170,7 +171,7 @@ const getContextTrayMenuTemplate = fetherApp => {
}
];

if (process.env.NODE_ENV !== 'production') {
if (!IS_PROD) {
template.push({
label: 'Reload',
click: () => fetherApp.win.webContents.reload()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import { DEFAULT_WS_PORT, TRUSTED_LOOPBACK } from '../constants';
import cli from '../cli';

function setupGlobals () {
// Globals for fether-react parityStore
global.wsInterface = cli.wsInterface;
global.defaultWsInterface = TRUSTED_LOOPBACK;
global.defaultWsPort = DEFAULT_WS_PORT;
global.wsPort = cli.wsPort;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

import electron from 'electron';

import { IS_PROD } from '../constants';
import { CSP } from '../utils/csp';
import messages from '../messages';
import Pino from '../utils/pino';

const pino = Pino();
const { ipcMain, session } = electron;

function setupRequestListeners (fetherApp) {
Expand All @@ -30,6 +35,24 @@ function setupRequestListeners (fetherApp) {
callback({ requestHeaders: details.requestHeaders }); // eslint-disable-line
}
);

// Content Security Policy (CSP)
session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
pino.debug(
`Configuring Content-Security-Policy for environment ${
IS_PROD ? 'production' : 'development'
}`
);

/* eslint-disable */
callback({
responseHeaders: {
...details.responseHeaders,
"Content-Security-Policy": [CSP]
}
});
/* eslint-enable */
});
}

export default setupRequestListeners;
61 changes: 56 additions & 5 deletions packages/fether-electron/src/main/app/methods/setupWinListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,71 @@
//
// SPDX-License-Identifier: BSD-3-Clause

import electron from 'electron';
import debounce from 'lodash/debounce';

import { SECURITY_OPTIONS } from '../options/config';
import Pino from '../utils/pino';

const { TRUSTED_HOSTS } = SECURITY_OPTIONS.fetherNetwork;
const trustedHostsAll = Object.values(TRUSTED_HOSTS).flat();
const pino = Pino();

function setupWinListeners (fetherApp) {
const { onWindowClose, processSaveWinPosition, win } = fetherApp;

// Open external links in browser
win.webContents.on('new-window', (event, url) => {
event.preventDefault();
electron.shell.openExternal(url);
/**
* Insecure TLS Validation - verify the application does not explicitly opt-out of TLS validation
*
* References:
* - https://doyensec.com/resources/us-17-Carettoni-Electronegativity-A-Study-Of-Electron-Security-wp.pdf
* - https://electronjs.org/docs/api/session#sessetcertificateverifyprocproc
*/
win.webContents.session.setCertificateVerifyProc((request, callback) => {
const { hostname, certificate, verificationResult, errorCode } = request; // eslint-disable-line

pino.debug(
'Processing server certificate verification request for the session in setCertificateVerifyProc with hostname: ',
hostname
);

if (errorCode) {
pino.error(
'Error processing server certificate verification request for the session in setCertificateVerifyProc: ',
errorCode
);

// Failure accepting certificate due to errorCode
callback(-2); // eslint-disable-line
} else if (!trustedHostsAll.includes(hostname)) {
pino.info(
'Failure accepting server certification due to its hostname being an untrusted host in setCertificateVerifyProc: ',
hostname
);

// Failure accepting server certificate due to its source hostname being untrusted
callback(-2); // eslint-disable-line
} else if (!verificationResult === 'net::OK') {
pino.info(
'Failure accepting server certificate due to it failing Chromium verification: ',
hostname,
verificationResult
);

// Failure accepting server certificate due to it failing Chromium verification
callback(-2); // eslint-disable-line
} else {
pino.info(
'Fallback to using the verification result from Chromium: ',
hostname,
verificationResult
);

// Fallback to using the verification result from Chromium
callback(-3); // eslint-disable-line

// // Success and accept the certifcate, disable Certificate Transparency verification
// callback(0); // eslint-disable-line
}
});

// Windows and Linux (unchecked on others)
Expand Down
Loading