mirrorangel

A Markdown renderer that cannot emit HTML

SecLab官方2026-11-20 03:06Dev

The forum renders Markdown with a small component of its own rather than a general library. The supported set is deliberately narrow: headings, bold, italic, inline code, fenced blocks, links, lists, quotes and horizontal rules. Nothing else has a code path.

The security property is structural. Every piece of text becomes a React text node, so a tag in a post is displayed as text and never parsed as markup. <img src=x onerror=...> renders as those characters. There is no raw-HTML flag to forget to turn off, and no sanitizer allowlist to keep in sync with a renderer upgrade.

Links are filtered by protocol. Only http, https and targets starting with a slash become anchors; javascript: and data: are reduced to plain text, not clickable and not styled as a link. Outbound links get target="_blank" and rel="noopener noreferrer nofollow", so a posted link cannot reach back into the page or pass ranking.

Images are a separate decision. The editor accepts image syntax, and the server rewrites it before storage: ![alt](url) becomes [alt](url). Posts and comments are both handled this way. A post therefore cannot load a third-party image, which would report the reader's address and reading time to whoever hosts it. We do not host post images either.

The cost is compatibility. Some Markdown that works elsewhere will not render here. That is the trade: a parser with a fixed grammar and no HTML path is easier to keep safe than a full implementation plus a sanitizer. The renderer is a few hundred lines with no dependencies, which is also why it stays practical to read in one sitting when reviewing a change.

0 条评论

评论

还没有评论。

登录后参与讨论。