Discuss the security concerns associated with using jQuery's .html() method.
Instruction: Explain the potential security vulnerabilities of using the .html() method to dynamically insert content into a web page and how to mitigate these risks.
Context: Evaluates the candidate's awareness of web security practices, specifically in the context of safely manipulating HTML content with jQuery.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
.html(string) parses its input as HTML. Untrusted text from a form, URL, API response or stored record can become executable markup, including event-handler attributes. Server origin or prior storage does not make that content trustworthy. jQuery methods accepting HTML strings, including .append(), have the same general risk...