Skip to content

{Packaging} harden launcher against cwd module loading#33780

Open
naga-nandyala wants to merge 2 commits into
devfrom
naga-nandyala-review-pr-21261
Open

{Packaging} harden launcher against cwd module loading#33780
naga-nandyala wants to merge 2 commits into
devfrom
naga-nandyala-review-pr-21261

Conversation

@naga-nandyala

@naga-nandyala naga-nandyala commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Description

python -m adds the current working directory to the start of sys.path, so running az from an untrusted directory can load a local azure.py before the real package.

This change hardens the launcher in src/azure-cli/az to avoid that cwd import path.

Changes

  • Replaced os.execl(sys.executable, sys.executable, '-m', 'azure.cli', *sys.argv[1:]) with runpy.run_module(...).
  • Explicitly prepended the launcher src directory to sys.path before module execution to preserve local launcher import behavior.
  • Used run_name='__main__' and alter_sys=True for closer -m semantics while avoiding -m cwd import behavior.

Security context

This addresses the cwd import vector described in Debian bug #1005251 while keeping launcher behavior stable.

Related

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
Copilot AI review requested due to automatic review settings July 23, 2026 22:57
@naga-nandyala
naga-nandyala requested review from a team as code owners July 23, 2026 22:57
@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi @naga-nandyala,
Since the current milestone time is less than 7 days, this pr will be reviewed in the next milestone.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@yonzhan

yonzhan commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).

@yonzhan

yonzhan commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Thank you for your contribution! We will review the pull request and get back to you soon.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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', ...) with runpy.run_module(...) to avoid -m semantics that put the current working directory first on sys.path.
  • Prepends a launcher-derived path to sys.path before executing the CLI module.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/azure-cli/az Outdated
Comment thread src/azure-cli/az Outdated
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
@naga-nandyala naga-nandyala changed the title {az} harden launcher against cwd module loading {Packaging} harden launcher against cwd module loading Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants