Repository navigation
fix: escape attribute values in template HTML - #265
Merged
Merged
Conversation
The template builder wrote attribute values into the HTML string with no escape. A value that has quotes or angle brackets changed the shadow DOM markup. The builder now escapes the special HTML characters. The native media element gets the same attribute values as before, and the HTML from getTemplateHTML stays valid for server rendering.
getTemplateHTML writes the config as JSON in a script element. A config string with a closing script tag ended that element too early. The "<" character is now written as a JSON unicode escape, so JSON.parse gives the same config.
Use the same attribute escape as the other iframe based elements.
Use the same attribute escape as the other iframe based elements.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
luwes
reviewed
Oct 14, 2026
luwes
requested changes
Oct 14, 2026
luwes
left a comment
Collaborator
There was a problem hiding this comment.
does key need escaping there?
Escape the attribute names the same way as the values, so the template HTML stays correct for all input.
Merged
This branch was successfully 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.
The media elements make their shadow DOM from an HTML string. The attribute values went into that string with no escape. A value with quotes or angle brackets changed the markup in the shadow root. Server rendered pages that use the React wrappers had the same problem.
Changes
The native media element gets the same attribute values as before. The HTML from
getTemplateHTMLstays valid for server rendering. Subclasses that overridegetTemplateHTMLneed no change.Tests
getTemplateHTMLoutput keeps all attribute values.Note
Medium Risk
Security fix in shadow-DOM/SSR template generation with broad impact on elements using the shared serializer; logic is localized and covered by new regression tests.
Overview
Fixes HTML injection when custom media elements build shadow DOM from string templates: attribute names and values are now passed through
escapeHtmlinserializeAttributes(custom-media-element,cloudflare-video-element,spotify-audio-element), so quotes and angle brackets in values cannot break out of attributes or inject extra markup.For HLS, embedded config JSON in the template
<script>now escapes<as\u003cso malicious config strings cannot close the script tag.Behavior preserved: forwarded attributes on the native
<video>/<audio>/iframe still get the original values; only the serialized template HTML is escaped. New browser tests cover maliciousposter/crossoriginvalues, unchanged normal attributes,getTemplateHTMLoutput, and HLS config staying in a single parseable script.Reviewed by Cursor Bugbot for commit c8fd03c. Bugbot is set up for automated code reviews on this repo. Configure here.