Fix unsafe HTML export by escaping project metadata#5309
Merged
walterbender merged 3 commits intosugarlabs:masterfrom Jan 28, 2026
Merged
Fix unsafe HTML export by escaping project metadata#5309walterbender merged 3 commits intosugarlabs:masterfrom
walterbender merged 3 commits intosugarlabs:masterfrom
Conversation
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
Contributor
Author
|
@walterbender sir , |
Contributor
|
✅ All Jest tests passed! This PR is ready to merge. |
Contributor
Author
|
@walterbender sir , I understand you’re busy, and I’d appreciate it if you could review this when you have time. thankyou for continuous support |
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.
fixes - #5308
PR Description
What was happening before
When a project was exported as an HTML file, several project fields (project name, description, image URL, project ID, and project data) were directly inserted into the HTML template without escaping.
Because these values can be user-provided or come from imported/shared projects, this meant that HTML or script content could unintentionally be interpreted by the browser when the exported .html file was opened. This could also break the page layout or allow unintended script execution.
What this PR changes
Context-safe HTML escaping
{{ project_name }} and {{ project_description }} are now always HTML-escaped.
{{ data }} is always rendered as text only, never as executable HTML.
Hardened attribute handling
projectid is now encodeURIComponent-encoded before being inserted into the button URL.
project_image is sanitized to allow only:
http:// and https://
relative URLs
data:image/*;base64
Unsafe schemes such as javascript: and data:text/html are rejected.
Safer template replacement
Switched to function-based template replacements to avoid$1, $ &, and related replacement-string edge cases.
Why this is useful
Music Blocks projects are frequently shared and exported as HTML files. Ensuring that exported files render project information as text (and not executable HTML) helps prevent unexpected behavior and makes sharing projects safer and more predictable for all users.
Scope
-->Minimal, self-contained change
-->No new dependencies
-->No change to user workflow or project format
--> Focused only on HTML export safety