Files
Dylan M. Taylor 64750ea5a2 fix: escape raw HTML and script URLs in the markdown renderer (#272)
## What was wrong
The help menu (`libs/components/help-menu`) fetches `news.json` from the
website at runtime and renders each article with `markdownToHtml` into
`dangerouslySetInnerHTML`. `markdownToHtml` copied the source text into
its output unescaped, so any raw HTML in an article body (`<img
onerror=...>`, `<script>`, `<svg onload=...>`) went straight into the
app's DOM, including the desktop webview. Link and media targets were
also unchecked, so `[x](javascript:...)` produced a script URL, and a
`"` in a URL, alt text or `@image` size broke out of the attribute.

## What changed
- `markdownToHtml` now HTML-escapes every input line before applying
markdown syntax (blockquote `>` is matched first, then its content is
escaped). The only tags in the output are the ones the renderer builds.
- New `safeUrl`: link, image and video targets must be relative or
`http`/`https`/`mailto`; anything else becomes `#`.
- `@image` / `![...](url|size)` sizes must be `N`, `Npx`, `N%` or `WxH`;
other values are ignored since they go into a `style` attribute.

## Blast radius
Every caller of `markdownToHtml` from `@storyteller/markdown-content`:
the help menu and the library's own `NewsPost` page. The bundled
news/FAQ/tutorial markdown uses no raw HTML or non-http links, so its
rendering is unchanged (apostrophes and quotes now render via entities).
The website's separate copy in
`apps/artcraft-website-next/src/lib/markdown.ts` is not touched.

## Checks run
- `npx vitest run src/lib/utils/markdown.spec.ts` in
`libs/markdown-content`: 6/6 pass; 4 of them fail on `main`.
- `tsc -p tsconfig.lib.json` / `tsconfig.spec.json`: no errors in
touched files (existing TS6305 unbuilt-reference errors are unrelated).

## Checks not run
- Opening the help menu news view in the desktop app or webapp.

Addresses CodeRabbit security findings (CWE-79).


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Markdown content now displays embedded HTML as text and blocks unsafe
link destinations, reducing the risk of unwanted markup or navigation.
* Safe relative, web, and email links continue to work. Image sizing now
accepts only valid values, and malformed sizes are rejected.
* **Tests**
* Added coverage for supported Markdown, safe URL handling, embedded
HTML, and crafted links, images, and media.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-11-11 11:10:46 -05:00
..