Repository navigation
[Core] Add get_safe_executable_path to prevent binary planting when spawning subprocess - #34212
Merged
Ethan Yang (necusjz) merged 4 commits intoOct 14, 2026
Merged
Conversation
microsoft-github-policy-service
Bot
requested a review
from Yong Zhang (yonzhan)
October 12, 2026 05:24
Collaborator
|
Core |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The fallback invocation and relative-path handling can still execute attacker-controlled code from the working directory.
3 open findings
What changed in this PR
Adds secure executable resolution to mitigate binary planting in subprocess calls.
Changes:
- Adds and tests
get_safe_executable_path. - Secures post-upgrade Azure CLI subprocess execution.
- Documents secure executable invocation practices.
| File | Description |
|---|---|
src/azure-cli/azure/cli/command_modules/util/custom.py |
Uses resolved executable paths during upgrades. |
src/azure-cli-core/azure/cli/core/util.py |
Implements safe executable resolution. |
src/azure-cli-core/azure/cli/core/tests/test_util.py |
Adds resolver unit tests. |
doc/secure_executable_invocation.md |
Adds security guidance and examples. |
doc/cli_subprocess_guidelines.md |
Links the new guidance. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ethan Yang (necusjz)
force-pushed
the
safe-executable-solution
branch
from
October 13, 2026 04:57
140d239 to
f9753f7
Compare
Ethan Yang (necusjz)
marked this pull request as ready for review
October 13, 2026 07:52
DanielMicrosoft
approved these changes
Oct 14, 2026
Naga Nandyala (naga-nandyala)
approved these changes
Oct 14, 2026
2 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


🤖 PR Validation — ️✔️ All clear
Related command
Description
it's developer-facing, so with hard brackets.
On Windows, starting a process by a bare name (e.g.
cmd.exe,az) looks in the current working directory before the system directory andPATH. This happens withshell=Falseas well asshell=True. A malicious executable placed in a directory the usercds into (a cloned repo, an unzipped artifact) can then run inside the user's Azure CLI session (binary planting, CWE-427).az upgradewas affected: after upgrading it runsaz versionandaz extension updateas subprocesses with the bare nameazandshell=True.This PR:
Adds
azure.cli.core.util.get_safe_executable_path(executable), a shared helper that turns an executable name into an absolute path using only trusted locations:%SystemRoot%\System32and%SystemRoot%are searched first, socmd.exealways comes from there.PATHentries are used. Empty and relative entries ("",.,bin) are skipped because they point into the current directory.PROGRA~1) or junctions don't get around it. A match whose symlink target is in the current directory is also rejected.PATHEXTextensions are tried, soazresolves toaz.cmd/az.exe.Nonewhen there is no trusted match or the current directory can't be determined, the same contract asshutil.which. It never returns the bare name, because running that would bring back the current-directory lookup.Fixes
az upgrade: the post-upgrade version check and the extension update calls now use absolutecmd.exeandazpaths withshell=False. If either can't be found, it runs[sys.executable, '-m', 'azure.cli']instead, which is also an absolute path.Docs: adds
doc/secure_executable_invocation.md, a guide for module owners on finding and fixing bare executable calls (cmd.exe,docker,git,gh,kubectl, ...), and links it fromdoc/cli_subprocess_guidelines.md.Testing Guide
Unit tests:
TestSafeExecutablePathinsrc/azure-cli-core/azure/cli/core/tests/test_util.py. They cover the current directory onPATH, relativePATHentries, case-insensitive matching (Windows), skipping a fake binary to find the real one later onPATH, not found →None, an unknown current directory →None, andcmd.exeresolving to System32.Manual check (Windows):
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.