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.
This commit is contained in:
Jacques Le Roux
2021-11-08 13:14:24 +01:00
parent d83603f064
commit dfc7ee4032
@@ -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());
}
}