Skip to content

fix: render sanitized raw HTML in package READMEs - #542

Open
apoorvdarshan wants to merge 1 commit into
supabase:masterfrom
apoorvdarshan:fix/162-sanitized-readme-html
Open

apoorvdarshan wants to merge 1 commit into
supabase:masterfrom
apoorvdarshan:fix/162-sanitized-readme-html

Conversation

@apoorvdarshan

Copy link
Copy Markdown

Problem

Raw HTML in package READMEs is printed as literal text: <p align> badge rows, <a><img></a> badges, <details>, HTML comments. The server-rendered https://database.dev/kiwicopple/supa_audit contains &lt;p, &lt;a href= and &lt;img src= as text. react-markdown keeps README HTML as raw nodes, and with no plugin to parse them it turns each into a text node.

Fix

  • Parse the HTML with rehype-raw, then run rehype-sanitize with its default (GitHub-style) schema. It keeps align, width/height, http(s) image src, details/summary and tables, and removes script, iframe, on* handlers, javascript: URLs and class/style. Sanitizing is required: READMEs come from any publisher, pages are server-rendered, and the CSP allows script-src 'unsafe-inline'.
  • Sanitize runs before rehype-highlight, so highlight.js classes survive.
  • Sanitize prefixes ids with user-content- (DOM clobbering). remark-rehype already prefixes footnote ids, so it now uses clobberPrefix: '', and a small plugin gives in-page #… links the same prefix. Footnotes keep GitHub's #user-content-fn-1 fragments.

Tests

New website/__tests__/markdown.integration.test.tsx: raw HTML renders as elements; unsafe HTML is removed and README ids can't clobber page ids; SQL fences keep highlighting and the copy button; footnote and raw-HTML anchor links resolve. On master 2 of the 4 fail; with the fix all pass, and removing any part of the fix fails at least one. TZ=UTC pnpm exec vitest run --coverage (CI's test:coverage): 28/28. Prettier as in CI, tsc --noEmit, ESLint on the changed files and pnpm install --frozen-lockfile are clean.

Notes

  • rehype-raw adds parse5: about 54 kB gzipped to the package page's markdown bundle.
  • CSP img-src still limits external images (e.g. to img.shields.io and github.com), as for markdown images today.
  • fixes extensions page to list all extensions #341 #490 also touches markdown.tsx (styling only, no raw HTML); the two changes merge cleanly apart from pnpm-lock.yaml.

This PR was prepared with AI assistance (Claude Code).

Fixes #162

🤖 Generated with Claude Code

Package pages printed GitHub-style raw HTML in READMEs (centered badges,
<details>, HTML comments) as escaped text, because react-markdown turns
raw HTML nodes into text unless rehype-raw parses them.

Parse raw HTML with rehype-raw and pass it through rehype-sanitize's
GitHub-style schema before rehype-highlight. This removes scripts, event
handlers, unsafe URLs and class/style attributes from publisher-supplied
READMEs while keeping highlight.js classes. rehype-sanitize prefixes ids
and names with `user-content-` to prevent DOM clobbering, so in-page
links such as footnotes get the same prefix, and remark-rehype no longer
adds its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@apoorvdarshan is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

docs: support github markdown

1 participant