Visual Studio Code Jupyter Notebook RCE
A cross-site scripting flaw in Visual Studio Code's Jupyter Notebook support allowed a malicious .ipynb file to run script inside a sandboxed iframe. By abusing a path traversal in the vscode-file protocol and a postMessage reply, the attacker could load attacker-controlled HTML from the repository and reach the top window to execute code.
Published on blog.doyensec.com
I spared a few hours over the past weekend to look into the exploitation of this Visual Studio Code .ipynb Jupyter Notebook bug discovered by Justin Steven in August 2021.
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 notebook renderer inserted markdown output into a sandboxed iframe without sanitising it, and the iframe's allow-same-origin plus a path traversal in the vscode-file protocol let the injected script reach the top window with Node.js integration enabled.
Impact
Opening a malicious repository could let an attacker run arbitrary code on the victim's machine without further interaction, because the Jupyter extension opts out of Workspace Trust.
What the attacker needed
Victim opens a malicious repository; Jupyter Notebook extension enabled
The fix
The issue was fixed in Visual Studio Code 1.59.1.
How it was found
- Create a malicious repository containing a crafted .ipynb file and an HTML payload file.
- Open the repository in Visual Studio Code so the notebook is rendered.
- The injected script uses a postMessage reply to leak the current user directory path.
- The script builds a vscode-file URL with path traversal to load the attacker's HTML file.
- The loaded HTML reaches the top window and executes code via require('child_process').exec.
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.
A booby-trapped notebook could run JavaScript inside a sandboxed iframe; with extra tricks the script could reach the main window and start programs.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.