Repository navigation
Sanitize merchant-managed HTML in the markets recipe - #4278
Merged
Merged
Conversation
Contributor
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
lucyxiang
force-pushed
the
lucy/markets-sanitize-html
branch
2 times, most recently
from
October 29, 2026 04:17
60b90fa to
64cf707
Compare
frandiox
approved these changes
Nov 2, 2026
frandiox
left a comment
Contributor
There was a problem hiding this comment.
We could also rely directly on sanitize-html package but I guess for the cookbook it's not so important 👍
fredericoo
requested changes
Nov 2, 2026
lucyxiang
force-pushed
the
lucy/markets-sanitize-html
branch
from
November 2, 2026 16:48
17f10e1 to
c4e6c0b
Compare
The page, article, policy and product routes in the markets recipe render Storefront API HTML with dangerouslySetInnerHTML. Add an allowlist sanitizeHtml() ingredient and call it in each loader. - Keep formatting, lists, tables, images and safe links. Remove elements, attributes and URLs that can run script, and remove embeds, `style` and `id` attributes. - Decode character references before URL checks, and escape text attributes such as `alt` and `title` like text. - Keep the nofollow, sponsored, ugc, noopener and noreferrer rel tokens, and force noopener noreferrer on target="_blank" links. - Write the end tags that the browser implies for li, dd, dt, p and a nested table, and drop table parts outside a table. - Handle `/>` as the browser does: ignore it on non-void HTML elements, and treat it as a closed element in skipped SVG and MathML. - Run in linear time on unmatched end tags, unterminated start tags and long whitespace runs in URLs.
lucyxiang
force-pushed
the
lucy/markets-sanitize-html
branch
from
November 2, 2026 17:04
c4e6c0b to
e9e1ea1
Compare
fredericoo
approved these changes
Nov 2, 2026
lucyxiang
enabled auto-merge
November 2, 2026 17:34
lucyxiang
disabled auto-merge
November 2, 2026 17:39
lucyxiang
added a commit
that referenced
this pull request
Nov 2, 2026
The markets recipe README and LLM prompt link to files at the commit in recipe.yaml. That commit was older than #4278, so the links to sanitizeHtml.ts returned 404. Set the commit to the #4278 merge commit and render the README and prompt again. The Deleted Files links also returned 404. The deletedFiles paths already start with templates/skeleton/, and render.ts added that prefix again. Remove the extra prefix, and fix the same links in the express and multipass READMEs.
devteamaegis
pushed a commit
to devteamaegis/hydrogen
that referenced
this pull request
Nov 3, 2026
…#4291) The markets recipe README and LLM prompt link to files at the commit in recipe.yaml. That commit was older than Shopify#4278, so the links to sanitizeHtml.ts returned 404. Set the commit to the Shopify#4278 merge commit and render the README and prompt again. The Deleted Files links also returned 404. The deletedFiles paths already start with templates/skeleton/, and render.ts added that prefix again. Remove the extra prefix, and fix the same links in the express and multipass READMEs.
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.
The markets recipe renders merchant-managed HTML from the Storefront API with
dangerouslySetInnerHTMLand does not sanitize it. A<script>tag or anonerrorhandler in a page, article, policy or product description runs for every visitor. This PR adds an allowlist sanitizer and calls it in each loader.What this changes
app/lib/sanitizeHtml.tsingredient. It has no dependencies, so it runs in Oxygen, Node and the browser.details, images (http/https) and links (http,https,mailto,tel, relative).script,style,iframe,object,embed,svg,math, form controls,on*handlers,styleattributes and other URL schemes.Page.body,Article.contentHtml,ShopPolicy.bodyandProduct.descriptionHtmlin their loaders.recipe.yaml, and gives thepackage.jsonstep a description. The description wasnull.README.mdandllms/markets.prompt.md, and adds__tests__/sanitizeHtml.test.ts.No changeset. The cookbook does not ship in a package.
Risk