Linux local electron application script-src: self bypass
An HTML injection in a local Electron application was blocked by a script-src 'self' CSP, but the author found a bypass by forcing the victim's default browser to auto-download a JavaScript file and then loading it via the /proc/self/cwd path, which points to the user's home directory. This allowed script execution in the Electron app, potentially leading to RCE through IPC.
Published on mizu.re
While searching for XSS to RCE exploit chain on the draw.io desktop electron application, I faced a situation where I was able to get an HTML injection which wasn't sanitized but blocked by a script-src: self CSP. The specificity of this application is that everything is loaded locally using loadFile (it could be…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the application allowed loading local files from any path under the user's home directory, and the CSP 'self' policy considered file:// URLs from the same origin as allowed, so a downloaded script in the Downloads folder could be executed.
Impact
An attacker could execute arbitrary JavaScript in the Electron application, which could then communicate with the main process via IPC and potentially lead to remote code execution.
What the attacker needed
HTML injection in the Electron app; Victim clicks a link; Victim uses Linux
The fix
The issue was fixed by restricting local resource loading to a specific path using a webRequest handler.
How it was found
- Inject HTML that creates a link with target="_blank" to a server that forces a file download.
- The victim clicks the link, and the default browser downloads a JavaScript file to the Downloads folder.
- Inject a script tag that loads the downloaded file via /proc/self/cwd/Downloads/xss.js.
- The script executes in the Electron app, bypassing the CSP.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Electron apps are desktop programs built with web technology. A Content Security Policy (CSP) is a rule that tells the browser which scripts are allowed to run; 'self' means only scripts from the same place as the page. The author found a way to sneak a script in by making the user download a file and then loading it from a special Linux path that points to the user's home folder.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.