Repository navigation
fix: render sanitized raw HTML in package READMEs - #542
Open
apoorvdarshan wants to merge 1 commit into
Open
apoorvdarshan wants to merge 1 commit into
apoorvdarshan wants to merge 1 commit into
Conversation
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>
|
@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
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.
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<p,<a href=and<img src=as text. react-markdown keeps README HTML asrawnodes, and with no plugin to parse them it turns each into a text node.Fix
rehype-raw, then runrehype-sanitizewith its default (GitHub-style) schema. It keepsalign,width/height, http(s) imagesrc,details/summaryand tables, and removesscript,iframe,on*handlers,javascript:URLs andclass/style. Sanitizing is required: READMEs come from any publisher, pages are server-rendered, and the CSP allowsscript-src 'unsafe-inline'.rehype-highlight, so highlight.js classes survive.user-content-(DOM clobbering). remark-rehype already prefixes footnote ids, so it now usesclobberPrefix: '', and a small plugin gives in-page#…links the same prefix. Footnotes keep GitHub's#user-content-fn-1fragments.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'stest:coverage): 28/28. Prettier as in CI,tsc --noEmit, ESLint on the changed files andpnpm install --frozen-lockfileare clean.Notes
rehype-rawadds parse5: about 54 kB gzipped to the package page's markdown bundle.img-srcstill limits external images (e.g. toimg.shields.ioandgithub.com), as for markdown images today.markdown.tsx(styling only, no raw HTML); the two changes merge cleanly apart frompnpm-lock.yaml.This PR was prepared with AI assistance (Claude Code).
Fixes #162
🤖 Generated with Claude Code