This document is designed as a security spec that supports:
This document is designed as a security spec that supports:
It is intentionally written as a set of normative requirements (“MUST/SHOULD/MAY”) plus audit rules (what bad patterns look like, how to detect them, and how to fix/mitigate them).
unsafe-inline, enabling JSONP “because it works”, adding broad CORS, disabling sanitization, suppressing security checks).When asked to write new jQuery code or modify existing jQuery code:
While working anywhere in a repo that uses jQuery (even if the user did not ask for a security scan):
When the user asks to “scan”, “audit”, or “hunt for vulns”:
Recommended audit order:
.html, .append, $("<…>"), .load, etc.).dataType:"script", $.getScript, dynamic <script> insertion.href, src, style, on* attributes).$.extend patterns).Examples include:
location.href, location.search, location.hashdocument.URL, document.baseURI, document.referrerwindow.namelocalStorage / sessionStoragepostMessage event data (unless strict origin and schema validation exists)A sink is a code path where untrusted input can become interpreted as executable code or HTML.
Key jQuery sink categories:
.html(), .append(), and related methods (see CVE notes below). ([NVD][1])$(htmlString) (when the argument can be interpreted as HTML markup).jQuery.parseHTML(html, …, keepScripts) especially with keepScripts=true. ([jQuery API][2]).load(url) (loads HTML into DOM; has special script execution behavior). ([jQuery API][3])$.getScript() / $.ajax({ dataType: "script" }) (executes fetched JavaScript). ([jQuery API][4])dataType: "jsonp" or implicit JSONP behavior) (executes remote JavaScript as a response). ([jQuery API][5])eval, new Function, setTimeout("…"), setInterval("…"), $.globalEval (if present)href, src, srcdoc, style, or event-handler attributes (onload, onclick, etc.)javascript: URLs are particularly dangerous and discouraged. ([MDN Web Docs][6])For each issue found, output:
This is the smallest “production baseline” that prevents common jQuery-related security failures.
integrity) and correct crossorigin settings; the jQuery project explicitly supports and recommends SRI on its CDN. (Retrieved from [jquery.com][8])script-src restrictions and avoiding unsafe-inline). If not done through HTTP server, this can be done through the <meta http-equiv="Content-Security-Policy" content="..."> tag. ([OWASP Cheat Sheet Series][9]) NOTE: It is most important to set the CSP's script-src. All other directives are not as important and can generally be excluded for the ease of development.require-trusted-types-for, then code MUST route DOM-injection through Trusted Types policies. ([MDN Web Docs][11])require-trusted-types-for. ([blog.jquery.com][7])Even though these are typically set server-side, they materially reduce the blast radius of jQuery-related mistakes. However if the context is only the frontend web application, these cannot be acted on.
X-Content-Type-Options: nosniff, clickjacking protection via frame-ancestors / X-Frame-Options, Referrer-Policy). ([OWASP Cheat Sheet Series][12])localStorage) unless the threat model explicitly accepts “XSS == account takeover”. This is not jQuery-specific, but jQuery-heavy DOM manipulation increases the chance of DOM XSS regressions; reduce the payoff.Each rule contains: required practice, insecure patterns, detection hints, and remediation.
Severity: Medium (High if internet-facing app AND version is known-vulnerable)
NOTE: Before performing an upgrade, get concent from the user and try to understand if they have reasons to keep it back. Upgrading can break applications in unexpected ways. Report and recommend upgrades rather than just performing them.
Required:
Insecure patterns:
jquery-1., jquery-2., jquery-3.3., jquery-3.4., jquery-3.4.1, etc.).Detection hints:
jquery- and parse version strings.package.json, package-lock.json, yarn.lock, pnpm-lock.yaml.vendor/, public/, static/, assets/, wwwroot/ for jquery*.js.Fix:
Notes:
Severity: High
Required:
integrity) and correct crossorigin handling. ([jquery.com][8])Insecure patterns:
<script src="https://…/jquery.min.js"></script> with no integrity.Detection hints:
<script src= and check for integrity= + crossorigin=.Fix:
Note: If unable to get the correct SRI tag, skip this step but tell the user. If you end up using the wrong one the app will not function. In that case remove it and inform the user.
Severity: High (if attacker-controlled content reaches these sinks)
Required:
.text(untrusted) (text, not HTML). ([jQuery API][14]).val(untrusted) for form fields. ([jQuery API][15])Insecure patterns (examples):
$(selector).html(untrusted)$(selector).append(untrusted)$(selector).before(untrusted) / .after(untrusted) / .replaceWith(untrusted) / .wrap(untrusted) (and similar)"<div>" + untrusted + "</div>" then passing to jQueryDetection hints:
.html(, .append(, .prepend(, .before(, .after(, .replaceWith(, .wrap(, .wrapAll(, .wrapInner(Fix:
.text() / .val() or node construction:const $el = $("<span>").text(untrusted); container.append($el);Notes:
Severity: Medium (High if rich HTML is attacker-controlled and sanitizer is weak/misconfigured)
Required:
Insecure patterns:
<script>” or “escape <” attempts followed by .html() insertion.Detection hints:
</> patterns, or “allow all tags” configs..html() or equivalent sinks.Fix:
False positive notes:
$(untrustedString) and jQuery.parseHTML MUST NOT process attacker-controlled markupSeverity: High (if attacker-controlled)
Required:
$() when they might be interpreted as HTML.jQuery.parseHTML(html, …, keepScripts) as a high-risk primitive; keepScripts MUST be false for any untrusted input. ([jQuery API][2])Insecure patterns:
const $node = $(untrusted);$.parseHTML(untrusted, / context /, true) (scripts preserved)Detection hints:
$( calls where the argument is not a static selector or static markup.$.parseHTML( and inspect the keepScripts argument.Fix:
.text() for untrusted values..load() MUST be treated as an HTML+script injection surfaceSeverity: Medium (High if URL/content is attacker-controlled)
Required:
.load() with attacker-controlled URLs or attacker-controlled HTML fragments..load() script behavior:.html() before scripts are removed, which can execute scripts. ([jQuery API][3])fetch()/XHR to retrieve data, then render with safe DOM creation or sanitize explicitly.Insecure patterns:
$("#target").load(untrustedUrl)$("#target").load("/path?param=" + untrusted)Detection hints:
.load( across JS/TS files.Fix:
.load() with:fetch() to retrieve JSON, then render via .text() / node construction, orfetch() to retrieve HTML, sanitize it, then inject..load() must remain, ensure the URL is constant or strictly allowlisted and the returned content is trusted.Severity: High
Required:
$.getScript(url) executes the fetched script in the global context. ([jQuery API][4])$.ajax({ dataType: "script" }) and other script-typed requests that execute responses.Insecure patterns:
$.getScript(untrustedUrl)$.ajax({ url: untrustedUrl, dataType: "script" })<script src=...> injection where src is derived from untrusted input.Detection hints:
getScript(, dataType: "script", globalEval, eval, new Function.Fix:
Severity: Medium (High if attacker can influence URL/endpoint)
Required:
$.ajax, MUST explicitly disable JSONP for non-fully-trusted targets; jQuery’s own docs recommend setting jsonp: false “for security reasons” if you don’t trust the target. ([jQuery API][5])dataType: "json") and explicit origin allowlists server-side.Insecure patterns:
dataType: "jsonp"callback=? or patterns that trigger JSONP behavior. callback arguments are historically XSS vectors.$.get(untrustedUrl) without pinning dataType and disabling JSONP (risk depends on options and jQuery behavior)Detection hints:
jsonp, dataType: "jsonp", callback=?.Fix:
dataType: "json"jsonp: false (defense in depth when URL might be ambiguous) ([jQuery API][5])Severity: High
NOTE: This only matters when using cookie based auth. If the request use Authorization header, there is no CSRF potential.
Required:
Insecure patterns:
$.post("/transfer", {...}) or $.ajax({ method: "POST", ... }) with cookie auth and no CSRF token/header.X-Requested-With (defense-in-depth only, not primary).Detection hints:
Fix:
$.ajaxSetup({ headers: { "X-CSRF-Token": token } }), and ensure server verifies.False positive notes:
Severity: Low (High for events like onclick)
Required:
href, src, action, etc.javascript: URLs are discouraged because they can execute code. ([MDN Web Docs][6])onclick, onerror, etc.) from strings.style attributes; prefer toggling predefined CSS classes.Insecure patterns:
$("a").attr("href", untrustedUrl)$("img").attr("src", untrustedUrl)$(el).attr("style", untrustedCss)$(el).attr("onclick", untrustedJs)Detection hints:
.attr("href", .attr("src", .attr("style", .prop("href", .prop("src".Fix:
new URL(value, location.origin) and allowlist protocols (https: etc.) and hostnames when needed.style strings with addClass/removeClass using predefined class names.jQuery.escapeSelectorSeverity: Medium (can become High if it enables wrong-element selection in security-relevant UI)
Required:
jQuery.escapeSelector() (available in jQuery 3.0+). ([jQuery API][20])Insecure patterns:
$("#" + untrustedId)$("[data-id='" + untrusted + "']") (especially without strict quoting/escaping)Detection hints:
"#" +, ". " +, or template strings used inside $( selectors.Fix:
$("#" + $.escapeSelector(untrustedId)) ([jQuery API][20])Notes:
Severity: Medium
Required:
$.extend(true, …)) attacker-controlled objects into application objects without filtering dangerous keys.Insecure patterns:
$.extend(true, target, untrustedObj)$.extend(true, {}, defaults, untrustedObj) where untrustedObj comes from URL/JSON/storageDetection hints:
$.extend(true and inspect sources of merged objects.Fix:
__proto__, prototype, constructor, and nested occurrences.Severity: Medium
Required:
require-trusted-types-for), MUST ensure DOM injection goes through Trusted Types policies. ([MDN Web Docs][11])Insecure patterns:
script-src 'unsafe-inline' / 'unsafe-eval') without a compensating plan.Detection hints:
Fix:
script-src.When actively scanning, use these high-signal patterns:
jquery-*.js in vendor/ or static/package.json dependency jquery pinned to old versionsintegrity/crossorigin ([jquery.com][8]).html(, .append(, .prepend(, .before(, .after(, .replaceWith(, .wrap($( where argument might be HTML / template strings$.parseHTML( especially with keepScripts=true ([jQuery API][2]).load( (and whether selector is appended; script behavior differs) ([jQuery API][3])$.getScript(, dataType: "script" ([jQuery API][4])dataType: "jsonp" or jsonp: usage; callback=? patterns ([jQuery API][5])eval, new Function, setTimeout("…"), $.globalEval.attr("href", …), .attr("src", …), .attr("style", …)javascript:-like schemes or suspicious URL construction ([MDN Web Docs][6])$("#" + user) and similar; fix via $.escapeSelector ([jQuery API][20])$.extend(true, …, userObj); ensure jQuery >= 3.4.0 and filter dangerous keys ([NVD][13])$.post( / $.ajax({ method: ... }) with cookies and no CSRF token/header ([OWASP Cheat Sheet Series][19])Always try to confirm:
Primary jQuery project documentation and release notes:
https://blog.jquery.com/2026/01/17/jquery-4-0-0/. ([blog.jquery.com][7])https://jquery.com/download/. ([jquery.com][8]).html(): https://api.jquery.com/html/. ([jQuery API][21]).text(): https://api.jquery.com/text/. ([jQuery API][14]).append(): https://api.jquery.com/append/. ([jQuery API][22]).load() (script execution behavior): https://api.jquery.com/load/. ([jQuery API][3])jQuery.parseHTML(…, keepScripts): https://api.jquery.com/jQuery.parseHTML/. ([jQuery API][2])$.ajax() (jsonp: false security note): https://api.jquery.com/jQuery.ajax/. ([jQuery API][5])$.getScript() (executes script): https://api.jquery.com/jQuery.getScript/. ([jQuery API][4])jQuery.escapeSelector(): https://api.jquery.com/jQuery.escapeSelector/. ([jQuery API][20])jQuery vulnerabilities / advisories:
https://nvd.nist.gov/vuln/detail/CVE-2019-11358. ([NVD][13])https://nvd.nist.gov/vuln/detail/CVE-2020-11022. ([NVD][1])<option>; patched in 3.5.0): https://nvd.nist.gov/vuln/detail/CVE-2020-11023. ([NVD][23])https://github.com/jquery/jquery/security/advisories/GHSA-gxr4-xjj5-5px2. ([GitHub][16])OWASP Cheat Sheet Series (web app security foundations relevant to jQuery usage):
https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html. ([OWASP Cheat Sheet Series][24])https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html. ([OWASP Cheat Sheet Series][25])https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html. ([OWASP Cheat Sheet Series][19])https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html. ([OWASP Cheat Sheet Series][12])https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html. ([OWASP Cheat Sheet Series][9])Browser/platform references (SRI, CSP, Trusted Types, and dangerous URL schemes):
https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity. ([MDN Web Docs][26])https://www.w3.org/TR/sri-2/. ([W3C][27])https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP. ([MDN Web Docs][28])require-trusted-types-for directive: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/require-trusted-types-for. ([MDN Web Docs][11])https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API. ([MDN Web Docs][29])https://www.w3.org/TR/trusted-types/. ([W3C][10])javascript: URL scheme warning: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/javascript. ([MDN Web Docs][6])https://github.com/cure53/DOMPurify. ([GitHub][17])[1]: https://nvd.nist.gov/vuln/detail/cve-2020-11022?utm_source=chatgpt.com "CVE-2020-11022 Detail - NVD" [2]: https://api.jquery.com/jQuery.parseHTML/?utm_source=chatgpt.com "jQuery.parseHTML()" [3]: https://api.jquery.com/load/?utm_source=chatgpt.com ".load() | jQuery API Documentation" [4]: https://api.jquery.com/jQuery.getScript/?utm_source=chatgpt.com "jQuery.getScript()" [5]: https://api.jquery.com/jQuery.ajax/?utm_source=chatgpt.com "jQuery.ajax()" [6]: https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Schemes/javascript?utm_source=chatgpt.com "javascript: URLs - URIs - MDN Web Docs" [7]: https://blog.jquery.com/2026/01/17/jquery-4-0-0/ "jQuery 4.0.0 | Official jQuery Blog" [8]: https://jquery.com/download/ "Download jQuery | jQuery" [9]: https://cheatsheetseries.owasp.org/cheatsheets/Content_Security_Policy_Cheat_Sheet.html?utm_source=chatgpt.com "Content Security Policy - OWASP Cheat Sheet Series" [10]: https://www.w3.org/TR/trusted-types/?utm_source=chatgpt.com "Trusted Types" [11]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/require-trusted-types-for?utm_source=chatgpt.com "Content-Security-Policy: require-trusted-types-for directive" [12]: https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Headers_Cheat_Sheet.html?utm_source=chatgpt.com "HTTP Security Response Headers Cheat Sheet" [13]: https://nvd.nist.gov/vuln/detail/cve-2019-11358?utm_source=chatgpt.com "CVE-2019-11358 Detail - NVD" [14]: https://api.jquery.com/text/?utm_source=chatgpt.com ".text() | jQuery API Documentation" [15]: https://api.jquery.com/val/?utm_source=chatgpt.com ".val() | jQuery API Documentation" [16]: https://github.com/jquery/jquery/security/advisories/GHSA-gxr4-xjj5-5px2 "Potential XSS vulnerability in jQuery.htmlPrefilter and related methods · Advisory · jquery/jquery · GitHub" [17]: https://github.com/cure53/DOMPurify?utm_source=chatgpt.com "DOMPurify - a DOM-only, super-fast, uber-tolerant XSS ..." [18]: https://developer.mozilla.org/en-US/docs/Web/API/HTML_Sanitizer_API?utm_source=chatgpt.com "HTML Sanitizer API - MDN Web Docs" [19]: https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html?utm_source=chatgpt.com "Cross-Site Request Forgery Prevention Cheat Sheet" [20]: https://api.jquery.com/jQuery.escapeSelector/?utm_source=chatgpt.com "jQuery.escapeSelector()" [21]: https://api.jquery.com/html/?utm_source=chatgpt.com ".html() | jQuery API Documentation" [22]: https://api.jquery.com/append/?utm_source=chatgpt.com ".append() | jQuery API Documentation" [23]: https://nvd.nist.gov/vuln/detail/cve-2020-11023?utm_source=chatgpt.com "CVE-2020-11023 Detail - NVD" [24]: https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html?utm_source=chatgpt.com "Cross Site Scripting Prevention - OWASP Cheat Sheet Series" [25]: https://cheatsheetseries.owasp.org/cheatsheets/DOM_based_XSS_Prevention_Cheat_Sheet.html?utm_source=chatgpt.com "DOM based XSS Prevention Cheat Sheet" [26]: https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity?utm_source=chatgpt.com "Subresource Integrity - Security - MDN Web Docs" [27]: https://www.w3.org/TR/sri-2/?utm_source=chatgpt.com "Subresource Integrity" [28]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP?utm_source=chatgpt.com "Content Security Policy (CSP) - HTTP - MDN Web Docs" [29]: https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API?utm_source=chatgpt.com "Trusted Types API - MDN Web Docs"