Skip to content

Escape Unsafe HTML Characters in addon-serialize#5020

Merged
Tyriar merged 3 commits intoxtermjs:masterfrom
wavetermdev:escape-html
Apr 21, 2024
Merged

Escape Unsafe HTML Characters in addon-serialize#5020
Tyriar merged 3 commits intoxtermjs:masterfrom
wavetermdev:escape-html

Conversation

@sawka
Copy link
Copy Markdown
Contributor

@sawka sawka commented Mar 29, 2024

I was testing the addon-serialize serializeAsHTML functionality and noticed that it can produce invalid/unsafe html because it isn't escaping "<" and "&" characters in the output spans. Wrote a quick patch that escapes those two dangerous characters in the output.

Note that a lot of functions/libraries want to escape other characters (like quotes, greater than, etc.). These are only necessary to escape unless you are also worried about attribute values. These characters do not need to be escaped when you are only dealing with characters between tags (text content) which is the case here.

I added a test (which passes), but didn't put the more canonical "<script>alert("hello")</script>" test in because the test terminal only has 10 columns. All of the other serialize tests continue to pass.

@Tyriar Tyriar added this to the 5.6.0 milestone Apr 21, 2024
@Tyriar Tyriar self-assigned this Apr 21, 2024
@Tyriar Tyriar merged commit 1709d44 into xtermjs:master Apr 21, 2024
@Tyriar Tyriar modified the milestones: 5.6.0, 6.0.0 Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants