fix: prevent ReDoS in like()/ilike() pattern matching - #1745
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthrough
ChangesLIKE matcher fix
Priority: ⚪ Not assessed Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Suggested reviewers: Merge Risk: ⚪ Minimal · up to The LIKE and ILIKE implementation retains the established matching behavior while removing regex backtracking. No actionable merge-blocking issue remains. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. (3 skipped: 3 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/react-router-with-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
Fixes #1690.
The problem
evaluateLike()compiled SQL LIKE patterns to aRegExpby rewriting%to.*and_to.. A pattern with many%wildcards produces overlapping unbounded.*segments, and a near-miss value can trigger catastrophic backtracking through the public query-builder API (CWE-1333).The fix
This removes the regex and matches with an iterative two-pointer walk.
%uses bounded single-position retry, so hostile wildcard patterns no longer create exponential regex work.The matcher preserves the existing public semantics:
%matches any sequence, including empty strings and line breaks_matches exactly one characterilikeretains the existingtoLowerCase()case foldfalseCurrent
mainis merged into the branch. During the forward-port review, a wildcard-precedence regression was found: a%in the pattern could be treated as a literal when the input contained%at the same position. The matcher now recognizes the wildcard first, and focused witnesses cover inputs such aslike('100% done', '100%done').Oracle structure
The LIKE oracle now keeps its contract, independent dynamic-programming model, bounded string grammar, real compiled-expression driver, observations, replay interface, and declared limits together. It runs a stable 10,000-case campaign and a fresh 10,000-case campaign;
TANSTACK_DB_LIKE_ORACLE_SEEDreplays a recorded seed andTANSTACK_DB_LIKE_ORACLE_RUNScontrols the budget.The repository guide and agent rules now say explicitly that literate structure is mandatory for every oracle and generated-history test. A focused non-oracle regression may remain short, but it cannot waive that structure or replace applicable oracle coverage.
Verification
likeandilike.@tanstack/dbsuite: 212 files and 6,306 tests passed with no type errors.Note
AI assisted: implemented with the help of AI assistants; the behavior was independently reproduced and verified against current
main.Summary by CodeRabbit
Bug Fixes
LIKEandILIKEmatching for%and_wildcards, including when input values contain those characters.Tests