Skip to content

fix(security,perf): resolve adversarial audit findings across Marp, Mermaid, sanitizer, and structural diff - #110

Merged
phine-apps merged 2 commits into
mainfrom
fix/adversarial-audit-2026-11
Nov 19, 2026
Merged

phine-apps merged 2 commits into
mainfrom
fix/adversarial-audit-2026-11

Conversation

@phine-apps

Copy link
Copy Markdown
Owner

Summary

Remediates all 12 findings (Critical, High, Medium, Low) identified during the 6-Pillar Adversarial Code Audit:

Security & Sanitization (Pillar 3)

  • Marp Script Allowlist Bypass (Critical): Replace substring-based script extraction in src/markdown/marpRenderer.ts with exact matching against Marp Core's baseline internal script captured in loadMarp(), and neutralize </script in src/markdown/webviewTemplate.ts.
  • Marp CSS </style> Breakout (High): Neutralize </style sequences in scopeMarpCss() and webviewTemplate.ts (marpCss and katexCssInline).
  • Sanitizer src Scheme Validation (High): Add "src" to allowedSchemesAppliedToAttributes in src/markdown/sanitizer.ts (stripping javascript: on <img>) while allowing vscode-webview-resource and vscode-resource on img.
  • CSS url() Filter Hardening (Medium): Block CSS backslash escapes, /* comments, and image-set() / -webkit-image-set() in src/markdown/sanitizer.ts.
  • Export HTML Workspace Boundary (High): Enforce allowedRoots via isPathWithinAllowedRoots() in src/exportHtml.ts and pass workspace + extension media/data roots from src/extension.ts.
  • Webview Message Validation (Medium): Enforce Number.isInteger on line numbers, writable-scheme allowlist (file:/untitled:) for applyEdit, and strict type checks for page and runtimeDiagnostics payloads in src/extension.ts.

ReDoS & Linear Performance (Pillar 1)

  • Mermaid Edge Parser ReDoS (High): Eliminate overlapping whitespace quantifiers in parseMermaidEdges() (src/markdown/mermaidDiff.ts).
  • fixInvalidNesting Step 0 (Medium): Replace quadratic negative-lookahead regex with an $O(N)$ linear scanner in src/markdown/structuralDiff.ts.

HTML Structural Integrity, Line Mapping & CJK/Unicode (Pillars 2, 4, 5)

  • Marp Slide Splitting (Medium): Use depth-tracking findClosing in splitMarpSlides() and backreference \1 in cleanMarpHtml().
  • Quote-Aware Scanning & Offsets (Medium): Make maskBlockAttributes and splitByBlocks quote-aware; handle empty frontmatter, UTF-8 BOM, and matching delimiters in getLineOffset(); skip leading whitespace in injectLineNumbers().
  • labelBlockDiffTags (Low): Inspect the immediate child element's class attribute to attach data-diff-label.
  • CJK & ZWJ Emoji Support (Low): Support ZWJ (\u200D) and VS16 (\uFE0F) in obsidian_tag, and use code-point-safe slicing with CJK-aware thresholds for Marp fuzzy heading matching.

Verification

  • ./node_modules/.bin/tsc -p ./: Passed (0 errors)
  • npm run lint: Passed (0 errors, 0 warnings)
  • ./node_modules/.bin/mocha "./out/test/unit/**/*.test.js": 305 passing (including 11 new adversarial regression tests)

Comment thread src/test/unit/security.test.ts Fixed
@phine-apps
phine-apps merged commit 50fa396 into main Nov 19, 2026
3 checks passed
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.

2 participants