jQuery interview question · Most asked
Which security issues have affected jQuery, and how do you protect a legacy site?
Summary
Notable issues: XSS through HTML passed to DOM-manipulation methods in versions before 3.5.0 (CVE-2020-11022 and CVE-2020-11023, around htmlPrefilter), prototype pollution in $.extend(true, ...) before 3.4.0 (CVE-2019-11358), and older XSS issues in selector handling and cross-domain AJAX. Many sites still load vulnerable versions.
Longer Answer
Protection: upgrade to the latest jQuery 3.x, check plugins too (they often bundle old copies), never pass untrusted strings to .html(), $(html) or .append(), add a Content Security Policy, and scan dependencies regularly (npm audit, Retire.js, Snyk, or the browser extension that flags vulnerable libraries). Penetration testers and automated scanners flag old jQuery versions immediately.
Key Points
- XSS fixes in 3.5.0; prototype pollution fix in 3.4.0.
- Upgrade jQuery and plugins.
- No untrusted HTML into DOM methods.
- CSP and dependency scanning.
Deep dive: Code Clinic: review a jQuery shopping cart script
More most-asked jQuery questions
- How do you make AJAX requests with jQuery?
- What is the difference between .html() and .text(), and why does it matter for security?
- What is event delegation, and why is it useful?
- What is the difference between $(document).ready(), $(fn), DOMContentLoaded and window.onload?
- How do you bind and unbind events in modern jQuery? What happened to bind, live and delegate?
- What is the difference between .attr() and .prop()?
- What is the difference between preventDefault(), stopPropagation() and returning false in a jQuery handler?
- What is jQuery, and is it still relevant today?