jQuery's 120-second hang now takes 4 ms in 4.1.0
The same malicious selector took more than 120 seconds in jQuery 4.0.0 and 4 milliseconds in 4.1.0. I ran both builds against the library's own regression test: the old one never finished, the new one threw a clean syntax error in 4 ms.
jQuery 4.1.0 shipped today, 17 November 2026, ten months after 4.0.0 — alongside 3.8.0, which the team calls a send-off, not a comeback: the last planned feature release on the 3.x branch. The headline fix is a ReDoS in selector parsing, and it's the rare security fix you can watch fail in real time, because the old build doesn't error. It just thinks.
The repro
The test comes from the fix itself, commit d41cf7dd ("Selector: Fix ReDoS in identifier matching", closes gh-5807, reported by John Herren). The input is an attribute selector containing 30 hex escapes followed by an invalid character:
// jQuery's own regression test, test/unit/selector.js var selector = "[" + Array( 31 ).join( "\\a" ) + "!]"; // = "[\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a\a!]" jQuery( selector ); // must complete in < 1000ms I ran that exact input against the shipped builds in jsdom (Node 24, same harness both times, jQuery(selector) with a try/catch):
build input length result jQuery 4.0.0 63 chars killed at 120,000 ms, still running jQuery 4.1.0 63 chars 4 ms, throws "Syntax error, unrecognized expression" The old build didn't finish in 120 seconds — I killed it with timeout. The test comment says the naive version hangs "for over a minute"; on this machine it's at least 30,000x slower than the fix (120,000 ms and counting, versus 4 ms). The new build's behavior is also the correct one: the selector is invalid syntax, so it should throw immediately, not go into a trance first.
Why one character class fixed it
The bug is in the identifier regex, the production that matches CSS identifiers inside selectors. The old definition:
// 4.0.0 — src/selector/var/identifier.js identifier = "(?:\\\\[\\da-fA-F]{1,6}" + whitespace + "?|\\\\[^\\r\\n\\f]|[\\w-]|[^\\0-\\x7f])+"; The first alternative matches a hex escape like \a (\ + 1–6 hex digits). The second alternative matches a backslash followed by any non-newline character — which also matches \a, because a is a non-newline character. So every \a in the input has two ways to match, and the regex engine tries them in combination. Thirty escapes means up to 2^30 paths, and the trailing ! guarantees every path fails, so the engine explores all of them. That's catastrophic backtracking in its textbook form: not a slow regex, an exponential one.
The fix excludes hex digits from the second alternative, so each escape has exactly one parse:
// 4.1.0 — the `escape` production is now extracted and shared escape = "\\\\[\\da-fA-F]{1,6}" + whitespace + "?|" + "\\\\[^\\da-fA-F\\r\\n\\f]"; identifier = "(?:" + escape + "|[\\w-]|[^\\0-\\x7f])+"; The diff is [^\\r\\n\\f] → [^\\da-fA-F\\r\\n\\f]: six characters added to a character class, plus the refactor that pulls the escape production out so the two places that need it can't drift apart again. It also brings the production closer to the CSS Syntax spec's ident-token diagram, which is the stated motivation in the commit. A selector an attacker can smuggle into any page that calls $(userInput) — and plenty of pages do — hanging the tab for two minutes is a real denial of service, not a theoretical one. This is the kind of bug where the fix looks trivially small and the blast radius was the whole web page.
The rest of 4.1.0, measured
The release is 67 commits past 4.0.0 (17 January → 17 November 2026), touching 83 files (+6,908/−4,916 lines). I pulled the shipped files from the jQuery CDN and measured the sizes myself:
file 4.0.0 4.1.0 change jquery.min.js 78,748 B 78,965 B +217 B jquery.min.js (gzip) 27,449 B 27,541 B +92 B jquery.js 255,967 B 259,071 B +3,104 B jquery.slim.min.js 56,032 B 56,030 B -2 B jquery.slim.min.js (gzip) 19,414 B 19,430 B +16 B The release adds code overall — responseURL on jqXHR, form-associated custom elements in .serialize(), XML-document CSS support — so the full build grows 217 bytes minified. The slim build, which drops ajax and effects, actually shrinks 2 bytes raw, which is the "shave off some bytes" the changelog mentions for the data module, surviving into exactly one artifact.
Two other claims from the release post, checked against the shipped code:
"jQuery no longer uses getElementsByTagName or getElementsByClassName internally." Mostly true, with one footnote. Occurrences in the built file fall from 11 in 4.0.0 to 3 in 4.1.0 — and of those 3, two are in comments and the last is a live call guarded by if ( isIE && rdoubleDash.test( className ) ), an Internet Explorer fallback for identifiers starting with a double dash. In any modern browser the methods are gone; the one survivor only fires on IE. The switch also fixes real bugs the post lists, like MathML elements missed by lowercase tag names on cloned nodes in IE 11.
"uniqueSort goes from O(N²) to O(N)." I benchmarked it: arrays of N elements with every other element duplicated (1.5N inputs), median of 5 runs, same jsdom harness:
input size 4.0.0 4.1.0 speedup 2,000 3.16 ms 2.05 ms 1.5x 8,000 14.45 ms 11.30 ms 1.3x 32,000 86.92 ms 33.81 ms 2.6x The telling column is the scaling: 16x more input makes 4.0.0 27.5x slower (3.16 → 86.92 ms, superlinear — the old repeated-splice compaction) and 4.1.0 16.5x slower (2.05 → 33.81 ms, near-linear — the new single-pass two-pointer compaction). The sort step is shared between the two, so this is total uniqueSort time, not dedup alone; the gap widens exactly where the quadratic term should bite.
Also in the release: a Safari 27 regex-interpreter workaround in the selector engine, stricter quick-selection paths with fallback when querySelectorAll throws, and invalid escape code points decoded to U+FFFD per the CSS spec.
3.8.0 is the torch passing
The 3.8.0 half of the release is 166 commits past 3.7.1, but most of it is backports of fixes that already shipped in 4.0.0. The new-to-3.x pieces are small: hidden="until-found" support, and formal deprecations of the push/sort/splice Array methods on the jQuery prototype and of jQuery.expr[":"] / jQuery.expr.filters, so the Migrate plugin can warn before an upgrade. The post is explicit: from here, 3.x gets critical security and bug fixes only. jQuery 4.x is where active development happens, and 4.1.0 — a minor release with a ReDoS fix, a faster sort, and a smaller slim build — is the evidence that the 4.x line is being maintained as a living project, not a museum piece.
The jQuery-is-dead jokes are twenty years old and the library is still patching regexes that could hang your tab. The honest version of the story is less dramatic: a widely deployed library found a quadratic hole in its selector engine, fixed it with six characters, and shipped the fix alongside a faster dedup and a smaller build. That's maintenance, and maintenance is the whole job.
Sources: jQuery Blog, "jQuery 4.1.0 and 3.8.0 Released: Passing the Torch" (17 Nov 2026); Release 4.1.0 changelog; commit d41cf7dd (gh-5807). ReDoS timings, bundle sizes, and uniqueSort numbers are my own measurements on this machine (Node 24, jsdom; 4.0.0 ReDoS run killed at 120 s without completing).