Skip to content

fix(security, parser): prevent Marp script XSS and frontmatter line offset collision - #106

Merged
phine-apps merged 1 commit into
mainfrom
fix/marp-xss-and-frontmatter-offset
Nov 7, 2026
Merged

phine-apps merged 1 commit into
mainfrom
fix/marp-xss-and-frontmatter-offset

Conversation

@phine-apps

Copy link
Copy Markdown
Owner

Summary

Addresses adversarial audit findings regarding Marp script extraction XSS vulnerability and Quick Edit frontmatter line offset collisions:

  1. Marp Script Sanitization & XSS Prevention (src/markdown/marpRenderer.ts):

    • Only allows Marp Core's official auto-scaling and SVG polyfill scripts (data-marp-auto-scaling, marpitSVGPolyfill, marp-auto-scaling) to be extracted into scripts / marpJs.
    • Prevents untrusted user-supplied <script> tags inside Marp Markdown content from being extracted and executed in the Webview.
  2. Quick Edit Line Offset Collision Prevention (src/markdownDiff.ts):

    • In getLineOffset(original, content), if frontmatter is present at the beginning of the file, search starts past the frontmatter block (fmMatch[0].length).
    • Prevents words that appear in both frontmatter (e.g. desc: TargetBodyWord) and body text from colliding and generating erroneous data-line attributes.
  3. Security & Parser Unit Tests (src/test/unit/security.test.ts):

    • prevents XSS via user-supplied <script> in Marp documents: Verifies user <script> tags are not extracted into marpJs and are safely escaped in webview HTML.
    • prevents frontmatter offset collision with body content: Verifies data-line correctly maps to the body line index rather than colliding with frontmatter keys/values.

Verification

  • TypeScript compilation (tsc -p ./): 0 errors
  • Esbuild bundling (node esbuild.js --sourcemap): passed
  • ESLint (eslint src): 0 errors
  • Unit tests (mocha "./out/test/unit/**/*.test.js"): 294 passing

@phine-apps
phine-apps merged commit 1676aaf into main Nov 7, 2026
3 checks passed
@phine-apps
phine-apps deleted the fix/marp-xss-and-frontmatter-offset branch November 25, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant