The analysis of the provided patch commit c18d0df2702130cf5d0f050e516eb8999aa56301 reveals multiple SQL injection vulnerabilities within the MetaStoreDirectSql.java file. The root cause is the unsafe construction of SQL queries using string concatenation with user-provided input, specifically when deleting table and partition column statistics, and when locking tables.
The primary vulnerability, as described in the CVE, relates to the deletion of column statistics. The patch addresses this in two places:
- The
deleteTableColumnStatistics method, which was concatenating column names and the engine name directly into the SQL string.
- An anonymous inner class's
run method, responsible for deleting partition column statistics, which had the same string concatenation flaw.
Both vulnerabilities are fixed by converting the code to use parameterized SQL queries, which properly separates the query logic from the data and prevents injection attacks.
Additionally, the patch fixes a similar SQL injection vulnerability in the lockDbTable method, which was also using string concatenation for the table name. The fix here involves an allowlist check on the table name.
The identified functions are all within the org.apache.hadoop.hive.metastore.MetaStoreDirectSql class, which is invoked when the metastore.try.direct.sql configuration property is enabled. These functions would appear in a runtime profile when a malicious request to the Hive Metastore Thrift API triggers the vulnerable code paths.