All articles · Web Security

Old jQuery in Production: Finding and Upgrading Vulnerable Libraries

Cover with the article title next to a puzzle piece with a warning sign, in amber on a dark background

Front-end libraries age quietly. A theme bundles jQuery, a plugin brings its own copy of Bootstrap, someone pastes a CDN tag for a date picker, and none of it shows up in the package manager your team actually audits. Years later the site still loads a version with published security advisories, and nobody remembers why it’s there.

This article covers how to find the libraries your pages really load, how to read the advisories against them without panicking, and how to upgrade the most common one, jQuery, without breaking the site.

How old libraries get in

Vulnerable front-end code rarely arrives through your main build. The usual routes are:

  • Themes and templates that ship a fixed copy of jQuery, Bootstrap or a slider library in an assets/ folder.
  • CMS plugins that bundle their own dependencies instead of using the ones the CMS provides, sometimes several copies of the same library at different versions.
  • CDN tags pasted into a layout or a tag manager with a pinned version number.
  • Vendored files copied into the repository once and never updated, often renamed to something like vendor.min.js.
  • Old builds still deployed on a forgotten subdirectory or microsite.

npm audit and similar tools only see what’s in your lockfile. They won’t see any of the above.

Finding what your pages actually load

Start from the browser, because that’s what attackers see too.

  1. Network tab. Load your main templates (home, article, product, checkout, login) and filter by JS. Note every library file and where it comes from.
  2. Version numbers. Many libraries expose their version at runtime: jQuery.fn.jquery in the console returns jQuery’s version, and most minified files start with a license comment that names the version.
  3. Retire.js data. The Retire.js project maintains a public database of JavaScript libraries with known vulnerabilities, matched by file name, URL patterns and file content. Its browser extension and command-line tool check what a page loads against that list.
  4. Source scan. Search your repository and theme folders for jquery, bootstrap, lodash, moment, angular and other common names, including in minified bundles.

A passive scanner that only looks at script URLs, like the check PerfoMetrix runs against the Retire.js data, catches libraries whose version is in the file name or CDN path. It can’t see a library hidden inside your own bundle, so treat a clean URL check as a good start, not proof. Our vulnerable JavaScript libraries guide explains what that check can and can’t detect.

Reading the advisories

A library flagged as vulnerable doesn’t automatically mean your site is exploitable. Most front-end advisories describe a specific function that becomes dangerous when it receives untrusted input. The question to ask for each one is: does my code, or a plugin, pass user-controlled data to that function?

The jQuery advisories that show up most often:

Advisory Affects Fixed in What it’s about
CVE-2015-9251 before 3.0.0 3.0.0 Cross-domain Ajax responses could be executed as script
CVE-2019-11358 before 3.4.0 3.4.0 Prototype pollution through jQuery.extend(true, …)
CVE-2020-11022, CVE-2020-11023 before 3.5.0 3.5.0 Sanitized HTML passed to DOM methods could still run script

The 2020 pair is the one to take most seriously. Code that sanitizes HTML and then passes it to .html(), .append() or similar methods could still end up running injected script on older versions. Plenty of plugins do exactly that with content from URLs, comments or form fields.

Other libraries that commonly turn up on older sites:

  • Bootstrap before 3.4.1 and 4.3.1 had XSS issues in tooltip and popover data- attributes.
  • Lodash before 4.17.12 had prototype pollution in defaultsDeep, with further fixes in later 4.17.x releases.
  • Moment.js before 2.29.4 had a regular-expression denial-of-service issue in date parsing, and the project is in maintenance mode, so new code should use another date library.
  • AngularJS (the 1.x line) reached end of life at the end of 2021. It gets no security fixes at all, so every new issue stays open.

Even when you conclude that a particular advisory can’t be reached in your code, upgrade anyway. Your conclusion holds only until someone adds a plugin or a new feature that passes untrusted data to the vulnerable function.

Upgrading jQuery safely

Jumping from jQuery 1.x to 3.x in one step breaks things, because several APIs were removed or changed along the way. The jQuery team publishes the jQuery Migrate plugin for exactly this transition:

  1. Load the latest 3.x release together with jQuery Migrate 3.x on a staging copy of the site. Use the development (non-minified) build of Migrate.
  2. Open the console and use the site. Migrate restores removed APIs and logs a warning for each deprecated call, with a short code you can look up in its documentation.
  3. Fix the warnings in your own code. Common ones are .size() (use .length), .bind() and .delegate() (use .on()), $.parseJSON (use JSON.parse) and the old .load() event shorthand.
  4. For third-party plugins, upgrade the plugin rather than patching it. If a plugin is abandoned and depends on removed APIs, that’s a signal to replace it.
  5. Remove Migrate once the console stays quiet across all your templates and key flows. It’s a transition aid, not a permanent dependency.

On WordPress, core has shipped jQuery 3.x since 2020. If your pages still load jQuery 1.x, a theme or plugin is loading its own copy or replacing the core one. Find which one, and update or replace it rather than deregistering the newer core version.

Reducing the surface for next time

Upgrading once doesn’t help much if the same pattern repeats. A few habits keep this from coming back:

  • One copy per library. Load each library once, from one place, at one version. Two jQuery copies on one page are a common source of both bugs and old versions.
  • Put front-end dependencies in the package manager instead of in vendored files, so your regular audits see them.
  • Pin CDN versions deliberately and add Subresource Integrity hashes, so a compromised CDN file doesn’t run on your page. When you upgrade, update the hash.
  • Question whether you still need the library. Much of what sites used jQuery for, such as selectors, class toggling, Ajax and simple animation, is now built into browsers. Removing a dependency is the most permanent fix and also reduces the JavaScript cost of every page.
  • Review plugins before installing them. Check when they were last updated and whether they bundle their own libraries.

OWASP lists vulnerable and outdated components among the most common web application risks; its Top 10 project page explains the category and how it fits alongside the others.

A short action list

  • List every library your main templates load, with version and source.
  • Check them against the Retire.js data, and look up each advisory’s affected function.
  • Upgrade jQuery to the current 3.x line with jQuery Migrate on staging first.
  • Replace end-of-life libraries rather than waiting for a fix that won’t come.
  • Move what’s left into your package manager and audit it with the rest of your dependencies.

Old libraries are one of the few security problems you can find from the outside in an afternoon, and the fix is usually an upgrade you’d want for other reasons anyway.

Tags:JavaScriptjQuerydependenciesRetire.jsXSS