Skip to content
XSS Write-up Advanced

Supply Chain Security Analysis of a 9.5M-Install VS Code Extension

A popular VS Code Markdown preview extension evaluated the raw text of WaveDrom diagram blocks as JavaScript, so opening a crafted Markdown file ran attacker code inside the preview webview. That code could then reach an unvalidated webview message dispatcher and a file-write command, giving arbitrary file write on the developer's machine.

projectdiscovery.io

Published on projectdiscovery.io

Your code editor extensions auto-update and run with your privileges on the machine that holds your source code, your SSH keys, and your publishing credentials, but they rarely show up in a software bill of materials.

The author, on projectdiscovery.io

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 renderer passed untrusted Markdown content to eval, and the webview-to-extension message channel forwarded any command name and arguments to the command system without an allowlist or workspace containment check.

Impact

An attacker could run code in the preview and write arbitrary files on the developer's machine, which could lead to command execution on the next shell, Git operation or build; the text notes the chain required several links to line up.

What the attacker needed

Victim opens a crafted Markdown file; preview is rendered; extension version before 0.8.30

The fix

It was fixed: WaveDrom is now parsed as strict JSON instead of eval, workspace config files run in a QuickJS WebAssembly sandbox, head.html scripts are stripped, the dispatcher uses a command allowlist, and file writes are pinned to the previewed file.

How it was found

  1. Place a crafted WaveDrom block in a Markdown file.
  2. Open the file and render the preview, which evaluates the block as JavaScript.
  3. The injected script recovers the webview API handle and sends a message to the extension host.
  4. The dispatcher runs the requested command, reaching updateMarkdown.
  5. updateMarkdown writes attacker content to any file URI, such as an SSH authorised_keys file.

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 code editor extension is a small program that adds features to the editor, and it runs with the same permissions as you. This extension showed Markdown previews and, for one diagram format, treated the diagram's text as a program to run. So a booby-trapped Markdown file could run code on your computer and write files, such as your shell startup file, which then runs commands the next time you open a terminal.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.