test: cover markdown.tsx, the sole renderer of untrusted LLM output - #134
Open
shrdgn wants to merge 1 commit into
Open
test: cover markdown.tsx, the sole renderer of untrusted LLM output#134shrdgn wants to merge 1 commit into
shrdgn wants to merge 1 commit into
Conversation
markdown.tsx renders every panel/synthesized answer shown in the playground and is the only place model output reaches the DOM, but had zero tests. Adds coverage for plain text, GFM formatting (bold/list/table), and two regression tests locking in the component's XSS-safety property: a raw <script> or <img onerror> in markdown source renders as inert escaped text, never a live DOM element, since react-markdown has no rehype-raw plugin wired up. A future change adding one (e.g. to support HTML tables) will now trip a test instead of silently reintroducing script execution. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GdajDh7gW5bAjvGmmMpdt2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
web/src/components/markdown.tsxrenders every panel/synthesized answer shown in the playground (App.tsx's panel cards and fused-answer view) and is the only place untrusted model output reaches the DOM. It had zero tests anywhere underweb/src/__tests__or colocated, despite every other component/lib module having coverage.react-markdownv9 is safe by default here (norehype-rawplugin is wired up, so raw HTML in markdown source renders as inert escaped text rather than live DOM nodes) — but that safety property was entirely unenforced by any test. A future change (e.g. addingrehypeRawto support HTML tables, or a customimg/arenderer) could silently reintroduce script execution from model output with nothing catching it in CI.What changed
Added
web/src/components/__tests__/markdown.test.tsxcovering:<strong>,<li>,<table>).<script>tag in markdown source renders as inert escaped text (container.querySelector("script")is null, but the escaped text is visible) — never a live<script>element, andwindow.__pwnedis never set.<img onerror>handler renders the same way — never a live<img>element with anonerrorattribute.<a href>.The
<script>/<img onerror>tests are regression tests that lock in the exact current behavior (verified against the real rendered DOM, not assumed) so it fails loudly if a future PR changes the render pipeline in a way that reintroduces raw-HTML execution.How it was tested
npm run typecheckpassesnpm run test:coveragepasses: 55 tests (was 50), overall coverage 91.59%/81.26%/88.31%/93.73% (statements/branches/functions/lines), above the 90/70/85/90 CI gateGenerated by Claude Code