fix: replace innerHTML with textContent across core widgets for security#7757
Merged
walterbender merged 3 commits intoJul 9, 2026
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7757 +/- ##
==========================================
+ Coverage 56.80% 56.81% +0.01%
==========================================
Files 172 172
Lines 57683 57701 +18
==========================================
+ Hits 32767 32784 +17
- Misses 24916 24917 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
e141ca7 to
319393f
Compare
Ashutoshx7
approved these changes
Jul 7, 2026
Member
|
@walterbender lgtm |
Chaitu7032
approved these changes
Jul 8, 2026
rakshityadav1868
pushed a commit
to rakshityadav1868/musicblocks
that referenced
this pull request
Jul 9, 2026
…ity (sugarlabs#7757) * fix: replace innerHTML with textContent in jseditor.js * fix: replace innerHTML with textContent in turtles.js, palette.js, and toolbar-ui.js * test: update toolbar and palette tests to match textContent refactor
1 task
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.
Description
This PR replaces multiple usages of
innerHTMLwith safer DOM manipulation methods (textContentandcreateElement) across four core files (jseditor.js,turtles.js,palette.js, andtoolbar-ui.js). These changes mitigate potential Cross-Site Scripting (XSS) risks by avoiding unnecessary HTML parsing for plain text updates (such as Material Icons and Unicode characters).PR Category
Changes Made
jseditor.js: ReplacedinnerHTMLwithtextContentfor and console toggle arrows.turtles.js: ReplacedinnerHTMLwithtextContentwhen updating the Material Icons "menu" text.palette.js: SwappedinnerHTMLfortextContenton toggle arrows and refactored a complexinnerHTMLtable header cell to usedocument.createElement.toolbar-ui.js: ReplacedinnerHTMLwithtextContentfor plain text string assignments. Refactored icon tags (<i>and<img>) to usedocument.createElement(), and usednode.cloneNode()instead ofinnerHTMLto duplicate the theme select icon.Testing Performed
textContentfor Material Icons.npx jest js/widgets/__tests__/jseditor.test.jssuccessfully (54/54 passed).npx jest js/__tests__/turtles.test.jssuccessfully (45/45 passed).Checklist
npm run lintandnpx prettier --check .with no errors.Additional Notes for Reviewers
These changes follow the same security improvements recently made in other widgets. Using
textContentfor Material Icon strings is fully supported by the CSS font-family implementation and avoids triggering the browser's HTML parser entirely.