Skip to content

Sanitize link hrefs in DocumentRenderer - #1678

Open
tynianov1 wants to merge 1 commit into
Thinkmill:mainfrom
tynianov1:fix/document-renderer-href
Open

tynianov1 wants to merge 1 commit into
Thinkmill:mainfrom
tynianov1:fix/document-renderer-href

Conversation

@tynianov1

Copy link
Copy Markdown

Refs #1669

DocumentRenderer passes link hrefs from document content to the link renderer as is. On React 18, which is in the supported peer range, a stored javascript: link renders verbatim and runs script when clicked. React 19 blocks javascript: itself, but data: and vbscript: hrefs are still emitted.

This runs link hrefs through sanitizeUrl from @braintree/sanitize-url, the helper the document editor already uses to validate links. Unsafe schemes render as about:blank. Other URLs are unchanged. Custom link renderers receive the sanitized href too.

Testing: added packages/keystatic/src/renderer.test.tsx (unsafe schemes including mixed case and tab/newline variants, safe URLs unchanged, custom link renderer). It passes on React 19 and on React 18.3.1. Ran vitest for the keystatic project, tsc, eslint and prettier.

Link hrefs from document content were passed to the link renderer as
is. React 18 renders javascript: URLs, so a stored link could run
script on click. Hrefs now go through sanitizeUrl, the same helper the
editor uses, so unsafe schemes become about:blank.

Refs Thinkmill#1669
@tynianov1
tynianov1 requested a review from emmatown as a code owner November 20, 2026 14:15
@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d9d4fba

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@keystatic/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant