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-notebook extension.
- Create a file
leak.md and 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
indentation is defined before creating the RegExp, 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
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
undefinedRegex Bug)The extension contains a logic error in
src/markdownParser.tswhere it attempts to strip indentation from code blocks.When a code block has no indentation,
codeBlockStart.indentationisundefined. TheRegExpconstructor 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
vscode-markdown-notebookextension.leak.mdand open it with the Markdown Notebook editor.undefined_config = "critical_value";_config = "critical_value";. The logic is broken.Proposed Fix
indentationis defined before creating theRegExp, or default to an empty string.`sequence when serializing code cells back to the Markdown file.Reference: https://msrc.microsoft.com/report/vulnerability/VULN-174944