fix: replace inline event handlers with addEventListener to comply wi…#1342
Open
Jerricho93 wants to merge 1 commit into
Open
fix: replace inline event handlers with addEventListener to comply wi…#1342Jerricho93 wants to merge 1 commit into
Jerricho93 wants to merge 1 commit into
Conversation
|
@Jerricho93 is attempting to deploy a commit to the Mux Team on Vercel. A member of the Team first needs to authorize it. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
spuppo-mux
approved these changes
Jul 16, 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.
Closes #1341
The error dialog's
<media-theme>element used inlineoncloseandonfocusinattributes, which violate a strictscript-srcCSP (no'unsafe-inline', and noscript-src-attroverride). Unlike the retry link (fixed in #1332), these are not gated on user interaction; they fire on the dialog's own focus/lifecycle events, so they trip CSP essentially whenever an error dialog appears.Although the player's
htmltemplate processor rebindson*values viaaddEventListenerand strips the attribute at runtime, the literalon*=text still lives in the template HTML string that is parsed/cloned into the live DOM. The browser therefore attempts to compile the inline handler (and CSP refuses it, reportingviolated-directive: script-src-attr,blocked-uri: inline) before the processor removes the attribute.Changes
mux-player: Removes theonclose/onfocusinattributes from the<media-theme>template. The two handlers are now bound programmatically on themedia-themeelement viaaddEventListenerin#setUpErrors, with matching cleanup indisconnectedCallback. The handlers keep their existingcomposedPath()/media-error-dialogguards, so behavior is unchanged.onCloseErrorDialog/onFocusInErrorDialogtemplate props fromMuxTemplateProps.template.test.jsregression test asserting the rendered template contains no inlineon*event-handler attributes. It checks the raw template string (pre part-processing), since that is what the browser parses into the DOM and what CSP evaluates (the post-render DOM would hide the regression because the processor strips the attributes).Testing
npm testinpackages/mux-player— 134 passing, 0 failed.player.test.js) continue to pass, confirming the reboundclose/focusinhandlers behave identically.grep -oE '\bon[a-z]+="[^"]*"' dist/mux-player.mjsreturns no error-dialog handlers after build.Notes
onclickfrom the retry link. Together they clear all inline event-handler attributes from the error-dialog path so consumers (e.g. theplayer.mux.comiframe embed) can enforce a strictscript-srcwithout'unsafe-inline'.'unsafe-inline'is introduced; the fix is purelyaddEventListener-based.Note
Low Risk
Small, localized wiring change with existing tests and a CSP regression guard; no auth or data-path changes.
Overview
Removes inline
onclose/onfocusinfrom the<media-theme>template so strictscript-src(no'unsafe-inline') no longer tripsscript-src-attrwhen the error dialog appears. The browser evaluates inline handlers in the parsed template string before thehtmlprocessor can strip them.Error-dialog close and focus behavior is unchanged:
#onCloseErrorDialogand#onFocusInErrorDialogare class fields with the samecomposedPath()/media-error-dialogguards, wired in#setUpErrorswithaddEventListener('close'|'focusin')onmediaThemeand removed indisconnectedCallback. The corresponding props are dropped fromMuxTemplateProps.Adds a regression test that the raw template HTML (pre part-processing) contains no
on*event-handler attributes, since post-render DOM would hide a reintroduction.Reviewed by Cursor Bugbot for commit 0dbffa3. Bugbot is set up for automated code reviews on this repo. Configure here.