Skip to content

Commit 6c046e8

Browse files
committed
Split list_runs into two literal SQL statements
Opengrep's ``python_sql_rule-hardcoded-sql-expression`` can't prove the dynamically built SQL string in ``list_runs`` is safe even with the parameters bound, so it keeps firing as a false positive on PR runs. Branch the two cases (with/without source_type filter) into two fully literal queries — no string concatenation, just placeholders — so the rule has nothing to flag. Behaviour and test coverage unchanged.
1 parent 6c0e048 commit 6c046e8

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

je_auto_control/utils/run_history/history_store.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,22 @@ def list_runs(self, limit: int = 100,
166166
"""Return the most recent runs (newest first)."""
167167
if limit <= 0:
168168
return []
169-
if source_type is not None:
169+
bound_limit = int(limit)
170+
if source_type is None:
171+
with self._lock:
172+
rows = self._conn.execute(
173+
"SELECT * FROM runs "
174+
"ORDER BY started_at DESC LIMIT ?",
175+
(bound_limit,),
176+
).fetchall()
177+
else:
170178
_validate_source(source_type)
171-
sql = "SELECT * FROM runs"
172-
params: list = []
173-
if source_type is not None:
174-
sql += " WHERE source_type = ?"
175-
params.append(source_type)
176-
sql += " ORDER BY started_at DESC LIMIT ?"
177-
params.append(int(limit))
178-
with self._lock:
179-
# nosemgrep: python_sql_rule-hardcoded-sql-expression
180-
# reason: `sql` is composed only from in-module string literals; `source_type` is validated via `_validate_source`, and `limit` is coerced to int before binding as a parameter.
181-
rows = self._conn.execute(sql, params).fetchall()
179+
with self._lock:
180+
rows = self._conn.execute(
181+
"SELECT * FROM runs WHERE source_type = ? "
182+
"ORDER BY started_at DESC LIMIT ?",
183+
(source_type, bound_limit),
184+
).fetchall()
182185
return [_row_to_record(row) for row in rows]
183186

184187
def get_run(self, run_id: int) -> Optional[RunRecord]:

0 commit comments

Comments
 (0)