I have created an application in java in gae and run it against checkmarx to check for security vulnerabilities and it is throwing error under the heading - Client Potential Code Injection. it shows error at the following line:
var email = $(this).text();
Below is that snippet from my code and I am not sure why it is still throwing the error when I am escaping email before using it:
$("#user-modal .user-list li").click(function() {
$("#user-modal").hide();
var email = $(this).text();
var escapedEmail = escapeHtml(email);
$("input#user").val(escapedEmail);
loadAllData(email);
});
Here is what loadAllData method does using the passed email value:
function loadAllData(email) {
$("#user-modal").modal('hide');
userEmail = email;
userParam = "";
if (userEmail) {
userParam = "?userEmail=" + userEmail;
}
requestGroups("");
requestAdminRoles("");
requestOrganizationalUnits("");
// Search
$("button.refresh-ou").bind("click", function(){
var searchString = "/" + $("input.search-ou").val();
requestOrganizationalUnits(searchString);
});
$("button.refresh-role").bind("click", function() {
var searchString = "/" + $("input.search-role").val();
requestAdminRoles(searchString);
});
$("button.refresh-group").bind("click", function() {
var searchString = "/" + $("input.search-group").val();
requestGroups(searchString);
});
}
Can anyone help?
From owasp.org > M7: Client Side Injection > How Do I Prevent ‘Client Side Injection’?:
Apparently, OP's example is more complex: the user input gets sent to a function which sets a global variable, so now the program must be examined globally.