Skip to content

Silent Source Code Corruption and Cell Boundary Injection in Markdown Notebooks #42

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

  1. Install the vscode-markdown-notebook extension.
  2. Create a file leak.md and open it with the Markdown Notebook editor.
  3. To test Corruption: Add a code cell with the following line:
    undefined_config = "critical_value";
  4. Save and reopen the file as plain text.
  5. Observed Result: The line has been changed to _config = "critical_value";. The logic is broken.
  6. To test Injection: Open the attached files using extension:
  1. Observed Result: The link renders as a massive, trusted UI element outside of the code block.

Proposed Fix

  1. For Regex: Explicitly check if indentation is defined before creating the RegExp, or default to an empty string.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions