Skip to content

fix(security): resolve CodeQL ReDoS, Marp tag sanitization, and test runner issues - #80

Merged
phine-apps merged 2 commits into
mainfrom
fix/codeql-security-and-test-runner
Aug 28, 2026
Merged

fix(security): resolve CodeQL ReDoS, Marp tag sanitization, and test runner issues#80
phine-apps merged 2 commits into
mainfrom
fix/codeql-security-and-test-runner

Conversation

@phine-apps

Copy link
Copy Markdown
Owner

Summary

This PR addresses high-priority security alerts reported by GitHub CodeQL (Code Scanning) and fixes the VS Code integration test runner environment.

1. Fix ReDoS in structural diff regexes (js/redos)

  • Footnote bundle matching: Simplified footnoteBundleRegex in src/markdown/structuralDiff.ts by eliminating nested quantifiers ((?:<li[^>]*>[\s\S]*?<\/li>\s*)+) that caused exponential backtracking on long or repeated list items. Guarded the callback to process only valid footnote list bundles without colliding with list container swaps.
  • Heading prefix matching: Rewrote wrapHeadingPrefixes in src/markdown/structuralDiff.ts to use a linear heading matcher and deterministic prefix parser instead of backtracking nested whitespace/quantifier groups.

2. Improve Marp script & style sanitization (js/bad-tag-filter, js/incomplete-multi-character-sanitization)

  • Marp tag extraction and cleaning: Updated cleanMarpHtml in src/markdown/marpRenderer.ts to use case-insensitive matching with whitespace tolerance (/<\s*script\b[^>]*>([\s\S]*?)<\/\s*script\s*>/gi) to avoid tag bypasses (e.g. </script >, multiline attributes, uppercase tags). Applied iterative loop stripping (do ... while) for complete tag removal.
  • Unit test script regex: Updated script matching pattern in src/test/unit/markdownDiff.test.ts to match case-insensitively with full attribute/whitespace tolerance.

3. Fix VS Code integration test runner (src/test/runTest.ts)

  • Removed inherited ELECTRON_RUN_AS_NODE from process.env before calling runTests so VS Code launches properly as a GUI Electron app with extension CLI arguments when executed from VS Code integrated terminals or IDE sub-shells.

Verification

  • Unit Tests: 233 passing (3s) (pnpm test:unit)
  • Integration Tests: 50 passing (3s) (npm run test)
  • Visual Regression Tests: Passed via Docker (pnpm run test:visual:docker)
  • Compile & Lint: 0 errors

Comment thread src/markdown/marpRenderer.ts Fixed
Comment thread src/markdown/marpRenderer.ts Fixed
Comment thread src/markdown/marpRenderer.ts Fixed
Comment thread src/markdown/structuralDiff.ts Fixed
Comment thread src/test/unit/markdownDiff.test.ts Fixed
@phine-apps
phine-apps merged commit 1eb6f29 into main Aug 28, 2026
3 checks passed
phine-apps added a commit that referenced this pull request Aug 30, 2026
…unner

fix(security): resolve CodeQL ReDoS, Marp tag sanitization, and test runner issues
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