fix(store): sanitize FTS5 operators in buildFtsQuery (fixes #160)#380
Open
MLYoshi wants to merge 1 commit into
Open
fix(store): sanitize FTS5 operators in buildFtsQuery (fixes #160)#380MLYoshi wants to merge 1 commit into
MLYoshi wants to merge 1 commit into
Conversation
…oud#160) Add sanitizeFtsRaw() to strip FTS5 special operators and characters from raw search input before tokenization. Defense-in-depth approach: - Input-level: strip FTS5 syntax chars and boolean operators (AND/OR/NOT/NEAR) with \b word-boundary protection - Token-level: FTS5_OPERATORS Set as secondary filter for tokens that may leak through jieba tokenizer - Quoting: filter empty tokens after quote-stripping to avoid bare "" Add 11 security test cases covering operator injection, special chars, column filter syntax, word-boundary protection, jieba/fallback paths, pure-operator input, empty tokens, and normal recall preservation.
Collaborator
|
Thank you for submitting this PR and participating in Tencent Rhino-bird Open-source Training Program! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #160
Adds FTS5 operator injection protection to
buildFtsQuery()insrc/core/store/sqlite.tsusing a defense-in-depth approach:Changes
src/core/store/sqlite.ts— NewsanitizeFtsRaw()+ token-level filter:sanitizeFtsRaw)"'()*:\^-) and boolean operators (AND/OR/NOT/NEAR) before tokenization. Uses\bword-boundary to protect words likeANDROID.FTS5_OPERATORSSet)replaceAll('"', "")to avoid bare""in output.All 4 existing call sites (
auto-recall,l1-dedup,conversation-search,memory-search) benefit automatically with no changes needed.src/core/store/sqlite.test.ts— 11 new security test cases covering:"'()*:\^-)-) strippedcontent:foo) blockedANDROIDpreserved)nullTesting