Repository navigation
fix(editor): sanitize HTML output from getHTML/convertHTML to prevent script injection (Snyk report) - #4837
Open
irshadmb wants to merge 3 commits into
Open
fix(editor): sanitize HTML output from getHTML/convertHTML to prevent script injection (Snyk report)#4837irshadmb wants to merge 3 commits into
irshadmb wants to merge 3 commits into
Conversation
… script injection (Snyk report)
irshadmb
commented
Oct 16, 2026
irshadmb
left a comment
Author
There was a problem hiding this comment.
Please review it, as its a security issue.
irshadmb
marked this pull request as draft
October 22, 2026 10:59
irshadmb
marked this pull request as ready for review
October 22, 2026 11:01
This branch has not been 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.
Fixes a serveral-source injection/XSS risk reported by Snyk that originates from Editor.getHTML / convertHTML returning raw DOM HTML for some blots. The change sanitizes HTML produced by the editor export so user-supplied or blot-provided HTML cannot execute script or other active content when rendered in a browser.
What I changed
Sanitize HTML produced by Editor.getHTML / convertHTML instead of returning outerHTML/innerHTML verbatim.
Remove/neutralize dangerous elements: script, iframe, object, embed, style, and similar executable/embedded elements.
Strip dangerous attributes from elements:
Remove all event handler attributes (onclick, onerror, etc.).
Remove style attributes (to avoid style-based attacks such as style-propagated URLs or expression injection).
Only allow a small whitelist of safe attributes: href, src, alt, title, width, height, colspan, rowspan, plus data-* attributes.
Validate attribute values for URL attributes:
Disallow javascript: scheme and other unsafe schemes.
Deny or strictly limit data: URIs (only allow image data: if you choose to support it, otherwise strip).
Normalize and escape attribute values when reconstructing HTML.
Reconstruct and serialize elements from their tag/allowed attributes and sanitized children (safe re-serialization) rather than copying blot.domNode.outerHTML/innerHTML directly.
Preserve benign content and common structures: lists, tables, images, anchors, and inline content are preserved as long as attributes/values are safe.
Keep existing behavior for TextBlot and list serialization but ensure text and attributes are escaped/sanitized.
Security rationale
Returning outerHTML/innerHTML directly can expose consumers to XSS if a blot or content contains scriptable HTML or unsafe attributes.
Stripping dangerous tags and attributes plus validating URL schemes prevents execution of injected JavaScript or inclusion of malicious iframes/objects.
Reconstructing elements from allowed parts prevents subtle injection vectors from attributes or inner HTML fragments.
Tests and verification
Unit tests (recommended):
getHTML of content containing <script>, <iframe>, , , <style> should return sanitized HTML without those elements.
getHTML of elements with event handlers (onclick, onerror, etc.) returns the element without event attributes.
getHTML of anchors/images with javascript: or unsafe data: URIs strips or neutralizes the href/src attribute.
getHTML of normal content (links, images, lists, tables, code blocks) preserves expected structure and safe attributes.
Manual checks:
Insert malicious markup into the editor, call getHTML, and verify rendered result in a target page does not execute code.
Verify non-malicious content still renders correctly after export.