From dfc7ee40328b54339a03123bb10adf9a3bc1f74a Mon Sep 17 00:00:00 2001 From: Jacques Le Roux Date: Mon, 8 Nov 2021 13:14:24 +0100 Subject: [PATCH] Improved: Fix OFBiz speficic Javascript securiy issues reported by GH CodeQL (OFBIZ-12366) Fixes "A DOM text reinterpreted as HTML" issue in fieldlookup.js GH CodeQL reports: "A webpage with this vulnerability reads text from the DOM, and afterwards adds the text as HTML to the DOM. Using text from the DOM as HTML effectively unescapes the text, and thereby invalidates any escaping done on the text. If an attacker is able to control the safe sanitized text, then this vulnerability can be exploited to perform a cross-site scripting attack. Recommendation To guard against cross-site scripting, consider using contextual output encoding/escaping before writing text to the page, or one of the other solutions that are mentioned in the References section below. Example "Extracting text from a DOM node and interpreting it as HTML can lead to a cross-site scripting vulnerability." GH CodeQL suggest: The above vulnerability can be fixed by using $.find instead of $. The $.find function will only interpret target as a CSS selector and never as HTML, thereby preventing an XSS attack. --- themes/common-theme/webapp/common/js/util/fieldlookup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/common-theme/webapp/common/js/util/fieldlookup.js b/themes/common-theme/webapp/common/js/util/fieldlookup.js index 7f6e38b182..5d8029cb13 100644 --- a/themes/common-theme/webapp/common/js/util/fieldlookup.js +++ b/themes/common-theme/webapp/common/js/util/fieldlookup.js @@ -304,7 +304,7 @@ var Lookup = function(options) { var queryArgs = "presentation=" + options.presentation; if (typeof options.args == "object" && jQuery.isArray(options.args)) { for ( var i = 0; i < options.args.length; i++) { - queryArgs += "&parm" + i + "=" + jQuery(options.args[i]).val(); + queryArgs += "&parm" + i + "=" + jQuery(jQuery.find(options.args[i]).val()); } }