Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

fix(security): suppress Bearer SQL-injection false positive in migration 0018 (alert #7993) (#4788)

LearningCircuita7214633df0f
diff --git a/src/local_deep_research/database/migrations/versions/0018_remove_mcp_strategy.py b/src/local_deep_research/database/migrations/versions/0018_remove_mcp_strategy.py
index 35c1e536d1..f1c4dc78db 100644
--- a/src/local_deep_research/database/migrations/versions/0018_remove_mcp_strategy.py
+++ b/src/local_deep_research/database/migrations/versions/0018_remove_mcp_strategy.py
@@ -72,7 +72,11 @@ _queued = sa.table(
# The two benchmark tables share the same shape. They are declared here with
# literal names (rather than building ``sa.table(table_name, ...)`` from a
# passed-in string) so the migration never constructs a SQL identifier from a
-# variable — there is no dynamic-table-name flow for a static analyzer to flag.
+# variable. The shared helper below still receives the table object as a
+# parameter, which Bearer's taint analysis reports as a SQL-injection false
+# positive on its ``conn.execute`` call — suppressed with a
+# ``# bearer:disable python_lang_sql_injection`` directive placed on the line
+# directly above the statement (the only placement Bearer honors).
_benchmark_runs = sa.table(
"benchmark_runs", sa.column("id"), sa.column("search_config")
)
@@ -184,9 +188,20 @@ def _rewrite_benchmark_search_configs(conn, table) -> None:
"""Rewrite removed strategies in a benchmark table's ``search_config`` JSON.
``table`` is one of the module-level literal ``sa.table`` objects
- (``_benchmark_runs`` / ``_benchmark_configs``) — never a string — so the
- query below contains no dynamically-built SQL identifier.
+ (``_benchmark_runs`` / ``_benchmark_configs``) — never a string and never
+ external input — so the table/column identifiers are fixed literals that
+ SQLAlchemy renders verbatim (and the UPDATE binds its value as a parameter);
+ nothing user-derived reaches the SQL. Bearer's taint analysis nonetheless
+ reports the ``table`` parameter flowing into ``conn.execute`` as SQL
+ injection (a false positive). It is suppressed with a
+ ``# bearer:disable python_lang_sql_injection`` directive on the line
+ directly above the statement — the only placement Bearer honors (a
+ same-line trailing directive is ignored). Bearer flags only the read; the
+ write below carries the same directive defensively.
"""
+ # ``table`` is a module-level literal sa.table (see docstring) — the Bearer
+ # SQL-injection report on this read is a false positive.
+ # bearer:disable python_lang_sql_injection
rows = conn.execute(sa.select(table.c.id, table.c.search_config)).fetchall()
rewritten = 0
@@ -198,6 +213,8 @@ def _rewrite_benchmark_search_configs(conn, table) -> None:
continue
if config.get("search_strategy") in REMOVED_STRATEGIES:
config["search_strategy"] = REPLACEMENT_STRATEGY
+ # Same module-level literal table object, no external input.
+ # bearer:disable python_lang_sql_injection
conn.execute(
sa.update(table)
.where(table.c.id == row_id)