injection fix using shell=false#45740
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the local endpoints CLI invocation helper to mitigate command injection by avoiding shell=True + string-joined commands on non-Windows platforms, and introduces Windows-specific handling for commands that are provided as .cmd/.bat shims.
Changes:
- Switch non-Windows execution to
shell=Falsewith argv list. - Add Windows branch that builds a command line string via
subprocess.list2cmdline(...)and executes withshell=True. - Minor refactor/formatting around command printing and subprocess args construction.
You can also share your feedback on Copilot code review. Take the survey.
sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/utilities/commandline_utility.py
Show resolved
Hide resolved
sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/utilities/commandline_utility.py
Outdated
Show resolved
Hide resolved
sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/utilities/commandline_utility.py
Outdated
Show resolved
Hide resolved
sdk/ml/azure-ai-ml/azure/ai/ml/_local_endpoints/utilities/commandline_utility.py
Outdated
Show resolved
Hide resolved
…into ayushhgarg/macos3
|
@ayushhgarg-work please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Description
What
Fix command injection vulnerability (CWE-94) in
commandline_utility.pyby removingunsafe
shell=True+ string-join pattern.Related: MSRC Case 106104 (Moderate - Remote Code Execution)
Why
The
run_cli_commandfunction previously joined command arguments into a single stringvia
" ".join(cmd_arguments)and executed it withsubprocess.check_output(..., shell=True).This allowed shell metacharacters in user-controlled input (e.g.,
scoring_scriptpathin a deployment YAML) to break out of the command and execute arbitrary code.
Changes
shell=Falseand passcmd_argumentsas a list directly tosubprocess.check_outputon all platforms — shell metacharacters are never interpreted" ".join(cmd_arguments)pattern and the outdated commentreferencing the old
shell=Trueapproachrun_cli_commandcovering:shell,stderr,env);,&payloads matching MSRC attack vectors)CalledProcessErrorpropagationTesting
&,;,|are passed asliteral strings and do not result in command injection