From 2b9dc165cd03ce48b93784ded566d12ed882fcfc Mon Sep 17 00:00:00 2001 From: JannisX11 Date: Tue, 24 Jan 2023 19:05:25 +0100 Subject: [PATCH] Implement dom purify --- index.html | 1 + js/interface/about.js | 1 + js/interface/dialog.js | 6 +++--- js/interface/start_screen.js | 17 +++++++++-------- js/plugin_loader.js | 3 ++- js/util.js | 22 +++++----------------- js/validator.js | 4 ++-- lib/purify.min.js | 2 ++ 8 files changed, 25 insertions(+), 31 deletions(-) create mode 100644 lib/purify.min.js diff --git a/index.html b/index.html index 4f4996c2..65dbd9d6 100644 --- a/index.html +++ b/index.html @@ -74,6 +74,7 @@ + diff --git a/js/interface/about.js b/js/interface/about.js index 7c27991a..00801f63 100644 --- a/js/interface/about.js +++ b/js/interface/about.js @@ -116,6 +116,7 @@ BARS.defineActions(() => {
  • FileSaver.js
  • PeerJS
  • Marked
  • +
  • DOMPurify
  • Prism
  • Canvas2APNG
  • Vue Prism Editor
  • diff --git a/js/interface/dialog.js b/js/interface/dialog.js index ffb6d9ec..98cf628a 100644 --- a/js/interface/dialog.js +++ b/js/interface/dialog.js @@ -116,7 +116,7 @@ function buildForm(dialog) { case 'info': - data.text = marked(tl(data.text)) + data.text = pureMarked(tl(data.text)) bar.append(`

    ${data.text}

    `) bar.addClass('small_text') break; @@ -328,7 +328,7 @@ function buildLines(dialog) { dialog.uses_wide_inputs = true; dialog_content.append(bar) } else { - dialog_content.append(l) + dialog_content.append(DOMPurify.sanitize(l)) } }) } @@ -877,7 +877,7 @@ window.MessageBox = class MessageBox extends Dialog { if (options.message) { content.append($('
    '+ - marked(tl(options.message))+ + pureMarked(tl(options.message))+ '
    ')[0]); } if (options.icon) { diff --git a/js/interface/start_screen.js b/js/interface/start_screen.js index 2f094bfe..72e67bf1 100644 --- a/js/interface/start_screen.js +++ b/js/interface/start_screen.js @@ -35,7 +35,7 @@ function addStartScreenSection(id, data) { if (data.graphic.aspect_ratio) left.css('aspect-ratio', data.graphic.aspect_ratio); } if (data.graphic.description) { - let content = $(marked(data.graphic.description)); + let content = $(pureMarked(data.graphic.description)); content.addClass('start_screen_graphic_description') content.css({ 'color': data.graphic.text_color || '#ffffff', @@ -47,7 +47,7 @@ function addStartScreenSection(id, data) { var right = $('
    ') obj.append(right) data.text.forEach(line => { - var content = line.text ? marked(tl(line.text)) : ''; + var content = line.text ? pureMarked(tl(line.text)) : ''; switch (line.type) { case 'h1': var tag = 'h1'; break; case 'h2': var tag = 'h3'; break; @@ -55,7 +55,7 @@ function addStartScreenSection(id, data) { case 'list': var tag = 'ul class="list_style"'; line.list.forEach(string => { - content += `
  • ${marked(tl(string))}
  • `; + content += `
  • ${pureMarked(tl(string))}
  • `; }) break; case 'button': var tag = 'button'; break; @@ -269,6 +269,7 @@ onVueSetup(function() { openLink(link) { Blockbench.openLink(link); }, + pureMarked, tl }, computed: { @@ -351,11 +352,11 @@ onVueSetup(function() { diff --git a/js/plugin_loader.js b/js/plugin_loader.js index 62183ad8..f2860d7b 100644 --- a/js/plugin_loader.js +++ b/js/plugin_loader.js @@ -565,6 +565,7 @@ BARS.defineActions(function() { } }, getIconNode: Blockbench.getIconNode, + pureMarked, tl }, template: ` @@ -595,7 +596,7 @@ BARS.defineActions(function() {
    {{ tl('dialog.plugins.author', [plugin.author]) }}
    {{ plugin.description }}
    -
    +
    ${tl('dialog.plugins.show_less')}