Skip to content

Commit

Permalink
Desktop,Mobile: Security: Improve comment escaping (#11706)
Browse files Browse the repository at this point in the history
  • Loading branch information
personalizedrefrigerator authored Jan 23, 2025
1 parent d621e63 commit 2a058ed
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/app-cli/tests/md_to_html/sanitize_21.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Should keep this comment: <!-- keep this &amp; that -->
Should keep this comment: <!-- keep this & that -->
1 change: 1 addition & 0 deletions packages/app-cli/tests/md_to_html/sanitize_23.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<math class="jop-noMdConv"><p class="jop-noMdConv"><style class="jop-noMdConv"><!--&lt;/style&gt;&lt;img src onerror=alert(1)&gt;--></style>
1 change: 1 addition & 0 deletions packages/app-cli/tests/md_to_html/sanitize_23.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<math><p><style><!--</style><img src onerror=alert(1)>--></style>
6 changes: 4 additions & 2 deletions packages/renderer/htmlUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,10 @@ class HtmlUtils {

const parser = new htmlparser2.Parser({

oncomment: (encodedData: string) => {
output.push(`<!--${encodedData}-->`);
oncomment: (data: string) => {
// Ensure that <s and >s are escaped within comments. In some cases,
// these characters can end a comment early (e.g. <style><!--</style>-->)
output.push(`<!--${htmlentities(data)}-->`);
},

onopentag: (name: string, attrs: Record<string, string>) => {
Expand Down

0 comments on commit 2a058ed

Please sign in to comment.