Fix OS command injection vulnerability in RDBMS#33349
Conversation
…y flow This commit addresses ICM 31000000598917 / MSRC Case 115614 by: - Refactoring run_subprocess() to accept list arguments instead of interpolated strings, preventing shell metacharacters from being interpreted as command separators - Adding validate_git_ref() function to validate and reject shell metacharacters in branch and action names - Adding stdin_file parameter to replace shell redirection (< file) patterns - Converting all call sites (4) from string format to list format: * register_credential_secrets(): gh secret set with stdin file * register_connection_secrets(): gh secret set with -b parameter * github_actions_run(): gh workflow run with --ref parameter * gitcli_check_and_login(): gh auth login command - Adding comprehensive unit tests covering: * Valid git reference validation * Dangerous shell metacharacter rejection * List vs string argument handling * stdin_file parameter handling * Error handling and cleanup This is a Defense in Depth fix (no trust boundary crossing). The --branch and --repository parameters are supplied by the same user who has shell access. The fix improves code hygiene by eliminating unnecessary use of shell string interpolation. Fixes: ICM 31000000598917
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the RDBMS flexible-server “deploy” flow against OS command injection by eliminating shell-style string commands and adding validation for user-provided git refs/workflow identifiers.
Changes:
- Refactors
run_subprocessto require list-based args and addsstdin_filesupport to replace shell redirection patterns. - Adds
validate_git_refand applies it to GitHub Actions workflow invocation inputs. - Adds unit tests covering git ref validation and
run_subprocessbehavior (list args, stdin file, error handling).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/rdbms/_flexible_server_util.py |
Adds validate_git_ref, refactors run_subprocess to list args + stdin_file, and updates gh secret set call sites accordingly. |
src/azure-cli/azure/cli/command_modules/rdbms/flexible_server_custom_common.py |
Validates workflow/branch inputs and converts gh invocations to list-based subprocess args. |
src/azure-cli/azure/cli/command_modules/rdbms/tests/latest/test_command_injection_fixes.py |
Adds unit tests for validation and subprocess invocation changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Pattern to detect shell metacharacters and command injection attempts | ||
| if re.search(r'[;&$`|<>"\'\\]|\n', git_ref): | ||
| raise InvalidArgumentValueError( | ||
| 'Git reference contains invalid characters. Allowed: alphanumeric, -, _, ., /') |
| if stdout_show: | ||
| process = subprocess.Popen(args, stdin=stdin_handle) | ||
| else: | ||
| process = subprocess.Popen(args, stdin=stdin_handle, | ||
| stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| process.wait() | ||
|
|
||
| if process.returncode: | ||
| if not stdout_show: | ||
| stderr_output = process.stderr.read().strip().decode('UTF-8') | ||
| logger.warning(stderr_output) |
| process = subprocess.Popen(args, stdin=stdin_handle, | ||
| stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
| process.wait() | ||
|
|
||
| if process.returncode: | ||
| if not stdout_show: | ||
| stderr_output = process.stderr.read().strip().decode('UTF-8') | ||
| logger.warning(stderr_output) | ||
| raise CLIError('Command failed with exit code {}'.format(process.returncode)) |
| # -------------------------------------------------------------------------------------------- | ||
| """Unit tests for command injection vulnerability fixes in RDBMS flexible-server deploy flow.""" | ||
|
|
||
| import os |
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| unittest.main() |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
🔄AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
This commit addresses ICM 31000000598917 / MSRC Case 115614 by:
This is a Defense in Depth fix (no trust boundary crossing). The --branch and --repository parameters are supplied by the same user who has shell access. The fix improves code hygiene by eliminating unnecessary use of shell string interpolation.
Fixes: ICM 31000000598917
Related command
Description
Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE:
az command a: Make some customer-facing breaking change[Component Name 2]
az command b: Add some customer-facing featureThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.