javascript-jquery-web-frontend-security

This document is designed as a security spec that supports:

jQuery Frontend Security Spec (jQuery 4.0.x, modern browsers)

This document is designed as a security spec that supports:

  1. Secure-by-default code generation for new jQuery-based frontend code.
  2. Security review / vulnerability hunting in existing jQuery-based code (passive “notice issues while working” and active “scan the repo and report findings”).

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).


0) Safety, boundaries, and anti-abuse constraints (MUST FOLLOW)


1) Operating modes

1.1 Generation mode (default)

When asked to write new jQuery code or modify existing jQuery code:

1.2 Passive review mode (always on while editing)

While working anywhere in a repo that uses jQuery (even if the user did not ask for a security scan):

1.3 Active audit mode (explicit scan request)

When the user asks to “scan”, “audit”, or “hunt for vulns”:

Recommended audit order:

  1. jQuery sourcing, versions, and dependency hygiene (script tags, lockfiles, CDN usage, SRI).
  2. CSP / Trusted Types / security headers posture (in repo and at runtime if observable).
  3. DOM XSS: untrusted sources → jQuery sinks (.html, .append, $("<…>"), .load, etc.).
  4. Script execution sinks: JSONP, dataType:"script", $.getScript, dynamic <script> insertion.
  5. URL/attribute assignment (href, src, style, on* attributes).
  6. Prototype pollution / unsafe object merging ($.extend patterns).
  7. AJAX auth patterns + CSRF for cookie-based sessions.
  8. Third-party plugins and untrusted content rendering paths (comments, WYSIWYG, markdown-to-HTML).

2) Definitions and review guidance

2.1 Untrusted input (treat as attacker-controlled unless proven otherwise)

Examples include:

2.2 High-risk “sinks” in jQuery contexts

A sink is a code path where untrusted input can become interpreted as executable code or HTML.

Key jQuery sink categories:

2.3 Required audit finding format

For each issue found, output:


3) Secure baseline: minimum production configuration (MUST in production)

This is the smallest “production baseline” that prevents common jQuery-related security failures.

3.1 Use a supported, patched jQuery version (MUST)

3.2 Load jQuery safely (MUST)

3.3 CSP + Trusted Types (SHOULD, and MUST where available/required by policy)

3.4 Security headers and cookie posture (defense in depth; SHOULD)

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.


4) Rules (generation + audit)

Each rule contains: required practice, insecure patterns, detection hints, and remediation.

JQ-SUPPLY-001: jQuery MUST be patched; do not run known vulnerable versions

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:

Detection hints:

Fix:

Notes:


JQ-SUPPLY-002: Third-party script loading SHOULD use integrity and trusted origins

Severity: High

Required:

Insecure patterns:

Detection hints:

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.


JQ-XSS-001: Untrusted data MUST NOT be inserted as HTML via jQuery DOM-manipulation methods

Severity: High (if attacker-controlled content reaches these sinks)

Required:

Insecure patterns (examples):

Detection hints:

Fix:

Notes:


JQ-XSS-002: If rendering user-controlled HTML is required, it MUST be sanitized with a proven HTML sanitizer

Severity: Medium (High if rich HTML is attacker-controlled and sanitizer is weak/misconfigured)

Required:

Insecure patterns:

Detection hints:

Fix:

False positive notes:


JQ-XSS-003: $(untrustedString) and jQuery.parseHTML MUST NOT process attacker-controlled markup

Severity: High (if attacker-controlled)

Required:

Insecure patterns:

Detection hints:

Fix:


JQ-XSS-004: .load() MUST be treated as an HTML+script injection surface

Severity: Medium (High if URL/content is attacker-controlled)

Required:

Insecure patterns:

Detection hints:

Fix:


JQ-EXEC-001: Dynamic script execution and script fetching MUST NOT be reachable from untrusted input

Severity: High

Required:

Insecure patterns:

Detection hints:

Fix:


JQ-AJAX-001: JSONP MUST be disabled unless the endpoint is fully trusted (and even then, avoid)

Severity: Medium (High if attacker can influence URL/endpoint)

Required:

Insecure patterns:

Detection hints:

Fix:


JQ-AJAX-002: State-changing AJAX requests using cookie auth MUST be CSRF-protected

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:

Detection hints:

Fix:

False positive notes:


JQ-ATTR-001: Untrusted values MUST NOT be written into dangerous attributes without validation/allowlisting

Severity: Low (High for events like onclick)

Required:

Insecure patterns:

Detection hints:

Fix:


JQ-SELECTOR-001: User-controlled selector fragments MUST be escaped with jQuery.escapeSelector

Severity: Medium (can become High if it enables wrong-element selection in security-relevant UI)

Required:

Insecure patterns:

Detection hints:

Fix:

Notes:


JQ-PROTOTYPE-001: Do not deep-merge untrusted objects; prevent prototype pollution

Severity: Medium

Required:

Insecure patterns:

Detection hints:

Fix:


JQ-CSP-001: CSP and Trusted Types SHOULD be used to make DOM XSS harder to introduce and exploit

Severity: Medium

Required:

Insecure patterns:

Detection hints:

Fix:


5) Practical scanning heuristics (how to “hunt”)

When actively scanning, use these high-signal patterns:

Always try to confirm:


6) Sources (accessed 2026-01-27)

Primary jQuery project documentation and release notes:

jQuery vulnerabilities / advisories:

OWASP Cheat Sheet Series (web app security foundations relevant to jQuery usage):

Browser/platform references (SRI, CSP, Trusted Types, and dangerous URL schemes):

[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"