From 762b4e88f888ce104584293c10ac5d9ea21ad6de Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Mon, 14 Nov 2022 17:16:59 +0000 Subject: [PATCH] All: Security: Fix XSS when a specially crafted string is passed to the renderer --- packages/app-cli/tests/md_to_html/sanitize_12.html | 1 + packages/app-cli/tests/md_to_html/sanitize_12.md | 3 +++ packages/renderer/MdToHtml.ts | 4 +++- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 packages/app-cli/tests/md_to_html/sanitize_12.html create mode 100644 packages/app-cli/tests/md_to_html/sanitize_12.md diff --git a/packages/app-cli/tests/md_to_html/sanitize_12.html b/packages/app-cli/tests/md_to_html/sanitize_12.html new file mode 100644 index 0000000000..c8a5e8c242 --- /dev/null +++ b/packages/app-cli/tests/md_to_html/sanitize_12.html @@ -0,0 +1 @@ +
ts
ts
diff --git a/packages/app-cli/tests/md_to_html/sanitize_12.md b/packages/app-cli/tests/md_to_html/sanitize_12.md new file mode 100644 index 0000000000..22f71bb68f --- /dev/null +++ b/packages/app-cli/tests/md_to_html/sanitize_12.md @@ -0,0 +1,3 @@ +```"> +ts +``` diff --git a/packages/renderer/MdToHtml.ts b/packages/renderer/MdToHtml.ts index 333c0e7cd3..1e57d69931 100644 --- a/packages/renderer/MdToHtml.ts +++ b/packages/renderer/MdToHtml.ts @@ -8,6 +8,8 @@ import { RenderResult, RenderResultPluginAsset } from './MarkupToHtml'; import { Options as NoteStyleOptions } from './noteStyle'; import hljs from './highlight'; +const Entities = require('html-entities').AllHtmlEntities; +const htmlentities = new Entities().encode; const MarkdownIt = require('markdown-it'); const md5 = require('md5'); @@ -482,7 +484,7 @@ export default class MdToHtml { // The strings includes the last \n that is part of the fence, // so we remove it because we need the exact code in the source block const trimmedStr = this.removeLastNewLine(str); - const sourceBlockHtml = `
${markdownIt.utils.escapeHtml(trimmedStr)}
`; + const sourceBlockHtml = `
${markdownIt.utils.escapeHtml(trimmedStr)}
`; if (this.shouldSkipHighlighting(trimmedStr, lang)) { outputCodeHtml = markdownIt.utils.escapeHtml(trimmedStr);