Repository navigation
Description
Problem Statement
QueryService builds its WHERE clause by formatting values directly into the SQL string rather than binding them as parameters:
// packages/core/src/services/query_service/mod.rs
fn format_value(&self, value: Option<&serde_json::Value>) -> Result<String> {
match value {
Some(serde_json::Value::String(s)) => Ok(format!("'{}'", self.escape_string(s))),
...Safety currently rests on three things holding simultaneously: escape_string doubling single quotes, format_value accepting only String/Number/Bool/Null, and validate_identifier allowlisting [A-Za-z0-9_:-] for identifiers upstream in query_ops.
This is correct today. A review of #2742 specifically audited it and found no constructible injection: SQLite has no backslash escape in string literals, so quote-doubling is complete for a single-quoted literal, and escape_string_for_like orders its replacements correctly.
The concern is structural rather than an open vulnerability. The construction is correct-by-audit, not correct-by-construction: every future operator or filter type added to QueryService is a fresh opportunity to interpolate a value without routing it through escape_string, and nothing in the type system or a test will catch it. The guarantee lives in the discipline of whoever edits the file next.
Why now
The threat model changed in #2742. Previously this path was reachable only from agent and CLI callers; that PR routes the desktop app's saved queries through it, so user-authored filter values now reach the same string formatting. The filter editor emits only property filters over schema-known fields, so practical exposure is narrow — but "narrow" is a property of the current UI, not of the query engine.
Proposed Solution
Bind values as parameters. libsql supports bound parameters, so the WHERE-clause builders would emit placeholders and collect values into a parameter vector passed alongside the SQL.
Worth confirming during implementation:
execute_query_for_idscurrently takes a finished SQL string (store.query_node_ids_raw); binding needs a path that carries parameters too.- The
INoperator generates a variable-length list, so its placeholder count is dynamic. escape_string_for_likestill has a job after this — LIKE wildcard escaping is separate from parameter binding.- Identifier positions (table/column/JSON paths) cannot be bound and must keep using
validate_identifier.
Acceptance Criteria
- Filter values are bound as parameters rather than formatted into the SQL string
- Identifier positions still go through
validate_identifier(binding does not apply to them) - LIKE wildcard escaping is preserved for
contains - Existing
query_service_test.rscoverage passes unchanged — this is a refactor, not a behavior change - A test covers a value containing a quote to pin the behavior at the boundary
Context
Surfaced in review of #2742. Deferred there as a refactor of a file that PR does not modify.
Activity
malibio commentedon Sep 17, 2026
Frontend: 256 test files passed (5214 tests)
malibio commentedon Sep 17, 2026
Implementation complete; pre-push gate running.
Filter values now bind as parameters.
BoundSqlowns the SQL and its parameter vector, and itsbindis the only way to place a value — it pushes the value and returns the matching?Nin one step, so a placeholder cannot exist without its value and the numbering cannot drift.format_valueandescape_stringare deleted.On the four points the issue flagged for confirmation:
execute_query_for_ids/query_node_ids_rawnow carry a parameter vector alongside the SQL.INgenerates one placeholder per member, numbered consecutively.escape_string_for_likekeeps its job but loses its quote-doubling. Wildcard escaping is pattern semantics, not SQL syntax; quote-doubling was syntax, which binding subsumes. Leaving it in would have matched a literal doubled quote — this is a real behavior fix, pinned by a test that fails against the old code.validate_identifier.Five new tests, each verified to fail against the previous implementation by reverting the fix and re-running. All 1573 Rust lib tests pass;
quality:fixclean.Bind QueryService filter values as parameters instead of interpolatin…
Bind QueryService filter values as parameters instead of interpolatin…