microsoft / microsoft/vscode-markdown-notebook
Silent Source Code Corruption and Cell Boundary Injection in Markdown Notebooks
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 88
- Forks
- 19
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 3
Description
The extension contains two significant parsing and serialization flaws. These vulnerabilities result in the silent, permanent corruption of user source code and allow for UI injection within the VS Code Notebook interface.
1. Silent Data Destruction (The undefined Regex Bug)
The extension contains a logic error in src/markdownParser.ts where it attempts to strip indentation from code blocks.
// src/markdownParser.ts
const content = lines.slice(startSourceIdx, i - 1)
.map(line => line.replace(new RegExp('^' + codeBlockStart.indentation), ''))
When a code block has no indentation, codeBlockStart.indentation is undefined. The RegExp constructor coerces this into the literal string "undefined", creating the regex /^undefined/.
Result: Any line of code starting with the word undefined (e.g., undefined_variable = true) has that word silently deleted from the file upon opening/saving. This is a high-integrity risk as it changes application logic without user interaction or warning.
2. Cell Boundary Injection (Improper Neutralization)
When saving a notebook, the extension fails to escape or sanitize the markdown code block terminator (`).
Result: A user can craft a code cell containing ` followed by malicious Markdown (such as a deceptive header or phishing link). Upon the next load, the extension misinterprets the boundary, "breaks out" of the code cell, and renders the attacker's payload as active, high-priority Markdown UI.
Steps to Reproduce
- Install the
vscode-markdown-notebookextension. - Create a file
leak.mdand open it with the Markdown Notebook editor. - To test Corruption: Add a code cell with the following line:
undefined_config = "critical_value"; - Save and reopen the file as plain text.
- Observed Result: The line has been changed to
_config = "critical_value";. The logic is broken. - To test Injection: Open the attached files using extension:
- Observed Result: The link renders as a massive, trusted UI element outside of the code block.
Proposed Fix
- For Regex: Explicitly check if
indentationis defined before creating theRegExp, or default to an empty string. - For Injection: Implement proper escaping for the
`sequence when serializing code cells back to the Markdown file.
Reference: https://msrc.microsoft.com/report/vulnerability/VULN-174944
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/markdownParser.ts and reproduce the undefined-prefix corruption using the issue's example. Then trace the notebook save serialization path and inspect the supplied exploit.md and poc.md cases. Done means code beginning with undefined is preserved and markdown-like content inside a code cell cannot escape its cell boundary or render as notebook UI.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- security, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100