luci-base: form.js: do not execute embedded script code in stripTags()
authorJo-Philipp Wich <[email protected]>
Thu, 23 Dec 2021 16:06:09 +0000 (17:06 +0100)
committerJo-Philipp Wich <[email protected]>
Thu, 23 Dec 2021 16:08:21 +0000 (17:08 +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 <[email protected]>
modules/luci-base/htdocs/luci-static/resources/form.js

index 312d83605ddabbf315985eacf406c4bdf83563c1..23cc0b1cb574778565391f9884763889f8fdb971 100644 (file)
@@ -287,7 +287,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 || '';
        },