Fix SQL injection vulnerability in UC function execution#19381
Fix SQL injection vulnerability in UC function execution#19381harupy merged 3 commits intomlflow:masterfrom
Conversation
|
Documentation preview for fd49858 is available at: More info
|
There was a problem hiding this comment.
Pull request overview
This PR addresses a critical SQL injection vulnerability in Unity Catalog function execution by introducing proper escaping of function names before SQL interpolation. The fix adds a new escape_uc_identifier() function that validates and escapes catalog.schema.function identifiers with backticks, preventing malicious function names from executing arbitrary SQL.
Key changes:
- Introduces
escape_uc_identifier()function to validate and escape 3-part Unity Catalog identifiers - Updates
get_execute_function_sql_stmt()to escape function names before SQL interpolation - Implements backtick escaping with double-backtick escape sequences for embedded backticks
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
IMO, https://mlflow.org/docs/latest/genai/governance/unity-catalog/ no longer makes sense. We can just use MCP now.
03c54f3 to
628fb93
Compare
|
Actually is this a real vulnerability? |
|
@serena-ruan Even if the attack is not valid, the fix still makes sense. The current code seems vulnerable to SQL injection. |
mlflow/gateway/uc_function_utils.py
Outdated
|
|
||
| # Valid Unity Catalog identifier pattern: must start with letter or underscore, | ||
| # followed by letters, digits, or underscores | ||
| _VALID_UC_IDENTIFIER = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$") |
There was a problem hiding this comment.
It's possible it includes backticks?
It's true, but SQL injection shouldn't happen in function name part but the parameters part? BTW UC function execution should handle any potential security issues |
Add `escape_uc_identifier()` to properly escape Unity Catalog function names with backticks before SQL interpolation, preventing SQL injection attacks via maliciously crafted function names. Fixes mlflow#19365 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Add input validation for Unity Catalog function names in get_execute_function_sql_stmt() to prevent SQL injection attacks. Function names are now validated to ensure they follow the catalog.schema.function format with only safe identifier characters. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
Replace validation-based approach with identifier quoting using backticks. This is more flexible while still preventing SQL injection. - Add _quote_identifier() to quote SQL identifiers with backticks - Strip existing backticks before re-quoting - Reject identifiers with embedded backticks - Quote function names and parameter names in SQL statements 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Signed-off-by: harupy <17039389+harupy@users.noreply.github.com>
b808920 to
fd49858
Compare
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: harupy <17039389+harupy@users.noreply.github.com> Co-authored-by: Claude <noreply@anthropic.com>
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
Resolve #19365
What changes are proposed in this pull request?
Add
_quote_identifier()function to properly quote Unity Catalog identifiers with backticks before SQL interpolation. This prevents SQL injection attacks via maliciously crafted function names.The function:
catalog.schema.function) and quotes each part with backticksHow is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
Fixed a SQL injection vulnerability in Unity Catalog function execution where maliciously crafted function names could execute arbitrary SQL.
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsHow should the PR be classified in the release notes? Choose one:
rn/bug-fix- A user-facing bug fix worth mentioning in the release notesShould this PR be included in the next patch release?
🤖 Generated with Claude Code