fix(security): prevent potential SQL injection in database migration
Replaced manual double-quoting of table names with SQLAlchemy's dialect-specific identifier preparer in `app/utils/db_migrate.py`. This ensures proper quoting for any database dialect and acts as a defense-in-depth measure against SQL injection or syntax errors if a table name contains unexpected characters. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -85,7 +85,8 @@ def preview_migration(source_url: str) -> dict[str, Any]:
|
||||
with src_engine.connect() as conn:
|
||||
for table_name in tables:
|
||||
# table_name is safe — sourced from inspect().get_table_names(), not user input
|
||||
row = conn.execute(text(f'SELECT COUNT(*) FROM "{table_name}"')).fetchone() # noqa: S608
|
||||
quoted_table = conn.dialect.identifier_preparer.quote(table_name)
|
||||
row = conn.execute(text(f"SELECT COUNT(*) FROM {quoted_table}")).fetchone() # noqa: S608
|
||||
count = row[0] if row else 0
|
||||
result.append({"name": table_name, "row_count": count})
|
||||
total += count
|
||||
|
||||
Reference in New Issue
Block a user