@@ -100,7 +100,7 @@ For full license text, see the LICENSE file in the repo root or https://opensour
100100 alert(event.message);
101101 }
102102 },
103- { escape: false }
103+ { escape: true }
104104 );
105105 },
106106 searchRecords: function (key, sObjType, cObject) {
@@ -116,13 +116,15 @@ For full license text, see the LICENSE file in the repo root or https://opensour
116116 var searchList = "";
117117 //Creating List Elements Based on Query Results
118118 var searchIcon = '{!URLFOR($Asset.SLDS, "assets/icons/utility-sprite/svg/symbols.svg#search")}';
119+ // Escape HTML to prevent XSS attacks
120+ var escapedSearchKey = j$('<div>').text(searchKey).html();
119121 searchList += '<li role="presentation" class="slds-listbox__item">' +
120122 '<div aria-selected="true" id="option0" class="slds-media slds-listbox__option slds-listbox__option_entity slds-listbox__option_term slds-has-focus" role="option">' +
121123 '<span class="slds-media__figure slds-listbox__option-icon">' +
122124 '<span class="slds-icon_container slds-icon-utility-search" title="{!$Label.ap_Search}:">' +
123125 '<svg class="slds-icon slds-icon_x-small slds-icon-text-default" aria-hidden="true"><use xlink:href="' + searchIcon + '"></use></svg>' +
124126 '<span class="slds-assistive-text">{!$Label.ap_Search}:</span></span></span>' +
125- '<span class="slds-media__body"><span class="slds-listbox__option-text slds-listbox__option-text_entity">' + searchKey + '</span></span></div > ' +
127+ '<span class="slds-media__body"><span class="slds-listbox__option-text slds-listbox__option-text_entity">' + escapedSearchKey + '</span></span></div > ' +
126128 '</li>';
127129 //Call secure search method with separate parameters
128130 var records = [];
@@ -150,9 +152,15 @@ For full license text, see the LICENSE file in the repo root or https://opensour
150152 objectIcon = '{!URLFOR($Asset.SLDS, "assets/icons/standard-sprite/svg/symbols.svg#' + iconTag + '")}';
151153 }
152154
153- searchList += '<li onclick="LightningLookupScripts{!for}.recInfo(\'' + records[i].Id + '\'' + ', \'' + sObjType.toLowerCase() + '\');" class="slds-lookup__item">';
154- searchList += '<a id="' + records[i].Id + '" href="#" role="option"><svg aria-hidden="true" class="slds-icon ' + iconStyle + ' slds-icon_small">'
155- + '<use xlink:href="' + objectIcon + '"></use></svg>' + records[i]["{!JSENCODE(displayField)}"] + '</a>';
155+ // Escape HTML and JavaScript to prevent XSS attacks
156+ var escapedId = j$('<div>').text(records[i].Id).html();
157+ var escapedDisplayField = j$('<div>').text(records[i]["{!JSENCODE(displayField)}"]).html();
158+ var escapedIdForJS = escapedId.replace(/'/g, "\\'");
159+ var escapedSObjType = sObjType.toLowerCase().replace(/'/g, "\\'");
160+
161+ searchList += '<li onclick="LightningLookupScripts{!for}.recInfo(\'' + escapedIdForJS + '\'' + ', \'' + escapedSObjType + '\');" class="slds-lookup__item">';
162+ searchList += '<a id="' + escapedId + '" href="#" role="option"><svg aria-hidden="true" class="slds-icon ' + iconStyle + ' slds-icon_small">'
163+ + '<use xlink:href="' + objectIcon + '"></use></svg>' + escapedDisplayField + '</a>';
156164 searchList += '</li>';
157165 }
158166 } else {
@@ -167,7 +175,7 @@ For full license text, see the LICENSE file in the repo root or https://opensour
167175 alert(event.message);
168176 }
169177 },
170- { escape: false }
178+ { escape: true }
171179 );
172180 }
173181 }
0 commit comments