From 4e4481cf9609aef9bedbe8c9e38b5f57ba686518 Mon Sep 17 00:00:00 2001 From: jean-emmanuel Date: Wed, 10 Sep 2025 11:06:15 +0200 Subject: [PATCH] widget: unrestrict html property (yes, let users break the app eventually), speeds up build times 2x --- CHANGELOG.md | 4 ++++ package.json | 1 - src/client/widgets/common/widget.js | 23 ++--------------------- src/client/widgets/frames/html.js | 3 +-- 4 files changed, 7 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70c2cc19..e27c50d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ - bug fixes - server: fix resolving absolute file urls containing the remote-root path +- widgets + - the html property is no longer restricted / sanitized + + ## 1.29.8 diff --git a/package.json b/package.json index 8bc78ba5..5fc52c16 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,6 @@ "rollup-plugin-copy": "3.5.0", "rollup-plugin-license": "^3.6.0", "rollup-plugin-node-externals": "^8.1.1", - "sanitize-html": "1.27.5", "sass": "1.89.2", "scope-css": "1.2.1", "screenfull": "5.2.0", diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js index 2739e714..11e2869e 100644 --- a/src/client/widgets/common/widget.js +++ b/src/client/widgets/common/widget.js @@ -11,7 +11,6 @@ var EventEmitter = require('../../events/event-emitter'), {deepCopy, deepEqual, isJSON} = require('../../utils'), html = require('nanohtml/lib/browser'), morph = require('nanomorph'), - sanitizeHtml = require('sanitize-html'), updateWidget = ()=>{}, Script = require('../scripts/script'), uiConsole, uiTree, uiDragResize, sessionManager @@ -82,13 +81,7 @@ class Widget extends EventEmitter { html: {type: 'string', value: '', editor: 'html', syntaxChecker: false, help: [ 'Custom html content to be inserted in the widget (before the widget\'s content). Elements are all unstyled by default, `css` should be used to customize their appearance.', 'The code is automatically wrapped in <div class="html"></div>', - 'Allowed HTML tags:', - '  h1-6, blockquote, p, a, ul, ol, nl, li,', - '  b, i, strong, em, strike, code, hr, br, div,', - '  table, thead, img, caption, tbody, tr, th, td, pre', - 'Allowed attributes:', - '  <*>: class, style, title, name', - '  <img>: src, width, height', + 'Note: inserting scripts may break the application.', ]}, css: {type: 'string', value: '', editor: 'css', syntaxChecker: false, help: [ 'CSS rules. See documentation.', @@ -1278,7 +1271,7 @@ class Widget extends EventEmitter { updateHtml(){ - var extraHtml = this.getProp('html') !== '' ? sanitizeHtml(this.getProp('html'), Widget.sanitizeHtmlOptions) : null + var extraHtml = this.getProp('html') || null if (this.extraHtml) { if (!extraHtml) { @@ -1346,18 +1339,6 @@ class Widget extends EventEmitter { } -Widget.sanitizeHtmlOptions = { - allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe'), - allowedAttributes: { - '*': [ 'title', 'class', 'style', 'name'], - 'img': [ 'src' , 'title', 'class', 'style', 'width', 'height'], - 'a': ['href', 'target'] - }, - transformTags: { - 'a': sanitizeHtml.simpleTransform('a', {target: '_blank'}) - } -} - Widget.parsersContexts = {} Widget.cssVariables = [ diff --git a/src/client/widgets/frames/html.js b/src/client/widgets/frames/html.js index 91ddfa93..261f1f2c 100644 --- a/src/client/widgets/frames/html.js +++ b/src/client/widgets/frames/html.js @@ -1,7 +1,6 @@ var Widget = require('../common/widget'), morph = require('nanomorph'), html = require('nanohtml/lib/browser'), - sanitizeHtml = require('sanitize-html'), StaticProperties = require('../mixins/static_properties') class Html extends StaticProperties(Widget, {bypass: true}) { @@ -49,7 +48,7 @@ class Html extends StaticProperties(Widget, {bypass: true}) { var newHtml = this.frame.cloneNode(false) - newHtml.innerHTML = sanitizeHtml(this.getProp('html'), Widget.sanitizeHtmlOptions) + newHtml.innerHTML = this.getProp('html') morph(this.frame, newHtml)