Skip to content

Commit

Permalink
fix: sql injection for schema (but not sql run as it is designed for …
Browse files Browse the repository at this point in the history
…that). (#56)
  • Loading branch information
tang2087 authored Sep 11, 2024
1 parent 458675f commit f9cdd2d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion kontext_copilot/services/_data_provider_service/_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
DataSourceModel,
SchemaTablesModel,
)
from kontext_copilot.utils import get_logger

logger = get_logger()


class BaseProvider(ABC):
Expand Down Expand Up @@ -210,7 +213,8 @@ def run_sql(
"""
with self.engine.connect() as conn:
if schema is not None:
conn.execute(f"USE {schema}")
conn.execute(text("USE :schema"), {"schema": schema})
logger.debug(f"Executing SQL: {sql}")
statement = text(sql)
result = conn.execute(statement=statement)
if result.returns_rows == False:
Expand Down

0 comments on commit f9cdd2d

Please sign in to comment.