Repository navigation
Sanitize HTML rendered from third-party markdown on catalog pages - #1518
Merged
Merged
Conversation
Package descriptions and custom element descriptions come from npm package metadata and custom elements manifests, and were rendered with marked() and inserted via unsafeHTML() without sanitization. Add renderUntrustedMarkdown(), which runs marked() output through sanitize-html with a tight allowlist (default tags plus img/del; link, image, code-language and table-align attributes only; http, https and mailto URLs), and use it in the package and element routes. Sanitizing on the server covers both the SSR output and the hydration data in __ssrData.
kevinpschaaf
enabled auto-merge (squash)
November 13, 2026 22:08
kevinpschaaf
disabled auto-merge
November 13, 2026 22:08
kevinpschaaf
approved these changes
Nov 13, 2026
kevinpschaaf
enabled auto-merge (squash)
November 13, 2026 22:10
auto-merge was automatically disabled
November 13, 2026 22:19
Head branch was pushed to by a user without write access
dfreedm
approved these changes
Nov 13, 2026
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.
Package descriptions and custom element descriptions come from third-party npm package metadata and custom elements manifests. The catalog renders them with
marked()and inserts the result withunsafeHTML(), butmarkedpasses raw HTML through unchanged and nothing was sanitizing it.This change:
renderUntrustedMarkdown()inpackages/site-server/src/lib/catalog/markdown.ts. It runs themarked()output through sanitize-html with a tight allowlist:imganddelhttp,httpsandmailto(no protocol-relative URLs)marked()directly. Sanitizing on the server covers both the SSR output and the hydration data in__ssrData.src/test/catalog/markdown_test.ts). These don't need the dev servers.I chose sanitize-html over DOMPurify so the site server doesn't need jsdom: it adds about 15 packages to the lockfile instead of about 38.