Repository navigation
Closed
Copy link
Description
DRAFT 21 (SDK, 2026-10-27) — to be filed
Title: [Bug]: fulltext search terms/queries are never escaped — apostrophes break AGAINST, boolean operators in terms rewrite query semantics
Description
The fulltext builder chain never escapes user content at any of the three boundaries where it matters. All evidence from matrixone/sqlalchemy_ext/fulltext_search.py:
- Terms are embedded raw into the boolean query (
FulltextElement.build()→f"{operator}{content}", groups built with no content guard):boolean_match('body').must("O'Brien")→ generatedMATCH(body) AGAINST('+O'Brien' IN BOOLEAN MODE)at the finalcompile()— the apostrophe terminates the SQL string literal, producing broken SQL (+'O'remainder + dangling quotes), the same unescaped-string-literal family as today's other reports, but on the most common user-data character in English text (don't, O'Brien, it's).- Terms containing boolean-mode operators are silently repurposed:
must("c++")builds+c++(operator soup),must("stop-fire")builds+stop-fire— the-firehalf becomes an exclusion inside the must clause, so a search for the literal product name "stop-fire" == excludes 'fire' and requires 'stop'. Real-world impact on product/part-number searches is direct. phrase('a "quoted" thing')→"a "quoted" thing"— inner double quotes break phrase delimiting.
- The AGAINST string literal itself is unescaped in
FulltextFilter.compile():Even withoutboolean-operator issues, any single characterreturn f"MATCH({columns_str}) AGAINST('{query_string}' IN BOOLEAN MODE)"
'anywhere in any term breaks out of the literal — SQL syntax error or (in composed contexts) injection. - Column names in
MATCH({columns_str})are raw-joined (", ".join of caller strings) — no backtick quoting; a column namedkey/orderor one containing special chars fails.
Per MySQL boolean-mode documentation, double-quoted term wrappers are the standard escape for literal operator characters (+"c++" style), and apostrophes inside the AGAINST literal need '' doubling — none of that machinery exists here.
(Related-but-different: #31259 covered the group() OR semantics producing wrong-shaped queries; this report covers escaping/semantic-safety of user term content — the reproduction classes do not overlap.)
Reproduction
from matrixone.sqlalchemy_ext.fulltext_search import boolean_match
f = boolean_match('body').must("O'Brien")
f.compile()
# "MATCH(body) AGAINST('+O'Brien' IN BOOLEAN MODE)" ← literal broken
f2 = boolean_match('body').must("stop-fire").compile()
# "+stop-fire" — 'fire' becomes an exclusion; literal product search misfiresImpact
- Any application passing user input into these documented builders (the intended use) hits apostrophe-breakage or operator-hijack on ordinary English input; searchable-content domains (product names, titles, error strings) routinely contain
-,+, quotes, parentheses. - Errors from (1) arrive as server-side syntax errors that do not mention the term; semantic misfires from (2) return wrong rows with no error at all — the search quietly means something else.
- The three modes (NATURAL_LANGUAGE/BOOLEAN/QUERY_EXPANSION) share the same unescaped
AGAINST('{query}')frame, so all are affected.
Expected behavior
- Escape
'in the assembled query string before wrapping (''doubling) in all three compile paths. - Per-term escaping for boolean mode: wrap terms containing operator characters in double quotes (
"stop-fire","c++") or escape per MySQL rules; phrase() should guard embedded double quotes. - Quote column names in MATCH(...) with backticks (doubling any embedded backtick).
- Regression table: terms
O'Brien,stop-fire,c++,a "quoted" x, columnorder— assert the compiled SQL is a single well-formed statement and the boolean semantics match the caller's intent.
Activity
Ariznawlll commentedon Oct 27, 2026
Partial-verify against current main (2026-10-27): the apostrophe escaping shown in this report is now fixed —
boolean_match('body').must("O'Brien").compile()rendersAGAINST('+O''Brien' ...)on main. The remaining unverified halves of the report: (a) boolean-operator hijacking — a term likestop-firestill compiles to+stop-firewhich boolean mode reads as (require stop, exclude fire); (b) MATCH() column names are still unquoted raw joins. Recommend keeping this open only for those two residual pieces (or splitting them if triage prefers).MatrixAdventurer commentedon Oct 28, 2026
已在当前 main(
e9dc8c4)复核,结论和上面 @Ariznawlll 的部分复核一致:只修复了一部分,暂不关闭。已修复: AGAINST 字面量的单引号转义。#31262(
28e8760)在clients/python/matrixone/sqlalchemy_ext/fulltext_search.py的 L645、L657、L897 改用fulltext_term_token(...)。boolean_match('body').must("O'Brien")生成AGAINST('+O''Brien' IN BOOLEAN MODE)。仍未修复(在 main 上本地编译验证):
FulltextElement.build,L121-122)。must("stop-fire")生成'+stop-fire',must("c++")生成'+c++'。phrase('a "quoted" thing')生成'"a "quoted" thing"',短语边界被破坏。boolean_match('order', 'body')生成MATCH(order, body)。建议保留本 issue 跟踪这三项。
本操作由 LW 授权的 Grok Bot 智能体执行
fix(python): unify SDK query and analytics lifecycle contracts (#31774)
XuPeng-SH commentedon Oct 30, 2026
QA handoff for merged #31774 (main
bbfe55669a1440424914d45a283a1d0e36f722fa): please verify fulltext boolean term validation, embedded quotes and MATCH identifier quoting. This isolated QA run inspected the issue and merged source but did not run tests or a live MatrixOne service at this SHA because resource headroom under the existing guard was insufficient. Earlier QA counterexamples and PR author-reported validation remain scoped to their recorded versions and are not results of this QA run.Ariznawlll commentedon Oct 30, 2026
结论
测试不通过。全文检索 builder 的 MATCH 列名仍未正确引用,合法的保留字列名导致 SDK 生成的查询无法执行。
关键证据
main@d39d8a40343ccd40bf665036388df7a40ee867f8;相关修复 PR fix(python): unify SDK query and analytics lifecycle contracts #31774 的合并提交bbfe55669a1440424914d45a283a1d0e36f722fa在其祖先链。实际二进制与 SDK 同完整 SHA;本地隔离 1 CN / 1 TN / 1 LogService,Python 3.12。order的表和真实全文索引。手写MATCH(`order`) AGAINST('+alpha' IN BOOLEAN MODE)均返回 id 1;boolean_match('order').must('alpha').compile()实际生成MATCH(order) AGAINST('+alpha' IN BOOLEAN MODE),在真实服务均报 1064,3/3。SELECT 1正常,测试库清理。此项是原 issue 中已列出的列名引用边界,不另建重复 issue;本轮未据此判断布尔词项其他语义。待解决点
fix(python-sdk): unify SQL, transaction and driver boundaries (#31889)
XuPeng-SH commentedon Oct 30, 2026
新修复转 QA:#31889 已合入 main,合并提交
91dfab2132c4c4fcd3f9a115dbfa968b196b8b14。四个MATCH入口统一引用列名/SQLAlchemy列对象,保留qualified字符串与atomic列名;对应旧d39d8a4保留字order的真实失败路径。
已核对 issue 正文、完整评论及当前合并源码/测试内容。历史失败按其原 SHA 保留;新修复直接覆盖上述残留,未发现适用于新修复的已验证反例或尚未完成的开发 follow-up。本轮仅源码/测试内容静态核对,没有运行 MatrixOne 服务或 SDK 回归;作者在 PR 内的运行结果是作者证据,不是本轮独立测试。转 Ariznawlll 继续验证,不代表验收通过。
QA 待验范围:order/特殊标识符、列对象、单引号与布尔词项/phrase边界、真实全文索引语义和源行不变,保留dotted-name建索引原生限制。
Ariznawlll commentedon Oct 31, 2026
结论
测试不通过。SDK 已覆盖的保留字列和词项场景通过,但原 issue 要求的含反引号特殊列名无法完成端到端全文检索验证:原生全文索引创建先报语法错误。
关键证据
main@6e5f2ce0fa52b834e39fb4ada00984fa57c02c14,本地隔离双 CN / 单 TN / LogService,服务二进制和 SDK 源码对应该 SHA。order保留字列的真实索引上,三个 SDK 构造入口以及O'Brien、stop-fire、c++的词项结果与原生查询对照一致;嵌入引号的非法 phrase 按预期拒绝。两 CN 各 3 轮均通过,源表保持不变;可执行部分已补入 MOTR #298 的issue_31399_fulltext_terms,实际运行 3/3。`tickcol`` 列的表并执行 ``CREATE FULLTEXT INDEX ft_tick ON special_docs (tickcol`),原生服务在索引创建阶段 3/3 报语法错误,内部 SQL 的报错位置指向列名中反引号后的col;因此没有全文索引可供 SDK 执行该特殊列名查询。这是服务端前置步骤的实测失败,不证明 SDK 的列名转义本身仍有错。待解决点
fix(python): restore SDK SQL and execution contracts (#31953)
XuPeng-SH commentedon Oct 31, 2026
新修复转 QA:#31953 已合入 main,merge SHA
569d521cfae73ba80c42f58366c172ce4ef84ed7。本次原生 fulltext population、post-DML 和 CDC SQL 统一原子标识符引用,并携带 tokenizer 配置,覆盖旧 main 含反引号列名建索引前置失败。请复验原生创建、SDK MATCH、保留字/反引号、O'Brien/stop-fire/c++、phrase 拒绝、增删改及异步索引追平。4.2.5 的已知原生限制不是 main 修复已通过,也不自动要求 backport。
验证证据:作者记录离线多 SQLAlchemy 矩阵、187 个 native 合同、19 个全文 SQL 检查;当前 head 独立 reviewer 记录 315 个 focused Python tests、11 个 SDK online cases 及三个 Go owner package 通过。上述均为 PR 作者/评审者报告,不是本轮独立本地实测。本轮读取 issue 完整评论、修复范围及远端合并状态,未运行服务或测试;未发现适用于新合并版本的已验证反例或未完成的开发 follow-up。转 @Ariznawlll 继续验证,不代表验收通过。完整 BVT、多 CN、长稳和生产环境验证不在本轮证据范围内。
Ariznawlll commentedon Nov 2, 2026
结论
测试通过。全文搜索构造器能正确引用保留字和含反引号的列,特殊词项与原生查询一致;此前阻塞验收的反引号列建索引场景现已通过。
关键证据
main@35202093259793e48dcd7abc8ff418f07190f746,修复 fix(python): restore SDK SQL and execution contracts #31953 的 merge569d521cfae73ba80c42f58366c172ce4ef84ed7为祖先;本地隔离单 CN / TN / LogService,服务 SQL 版本及二进制构建 SHA 一致,vcs.modified=false。Python 3.12,SQLAlchemy 1.4.54 与 2.1.6。order和含反引号列tick\col建立全文索引;保留字列的三个 SDK 构造入口查询alpha均返回 id 1、2。特殊词项O'Brien、stop-fire、c++` 的 SDK 结果逐项与原生 MATCH 对照。反引号列 SDK MATCH 与原生 MATCH 均返回 id 1、2;更新 id 3、插入 id 4、删除 id 4 后等待索引追平,各阶段均对照完整结果。两种 SQLAlchemy 版本经 MOTR runner 各 3/3。qa_terms_前缀测试库计数为 0。test_fulltext_embedded_backtick_column还分别通过同步和异步客户端执行反引号列的建索引及插入、更新、删除后查询;SQLAlchemy 1.4.54 和 2.1.6 各 3 轮通过。待解决点