{Packaging} harden launcher against cwd module loading#33780
Open
naga-nandyala wants to merge 2 commits into
Open
{Packaging} harden launcher against cwd module loading#33780naga-nandyala wants to merge 2 commits into
naga-nandyala wants to merge 2 commits into
Conversation
Replace python -m re-exec with runpy invocation and explicitly prepend the launcher src path to sys.path before module execution. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 08ab13f2-06ce-4fb7-bc01-ad4510b2f6bb
|
Hi @naga-nandyala, |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
|
/azp run |
|
Azure Pipelines: Successfully started running 3 pipeline(s). |
Collaborator
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the az Python launcher against importing azure modules from an untrusted current working directory by avoiding python -m azure.cli re-exec and instead executing the CLI module in-process.
Changes:
- Replaces
os.execl(..., '-m', 'azure.cli', ...)withrunpy.run_module(...)to avoid-msemantics that put the current working directory first onsys.path. - Prepends a launcher-derived path to
sys.pathbefore executing the CLI module.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use azure.cli.__main__ as runpy target and resolve launcher path robustly by falling back to launcher directory when ./src is absent. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 08ab13f2-06ce-4fb7-bc01-ad4510b2f6bb
3 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.
Description
python -madds the current working directory to the start ofsys.path, so runningazfrom an untrusted directory can load a localazure.pybefore the real package.This change hardens the launcher in
src/azure-cli/azto avoid that cwd import path.Changes
os.execl(sys.executable, sys.executable, '-m', 'azure.cli', *sys.argv[1:])withrunpy.run_module(...).srcdirectory tosys.pathbefore module execution to preserve local launcher import behavior.run_name='__main__'andalter_sys=Truefor closer-msemantics while avoiding-mcwd import behavior.Security context
This addresses the cwd import vector described in Debian bug #1005251 while keeping launcher behavior stable.
Related