luci-base: form.js: do not execute embedded script code in stripTags()
authorJo-Philipp Wich <jo@mein.io>
Thu, 23 Dec 2021 16:06:09 +0000 (17:06 +0100)
committerJo-Philipp Wich <jo@mein.io>
Thu, 23 Dec 2021 16:10:32 +0000 (17:10 +0100)
Instead of relying on .innerHTML which executes embedded script code to
parse a given HTML fragment, use dom.parse() which utilizies DOMParser()
internally in order to extract textContent in a safe manner.

Fixes: FS#4199
Ref: https://bugs.openwrt.org/index.php?do=details&task_id=4199
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 993151504e8e810c083d3257555bdcdc2f00673a)

modules/luci-base/htdocs/luci-static/resources/form.js

index 72b41734932f614a80856329b30a651403c16fc9..92c53253bb7f570e4216883560769d82ef55c7f1 100644 (file)
@@ -279,7 +279,8 @@ var CBIAbstractElement = baseclass.extend(/** @lends LuCI.form.AbstractElement.p
                if (typeof(s) == 'string' && !s.match(/[<>]/))
                        return s;
 
-               var x = E('div', {}, s);
+               var x = dom.parse('<div>' + s + '</div>');
+
                return x.textContent || x.innerText || '';
        },