Skip to content

fix(html,ansi): escape plugin fallbacks and strip terminal control characters - #377

Open
atinux wants to merge 5 commits into
mainfrom
fix/renderer-output-encoding
Open

fix(html,ansi): escape plugin fallbacks and strip terminal control characters#377
atinux wants to merge 5 commits into
mainfrom
fix/renderer-output-encoding

Conversation

@atinux

@atinux atinux commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What

Escapes the raw source in @comark/html's math and mermaid catch branches (via a shared escapeHtml helper, deduplicating the binding plugin's copy), and strips C0/C1/DEL control characters from the document before rendering in @comark/ansi.

Why

A security scan found two output-encoding gaps in the renderer packages: when KaTeX or the mermaid renderer throw on malformed input, the fallback interpolated the author-controlled source into raw HTML (stored XSS even without the raw-HTML plugin); and the ANSI renderer passed ESC/BEL/OSC bytes from untrusted markdown straight to the terminal, enabling forged output and clipboard/title manipulation on permissive terminals. The ANSI sanitization copies the document rather than mutating it, and keeps tab/newline intact.


🤖 Prepared by an AI agent (OpenCode) from a security-audit findings list; commits are signed by the repository owner's key.

atinux added 3 commits August 21, 2026 11:48
When KaTeX or the mermaid renderer throw on malformed input, the catch
branches interpolated the raw markdown-controlled source into the
returned HTML — stored XSS, although raw HTML is otherwise opt-in.
Route the fallback through a shared escapeHtml helper (also deduplicating
the binding plugin's local copy).
The ANSI renderer concatenates node text, code bodies, and hrefs
verbatim, so raw ESC/BEL/C1 bytes from untrusted markdown reached the
terminal: forged output, overwritten lines, and OSC sequences (window
title, clipboard on permissive terminals).

Sanitize the document (copy, no mutation) in renderAnsiFromDocument:
remove C0 controls except tab/newline, DEL, and the C1 range from
strings and attribute values before rendering.
@atinux
atinux requested a review from farnabaz as a code owner August 21, 2026 09:58
@vercel

vercel Bot commented Aug 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
comark Ready Ready Preview Aug 21, 2026 1:32pm
comark-json-render Ready Ready Preview Aug 21, 2026 1:32pm
comark-nextjs Ready Ready Preview Aug 21, 2026 1:32pm
comark-nuxt Ready Ready Preview Aug 21, 2026 1:32pm
comark-svelte Ready Ready Preview Aug 21, 2026 1:32pm
comark-sveltekit Ready Ready Preview Aug 21, 2026 1:32pm
comark-twoslash Ready Ready Preview Aug 21, 2026 1:32pm
comark-vue Ready Ready Preview Aug 21, 2026 1:32pm

@pkg-pr-new

pkg-pr-new Bot commented Aug 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

comark

npm i https://pkg.pr.new/comark@377

@comark/angular

npm i https://pkg.pr.new/@comark/angular@377

@comark/ansi

npm i https://pkg.pr.new/@comark/ansi@377

@comark/html

npm i https://pkg.pr.new/@comark/html@377

@comark/nuxt

npm i https://pkg.pr.new/@comark/nuxt@377

@comark/react

npm i https://pkg.pr.new/@comark/react@377

@comark/svelte

npm i https://pkg.pr.new/@comark/svelte@377

@comark/vue

npm i https://pkg.pr.new/@comark/vue@377

commit: 03abcf7

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