Har1sh-k opened a new pull request, #66751:
URL: https://github.com/apache/airflow/pull/66751

   ## Summary
   
   `HiveStatsCollectionOperator` builds its bookkeeping SQL (the `SELECT` and 
`DELETE` against `hive_stats` in the MySQL metastore, and the `SELECT ... FROM 
<table> WHERE <partition_key> = '<value>'` against Presto) by 
f-string-interpolating template-rendered fields (`table`, `partition`, `dttm`) 
directly into raw SQL strings.
   
   Per the security model 
([`security_model.rst`](https://github.com/apache/airflow/blob/main/airflow-core/docs/security/security_model.rst#dag-author-code-passing-unsanitized-input-to-operators-and-hooks)
 and 
[`sql.rst`](https://github.com/apache/airflow/blob/main/airflow-core/docs/security/sql.rst)),
 this is not a vulnerability — Dag authors are trusted users responsible for 
sanitizing input before passing it to operators. This PR is defense-in-depth so 
the operator does not rely on each Dag author to sanitize.
   
   - The MySQL `SELECT` and `DELETE` use `%s` placeholders with the 
`parameters=` kwarg of `MySqlHook.get_records` / `.run`, so the values are 
bound by the driver instead of interpolated.
   - For the Presto `SELECT`, the table name and partition column names cannot 
be parameterized in standard SQL — they are validated against 
`^[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)?$` and 
`^[A-Za-z_][A-Za-z0-9_]*$` respectively, raising `AirflowException` on 
mismatch. Partition values are passed as bound parameters.
   
   ## Test plan
   
   - [x] New `test_execute_rejects_invalid_table_identifier` and 
`test_execute_rejects_invalid_partition_column` exercise the allowlist regexes.
   - [x] New `test_execute_parameterizes_mysql_bookkeeping_queries` and 
`test_execute_parameterizes_presto_partition_values` verify the SQL is 
parameterized (no f-string interpolation of `table` / `partition` values into 
the SQL body).
   - [x] Updated `test_execute_delete_previous_runs_rows` and 
`test_runs_for_hive_stats` to assert the parameterized form.
   - [x] Existing `test_hive_stats.py` tests continue to pass.
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [X] Yes (Claude Opus 4.7)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to