Merge pull request #19594 from sylwia-budzynska/pandas-sqli

Python: Add Pandas SQLi sinks
This commit is contained in:
Taus
2025-06-02 13:40:14 +02:00
committed by GitHub
3 changed files with 21 additions and 3 deletions

View File

@@ -151,4 +151,17 @@ private module Pandas {
override DataFlow::Node getCode() { result = this.getParameter(0, "expr").asSink() }
}
/**
* A Call to `pandas.read_sql` or `pandas.read_sql_query`
* which allows for executing raw SQL queries against a database.
* See https://pandas.pydata.org/docs/reference/api/pandas.read_sql.html
*/
class ReadSqlCall extends SqlExecution::Range, DataFlow::CallCfgNode {
ReadSqlCall() {
this = API::moduleImport("pandas").getMember(["read_sql", "read_sql_query"]).getACall()
}
override DataFlow::Node getSql() { result in [this.getArg(0), this.getArgByName("sql")] }
}
}

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Added SQL injection models from the `pandas` PyPI package.

View File

@@ -1,5 +1,5 @@
import pandas as pd
import sqlite3
df = pd.DataFrame({'temp_c': [17.0, 25.0]}, index=['Portland', 'Berkeley'])
df.sample().query("query") # $getCode="query"
@@ -55,11 +55,12 @@ df = pd.read_sql_table("filepath", 'postgres:///db_name')
df.query("query") # $getCode="query"
df.eval("query") # $getCode="query"
df = pd.read_sql_query("filepath", 'postgres:///db_name')
connection = sqlite3.connect("pets.db")
df = pd.read_sql_query("sql query", connection) # $getSql="sql query"
df.query("query") # $getCode="query"
df.eval("query") # $getCode="query"
df = pd.read_sql("filepath", 'postgres:///db_name')
df = pd.read_sql("sql query", connection) # $getSql="sql query"
df.query("query") # $getCode="query"
df.eval("query") # $getCode="query"