I am trying to render the partial view from AJAX response in ASP.NET project with below code.
$.ajax({
url: link,
data: { ID: id }
}).done(function (htmlResponse) {
$('#div_id').html(htmlResponse); //Render partial view from ajax response.
});
I have performed the security scan for the application to find the vulnerabilities.
After security scan we got the below message at $('#div_id').html(htmlResponse)
.
The application's }).done embeds untrusted data in the generated output with html, at line 26 of //partial.ascx. This untrusted data is embedded straight into the output without proper sanitization or encoding, enabling an attacker to inject malicious code into the output.
What is the best practice and how to avoid XSS attack and prevent embeds untrusted data in the generated partial view HTML from AJAX response