This proposal outlines the design and implementation for mitigating SQL injection risks in pg_durable by implementing parameterized queries. This feature was implemented but reverted for future consideration.
The df.sql function currently accepts a raw SQL string. This string is executed directly by the execute_sql activity, potentially allowing SQL injection if user input is concatenated into the string.
Update dsl::sql to accept an optional arguments parameter (JSONB).
pub fn sql(query: &str, args: Option<pgrx::JsonB>) -> String {
// ...
}This function constructs a JSON configuration object:
{
"query": "SELECT * FROM users WHERE id = $1",
"args": [123]
}Update activities::execute_sql to parse this JSON configuration. If "args" are present, use sqlx's binding mechanism to bind parameters safely.
// Logic to bind serde_json::Value types to sqlx query
match arg {
serde_json::Value::String(s) => query = query.bind(s),
serde_json::Value::Number(n) => ...
// ...
}Users would call it as:
SELECT df.sql('SELECT * FROM table WHERE id = $1', jsonb_build_array(1));Existing calls using raw strings should continue to work by treating the input as a query with no arguments.
- Unit tests in
dsl.rsto verify JSON generation. - E2E tests verifying parameter binding for various types.
Reverted to simplify the current scope and defer this enhancement.