TanStack DB, the reactive client-side store published as @tanstack/db, implemented its like() and ilike() query operators by translating a SQL LIKE pattern into a JavaScript RegExp and calling .test() on it. Each % became an unbounded .*, and nothing limited how many wildcards a pattern could carry. Buggs777 filed TanStack/db#1690 on 2026-07-24 with a pattern of twenty a% groups and a 51-character value, and a single refetch() occupied the thread for seconds to minutes. PR #1745 replaced the regex with an iterative matcher and merged on 2026-09-23. No CVE or GHSA identifier exists, because the maintainers handled the report as a performance bug.
01Background: a query compiler that runs on the caller's thread
TanStack DB is a TypeScript data store built around collections and live queries. An application declares a collection, filters it with q.where(({ item }) => like(item.name, "prefix%")), and the library evaluates that predicate in the browser or in Node instead of sending it to a database engine that would compile the pattern itself.
The compiler therefore shares a process and a thread with the UI. There is no statement timeout, no server-side query governor, and no way to cancel a running RegExp.test(). Whatever cost the compiler assigns to a pattern gets paid in full. The second argument is typed StringLike, effectively a bare string, and evaluateLike() never inspects its length or its wildcard count.
02Root cause: `%` becomes `.*` with no bound and no wildcard limit
The implementation sits in evaluateLike() at packages/db/src/query/compiler/evaluators.ts, lines 632 to 655 in the reported revision. It lowercases both operands for the case-insensitive path, escapes regex metacharacters, substitutes the two SQL wildcards, and anchors the result:
// Convert SQL LIKE pattern to regex
// First escape all regex special chars except % and _
let regexPattern = searchPattern.replace(/[.*+?^${}()|[\]\\]/g, `\\$&`)
// Then convert SQL wildcards to regex
regexPattern = regexPattern.replace(/%/g, `.*`) // % matches any sequence
regexPattern = regexPattern.replace(/_/g, `.`) // _ matches any single char
// 's' (dotAll flag) makes '.' match all characters including line terminations
const regex = new RegExp(`^${regexPattern}$`, 's')
return regex.test(searchValue)
Order matters here. The escaping pass runs before the substitution, and % and _ are not regex metacharacters, so both survive the escape and are then rewritten into quantifiers. Nothing counts them afterwards. A caller can pass one % or fifty, and every one adds another .* to the expression.
The ^ and $ anchors finish the job. A value that almost matches forces the engine to try every possible split of the input between adjacent .* segments before it can decide that the trailing literal does not line up. With k wildcards over a value of n characters, the number of candidate distributions grows combinatorially with k. The s flag makes the search space slightly larger, since . also crosses the line terminators that would otherwise stop a match early.
One more multiplier: evaluateLike() builds a fresh RegExp on each call, so the pattern is recompiled for every row the predicate visits.
03Proof of concept: twenty wildcards and one trailing `b`
The report's reproduction uses the public API only, with no patched build and no internal imports:
import { createCollection, createLiveQueryCollection, like } from '@tanstack/db'
const collection = createCollection({
name: 'items',
schema: { name: 'string' },
sync: { type: 'none' },
})
const liveQuery = createLiveQueryCollection({
source: collection,
query: (q) => q.where(({ item }) => like(item.name, 'a%a%a%a%a%a%a%a%a%a%a%a%a%a%a%a%a%a%a%a')),
})
// Near-miss: long string that matches most of the pattern but fails at the end
// The 'b' at the end forces the engine into exponential backtracking
const nearMiss = 'a' + 'a'.repeat(50) + 'b'
const start = Date.now()
await liveQuery.refetch()
console.log(`Took ${Date.now() - start}ms`) // seconds to minutes
The pattern holds twenty copies of a%, which is twenty .* segments separated by single-character literals. The input is 51 a characters followed by a b. Any segment can absorb any prefix of the a run, so the engine explores a large space of partitions and rejects each one on the final b. Buggs777 reported a single refetch() taking seconds to minutes, depending on the machine and the number of wildcards.
The near-miss matters. A value that fails on its first character is rejected in linear time. The blow-up needs a long prefix that keeps matching, which is the shape of real data such as slugs, email local parts or free-text search terms.
04Impact: thread starvation in browsers and in SSR workers
In a browser the regex runs on the main thread. The tab freezes, keystrokes queue up, and timers and animations stall until the match finishes. The process survives, so the effect is a hang rather than a crash.
Server-side rendering and Node services carry the worse case. There the same call blocks the event loop for the duration of the backtracking, and every other request handled by that worker waits behind it. One crafted search string then degrades the whole process.
Reachability depends on which argument the application controls. Search boxes and filters often build the pattern from user text ("starts with what was typed") and treat the value as data, which is exactly what like() permits. Where the pattern is a fixed literal and only values vary, the cost stays bounded and an attacker has nothing to steer.
This page rates the issue High: the trigger is remote, it needs no authentication when a search field is exposed, and a repetitive string is enough. There is no memory corruption and no code execution. No CVE was assigned and no CVSS vector exists, so both score fields are left empty instead of estimated.
05Affected versions
| Package | Affected | Fixed in |
|---|---|---|
@tanstack/db (npm) | all versions before the fix merged on 2026-09-23 | PR #1745, merged 2026-09-23 |
like() and ilike() share the path through evaluateLike(); ilike() only lowercases the operands first. The source material records no patched release number, only the merge of PR #1745, so consumers should pin to a build of @tanstack/db that contains it.
Disclosure timeline
- 2026-07-24Buggs777 opens issue #1690 with the
evaluateLike()excerpt, a runnable PoC and a suggested wildcard cap. - 2026-08-18Maintainer ifeelBALANCED claims the issue and starts on the long-term remediation: a linear character-by-character matcher plus regression tests for the pathological patterns.
- 2026-09-23PR #1745, "fix: prevent ReDoS in like()/ilike() pattern matching", merges with +373/-21 across 6 files. The issue closes.
06Remediation: an iterative matcher, not a wildcard cap
PR #1745 deletes the regular expression and matches the pattern with two pointers, walking the value and the pattern once while remembering the position of the most recent %. That is the O(n·m) worst case the report listed as the long-term option, and it removes the backtracking entirely instead of shrinking its exponent.
The report's own interim suggestion was a cap of 20 wildcards, throwing when a pattern exceeds it. A cap helps, but it leaves the cost of nineteen wildcards in place and converts a slow query into an exception the caller now has to catch.
- Upgrade to a
@tanstack/dbbuild containing PR #1745, or pin to the merge commit. - Keep user input out of the pattern. Escape
%and_in user text and append the wildcards yourself, so the attacker never chooses the wildcard count. - Bound the value length before the predicate sees it, and keep expensive filters off the SSR event loop.